Debian Codegraph @

debian/iproute2.postinst

raw
1 #!/bin/sh
2
3 set -e
4
5 # Alternatively this check can be disabled by preseeding:
6 # echo "iproute2/setcaps boolean false" | debconf-set-selections
7
8 . /usr/share/debconf/confmodule
9
10 case "$1" in
11 configure)
12 if command -v setcap > /dev/null; then
13 db_get iproute2/setcaps
14
15 # Allow dpkg-reconfigure to remove caps
16 if test "$RET" = "true"; then
17 if ! setcap "cap_dac_override,cap_bpf,cap_net_admin=ep" /bin/ip; then
18 echo "Setcap failed on /bin/ip, ip vrf exec will not be runnable by non-root" >&2
19 fi
20 else
21 # setcap -r fails if the xattr is not present
22 if getcap /bin/ip | grep -qs "/bin/ip"; then
23 if ! setcap "-r" /bin/ip; then
24 echo "Setcap -r failed on /bin/ip, could not remove capabilities" >&2
25 fi
26 fi
27 fi
28 fi
29 ;;
30
31 abort-upgrade|abort-remove|abort-deconfigure)
32 ;;
33
34 *)
35 echo "postinst called with unknown argument \`$1'" >&2
36 exit 1
37 ;;
38 esac
39
40 # dh_installdeb will replace this with shell code automatically
41 # generated by other debhelper scripts.
42
43 #DEBHELPER#
44
45 # TODO: drop in forky
46 if [ "$1" = "configure" ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt 6.5.0-4~; then
47 # If any of the config files that used to ship in /etc before were modified
48 # locally, then try to copy them back as overrides, but don't fail if it
49 # cannot be done for any weird reason, as is it not crucial for iproute2's
50 # functionality
51 for f in /etc/iproute2/group /etc/iproute2/rt_realms /etc/iproute2/rt_scopes /etc/iproute2/rt_tables /etc/iproute2/rt_tables.d/README /etc/iproute2/rt_protos.d/README /etc/iproute2/rt_protos /etc/iproute2/rt_dsfield /etc/iproute2/nl_protos /etc/iproute2/ematch_map /etc/iproute2/bpf_pinning; do
52 if [ -f "${f}.dpkg-bak" ]; then
53 mv "${f}.dpkg-bak" "${f}" || true
54 fi
55 done
56
57 if [ -d /etc/iproute2/rt_protos.d/ ]; then
58 rmdir --ignore-fail-on-non-empty /etc/iproute2/rt_protos.d
59 fi
60 if [ -d /etc/iproute2/rt_tables.d/ ]; then
61 rmdir --ignore-fail-on-non-empty /etc/iproute2/rt_tables.d
62 fi
63 if [ -d /etc/iproute2/ ]; then
64 rmdir --ignore-fail-on-non-empty /etc/iproute2
65 fi
66 fi
67
68 exit 0