Debian Codegraph @

add-shell

raw
1 #!/bin/sh -e
2
3 if test $# -eq 0
4 then
5 echo "usage: $0 shellname [shellname ...]"
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
13 set -o noclobber
14
15 cleanup() {
16 rm -f "$tmpfile"
17 }
18 trap cleanup EXIT
19
20 if ! cat "$file" > "$tmpfile"
21 then
22 cat 1>&2 <<EOF
23 Either another instance of $0 is running, or it was previously interrupted.
24 Please examine ${tmpfile} to see if it should be moved onto ${file}.
25 EOF
26 exit 1
27 fi
28
29 for i
30 do
31 REALDIR="$(dirname "$(realpath -m "$i")")/$(basename "$i")"
32 for j in "$i" "$REALDIR"
33 do
34 if ! grep -q "^${j}$" "$tmpfile"
35 then
36 echo "$j" >> "$tmpfile"
37 fi
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