summarylogtreecommitdiffstats
path: root/mksh.install
blob: 9f0c56c54a9eaecdcbf5dd0d148feaea477ac33f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pre_install() {
#  :
#}

post_install() {
  grep -q -x -e '/bin/mksh' '/etc/shells' || echo '/bin/mksh' >> '/etc/shells'
  # need to also add /usr/bin/mksh to /etc/shells to avoid https://bugs.archlinux.org/task/55053
  grep -q -x -e '/usr/bin/mksh' '/etc/shells' || echo '/usr/bin/mksh' >> '/etc/shells'
}

#pre_upgrade() {
#  :
#}

post_upgrade() {
  post_install
}

pre_remove() {
  # This is only necessary on alternate shells. sh and bash 
  # are at the base of Arch and cannot be removed.
  # To test this you should have a spare root shell already open.
  # Otherwise, if this doesn't work, you will need to learn how to bypass
  # the default shell on login.
  # http://stackoverflow.com/questions/11059067/what-is-the-nix-command-to-view-a-users-default-login-shell
  local _sh="$(getent passwd root | cut -d: -f7)"
  if [ "${_sh}" = '/bin/mksh' ] || [ "${_sh}" = '/usr/bin/mksh' ]; then
    echo '**********************************************'
    echo '*** Warning: ROOT HAS mksh as the login shell.'
    echo '*** Shell changed to sh to prevent loss of root access.'
    echo '**********************************************'
    # sh is more likely to guarantee a login than bash because sh is typically
    # unmodified. Crappy, but guaranteed.
    chsh -s '/bin/sh'
  fi
  sed -E -e '\:^(/usr/bin/mksh|/bin/mksh)$: d' -i '/etc/shells'
}

post_remove() {
  #mandb -q
  local _sha
  readarray -t _sha < <(getent passwd | cut -d':' -f'1,7' | grep -F -e $'/usr/bin/mksh\n/bin/mksh')
  if [ "${#_sha[@]}" -gt 0 ]; then
    echo '*** Warning: Some users have mksh as their login shell.'
    echo '*** Have root fix promptly to restore access.'
    printf '%s\n' "${_sha[@]}"
  fi
}