| 1 |
#!/bin/sh -e |
| 2 |
|
| 3 |
if test $# -eq 0 |
| 4 |
then |
| 5 |
echo "usage: $0 shellname [shellname ...]" 1>&2 |
| 6 |
exit 1 |
| 7 |
fi |
| 8 |
|
| 9 |
file="$DPKG_ROOT/etc/shells" |
| 10 |
# I want this to be GUARANTEED to be on the same filesystem as $file |
| 11 |
tmpfile="${file}.tmp" |
| 12 |
otmpfile="${file}.tmp2" |
| 13 |
|
| 14 |
set -o noclobber |
| 15 |
|
| 16 |
cleanup() { |
| 17 |
rm -f "$tmpfile" "$otmpfile" |
| 18 |
} |
| 19 |
trap cleanup EXIT |
| 20 |
|
| 21 |
if ! cat "$file" > "$tmpfile" |
| 22 |
then |
| 23 |
cat 1>&2 <<EOF |
| 24 |
Either another instance of $0 is running, or it was previously interrupted. |
| 25 |
Please examine ${tmpfile} to see if it should be moved onto ${file}. |
| 26 |
EOF |
| 27 |
exit 1 |
| 28 |
fi |
| 29 |
|
| 30 |
# this is supposed to be reliable, not pretty |
| 31 |
for i |
| 32 |
do |
| 33 |
REALDIR="$(dirname "$(realpath -m "$i")")/$(basename "$i")" |
| 34 |
for j in "$i" "$REALDIR" |
| 35 |
do |
| 36 |
grep -v "^${j}$" "$tmpfile" > "$otmpfile" || true |
| 37 |
mv "$otmpfile" "$tmpfile" |
| 38 |
done |
| 39 |
done |
| 40 |
|
| 41 |
chmod --reference="${file}" "${tmpfile}" || chmod $(stat -c %a "${file}") "${tmpfile}" |
| 42 |
chown --reference="${file}" "${tmpfile}" || chown $(stat -c %U "${file}") "${tmpfile}" |
| 43 |
|
| 44 |
mv -Z "${tmpfile}" "${file}" || mv "${tmpfile}" "${file}" |
| 45 |
|
| 46 |
trap "" EXIT |
| 47 |
exit 0 |