#!/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: # # * prerm "remove" # * old-prerm "upgrade" $new_version # * conflictors-prerm "remove" "in-favour" $new_package $new_version # * deconfigureds-prerm "deconfigure" "in-favour" # $package_being_installed $pbi_version # new-package # ["removing" $conflicting_package $cp_version] # old-package # The package and dependencies are at least Half-Installed; dependencies # have previously been configured and not removed. # # * new-prerm "failed-upgrade" $old_version # * new-prerm "failed-upgrade" $old_version $new_version # 1.18.5, stretch # Called when 'old-prerm "upgrade"' fails; new package not unpacked, all # other constraints the same as above. case $1 in (remove|deconfigure) update-alternatives --remove ksh /bin/mksh update-alternatives --remove ksh /bin/mksh-static # remove compatibility symlink if broken test '!' -h /usr/bin/ksh || test -e /usr/bin/ksh || rm -f /usr/bin/ksh # unadd us from /etc/shells; clean up old add-shell-caused damage # shellcheck disable=SC2046 mogrifyshells - /bin/mksh /bin/mksh-static \ - /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) ;; (upgrade|failed-upgrade) ;; (*) echo >&2 "E: prerm called with unknown subcommand '$1'" exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. exit 0