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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
#!/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
# also add nōn-canonical pathnames under /usr/bin/
um=+ # broken filesystem, unsupported by dpkg
# 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.
#DEBHELPER#
exit 0
|