#!/bin/sh # shellcheck disable=SC3043 set -e # Does what add-shell/remove-shell does, with the sync extras from # update-shells, but does not add the link targets, only the lines # listed; more safety checking; no regex escape issue; in contrast # to the debianutils ones, it honours the admin’s choice disabling # lines by commenting them, as in prefixing a single hash sign. mogrifyshells() { local basefile="$DPKG_ROOT/etc/shells" local tmpa="$basefile.tmp" local tmpb="$basefile.tmp2" local rc=0 x mode='' oshf=$- set +e case $basefile in (/*) ;; (*) echo >&2 "E: mogrifyshells: invalid DPKG_ROOT: $DPKG_ROOT" exit 1 ;; esac ( set -o noclobber cat "$basefile" >"$tmpa" ) || { cat >&2 <<-EOF E: add-shell/remove-shell is currently running or was previously interrupted I: Please examine ${tmpa} to see if it should be moved onto ${basefile} EOF exit 1 } for x in "$@"; do case $x in (+) mode=+; continue ;; (-) mode=-; continue ;; esac case $mode in (+) grep -F -x -q -e "$x" -e "#$x" "$tmpa" rc=$? case $rc in (0) ;; (1) printf '%s\n' "$x" >>"$tmpa" ;; (*) echo >&2 "E: mogrifyshells: grep error $rc" rm -f "$tmpa" exit 1 ;; esac ;; (-) grep -F -x -v -e "$x" -e "#$x" "$tmpa" >"$tmpb" rc=$? case $rc in (0|1) ;; (*) echo >&2 "E: mogrifyshells: grep error $rc" rm -f "$tmpa" "$tmpb" exit 1 ;; esac mv "$tmpb" "$tmpa" || { echo >&2 "E: mogrifyshells: mv error" rm -f "$tmpa" "$tmpb" exit 1 } ;; (*) echo >&2 'E: mogrifyshells: no mode given' rm -f "$tmpa" exit 1 ;; esac done rc=0 chmod --reference="$basefile" "$tmpa" || { x=$(stat -c %a "$basefile") || rc=1 chmod "0$x" "$tmpa" || rc=1 } chown --reference="$basefile" "$tmpa" || { x=$(stat -c %u:%g "$basefile") || rc=1 chown -- "$x" "$tmpa" || rc=1 } sync -d -- "$tmpa" || rc=1 test 0 = "$rc" || { echo >&2 'E: mogrifyshells: error during chmod/chown/fdatasync' rm -f "$tmpa" exit 1 } mv -Z "$tmpa" "$basefile" || mv "$tmpa" "$basefile" || { echo >&2 "E: mogrifyshells: error during mv back; $tmpa left" exit 1 # but keep temporary } sync "$basefile" "${basefile%/*}" || { echo >&2 "W: mogrifyshells: error during final sync" # and pray } case $oshf in (*e*) set -e ;; esac return 0 } # This maintainer script can be called the following ways: # # * new-postinst "configure" [$most_recently_configured_version] # The package is unpacked; all dependencies are unpacked and, when there # are no circular dependencies, configured. # # * old-postinst "abort-upgrade" $new_version # * old-postinst "abort-remove" # * conflictors-postinst "abort-remove" "in-favour" $new_package # $new_version # * deconfigureds-postinst "abort-deconfigure" "in-favour" # $failed_install_package $fip_version # new-package # ["removing" $conflicting_package $cp_version] # old-package # The package is unpacked; all dependencies are at least Half-Installed, # previously been configured, and not removed. In some error situations, # dependencies may not be even fully unpacked. # # * postinst "triggered" "${triggers[*]}" # For trigger-only calls, i.e. if "configure" is not called. # # * new-postinst "reconfigure" [$most_recently_configured_version](?) # Treat this as just like "configure" for a future extension by debconf. case $1 in (configure|reconfigure) update-alternatives --install /bin/ksh ksh /bin/mksh 12 \ --slave /usr/share/man/man1/ksh.1.gz ksh.1.gz \ /usr/share/man/man1/mksh.1.gz \ --slave /bin/rksh rksh /bin/mksh \ --slave /usr/share/man/man1/rksh.1.gz rksh.1.gz \ /usr/share/man/man1/mksh.1.gz update-alternatives --install /bin/ksh ksh /bin/mksh-static 11 \ --slave /usr/share/man/man1/ksh.1.gz ksh.1.gz \ /usr/share/man/man1/mksh-static.1.gz \ --slave /bin/rksh rksh /bin/mksh-static \ --slave /usr/share/man/man1/rksh.1.gz rksh.1.gz \ /usr/share/man/man1/mksh-static.1.gz # create compatibility symlink if necessary test -e /usr/bin/ksh || test -h /usr/bin/ksh || \ ln -s /bin/ksh /usr/bin/ksh # check for bogus filesystem layout; if so, also add # nōn-canonical pathnames for popular demand um=+ # broken filesystem, unsupported by dpkg test /usr/bin/mksh -ef /bin/mksh || um=- # traditional layout # add us to /etc/shells and clean up old add-shell-caused damage # shellcheck disable=SC2046 mogrifyshells + /bin/mksh /bin/mksh-static \ $um /usr/bin/mksh /usr/bin/mksh-static \ - $(for x in \ /usr/lib/klibc/bin \ /usr/lib/diet/bin \ /usr/lib/*-linux-musl*/bin \ ; do echo "$x/mksh" "$x/mksh-static"; done) ;; (abort-upgrade|abort-remove|abort-deconfigure) ;; (triggered) ;; (*) echo >&2 "E: postinst called with unknown subcommand '$1'" exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. # Automatically added by dh_installmenu/13.15.3 if [ "$1" = "configure" ] && [ -x "`command -v update-menus`" ] && [ -x "$DPKG_ROOT`command -v update-menus`" ]; then update-menus fi # End automatically added section exit 0