Debian Codegraph @

debian/asterisk.postinst

raw
1 #! /bin/sh
2
3 set -e
4
5 # summary of how this script can be called:
6 # * <postinst> `configure' <most-recently-configured-version>
7 # * <old-postinst> `abort-upgrade' <new version>
8 # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
9 # <new-version>
10 # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
11 # <failed-install-package> <version> `removing'
12 # <conflicting-package> <version>
13
14 case "$1" in
15 configure)
16 # add asterisk user
17 if ! getent passwd asterisk > /dev/null ; then
18 echo 'Adding system user for Asterisk' 1>&2
19 adduser --system --group --quiet \
20 --home /var/lib/asterisk \
21 --no-create-home --disabled-login \
22 --gecos "Asterisk PBX daemon" \
23 asterisk
24 fi
25
26 # add asterisk to required groups
27 for group in dialout audio; do
28 if groups asterisk | grep -w -q -v $group; then
29 adduser asterisk $group
30 fi
31 done
32
33 # chown asterisk on all $dirs and their subdirectories
34 # do not harm the files, they should be empty on new installations
35 # and we don't want to mess-up anything on old installations
36 find /var/log/asterisk \
37 /var/lib/asterisk \
38 -type d | while read dir; do
39 if ! dpkg-statoverride --list "$dir" > /dev/null ; then
40 chown asterisk: "$dir"
41 fi
42 done
43
44 # this is not needed for new installations but is not such a bad idea
45 # removing this will _break_ upgrades from versions < 1:1.4.10.1~dfsg-1
46 #
47 # we are doing the same for subdirectories, since we are not shipping
48 # any and it's supposed to be user-modifiable
49 if ! dpkg-statoverride --list "/etc/asterisk" > /dev/null ; then
50 chown asterisk: /etc/asterisk
51 fi
52
53 # these hold some sensitive information (e.g. monitor, voicemail etc.)
54 find /var/spool/asterisk /var/cache/asterisk -type d \
55 | while read dir; do
56 if ! dpkg-statoverride --list "$dir" > /dev/null ; then
57 chown asterisk: "$dir"
58 chmod 750 "$dir"
59 fi
60 done
61
62 # Create /usr/local directory; policy 9.1.2
63 if [ ! -e /usr/local/share/asterisk/sounds ]; then
64 if mkdir -p /usr/local/share/asterisk/sounds 2>/dev/null ; then
65 chown root:staff /usr/local/share/asterisk/sounds
66 chmod 2775 /usr/local/share/asterisk/sounds
67 fi
68 fi
69
70 ### this is done here in case asterisk-config was installed/upgraded first
71
72 set +e # ignore errors temporarily
73
74 # find the name of the package providing config; either asterisk-config
75 # or a package providing asterisk-config-custom
76 ASTERISK_CONFIG=`dpkg-query -W -f='${Package}\t${Provides}\n' | \
77 sed -nr 's/(.*)\tasterisk-config-custom|(asterisk-config)(\t.*)?/\1\2/p'`
78
79 # find conffiles under /etc/asterisk belonging to asterisk-config
80 # and chown them to user asterisk.
81 dpkg-query -W -f='${Conffiles}\n' $ASTERISK_CONFIG 2>/dev/null | \
82 sed -nr -e 's; (/etc/asterisk/.*) [0-9a-f]*;\1;p' | \
83 while read conffile; do
84 chown asterisk: "$conffile" 2>/dev/null
85 done
86
87 # handle them in the end with a glob since it's way faster
88 dpkg-statoverride --quiet --list '/etc/asterisk/*' | while read STAT; do
89 chown `echo $STAT | cut -d' ' -f 1,2,4 | sed 's/ /:/'` \
90 2>/dev/null
91 done
92
93 set -e
94 ;;
95
96 abort-upgrade|abort-remove|abort-deconfigure)
97 ;;
98
99 *)
100 echo "postinst called with unknown argument \`$1'" >&2
101 exit 1
102 ;;
103 esac
104
105 # dh_installdeb will replace this with shell code automatically
106 # generated by other debhelper scripts.
107
108 #DEBHELPER#
109
110 exit 0
111
112