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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#!/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.
#DEBHELPER#
exit 0
|