Commit | Line | Data |
---|---|---|
a52025b1 MN |
1 | #! /bin/sh |
2 | # postinst script for asterisk-config-auf | |
3 | # | |
4 | # see: dh_installdeb(1) | |
5 | ||
6 | ||
7 | set -e | |
8 | . /usr/share/debconf/confmodule | |
9 | ||
10 | # summary of how this script can be called: | |
11 | # * <postinst> `configure' <most-recently-configured-version> | |
12 | # * <old-postinst> `abort-upgrade' <new version> | |
13 | # * <conflictor's-postinst> `abort-remove' `in-favour' <package> | |
14 | # <new-version> | |
15 | # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' | |
16 | # <failed-install-package> <version> `removing' | |
17 | # <conflicting-package> <version> | |
18 | # for details, see http://www.debian.org/doc/debian-policy/ or | |
19 | # the debian-policy package | |
20 | # | |
21 | ||
22 | case "$1" in | |
23 | configure) | |
24 | set +e # ignore errors temporarily | |
25 | ||
26 | # find conffiles under /etc/asterisk belonging to asterisk-config | |
27 | # and chown them to user asterisk. | |
28 | dpkg-query -W -f='${Conffiles}\n' asterisk-config 2>/dev/null | \ | |
29 | sed -nr -e 's; (/etc/asterisk/.*) [0-9a-f]*;\1;p' | \ | |
30 | while read conffile; do | |
31 | chown asterisk: ${conffile} 2>/dev/null | |
32 | done | |
33 | ||
34 | # handle them in the end with a glob since it's way faster | |
35 | dpkg-statoverride --quiet --list '/etc/asterisk/*' | while read STAT; do | |
36 | chown `echo $STAT | cut -d' ' -f 1,2,4 | sed 's/ /:/'` \ | |
37 | 2>/dev/null | |
38 | done | |
39 | ||
40 | # extrait du postinst general a tous les paquets asterisk... | |
41 | ||
42 | # add asterisk user and add it to dialout and audio groups | |
43 | if ! getent passwd asterisk > /dev/null ; then | |
44 | echo 'Adding system user for Asterisk' 1>&2 | |
45 | adduser --system --group --quiet \ | |
46 | --home /var/lib/asterisk \ | |
47 | --no-create-home --disabled-login \ | |
48 | --gecos "Asterisk PBX daemon" \ | |
49 | asterisk | |
50 | for group in dialout audio; do | |
51 | if groups asterisk | grep -w -q -v $group; then | |
52 | adduser asterisk $group | |
53 | fi | |
54 | done | |
55 | fi | |
56 | ||
57 | # création du répertoire spécifique configs AUF | |
58 | test -d /etc/asterisk/auf || mkdir -p /etc/asterisk/auf | |
59 | ||
60 | chown -R root:asterisk /etc/asterisk | |
61 | chmod 0755 /etc/asterisk | |
62 | chmod 0755 /etc/asterisk/auf | |
63 | chmod 0640 /etc/asterisk/*.conf 2> /dev/null || true | |
64 | #chmod 0640 /etc/asterisk/auf/* 2> /dev/null || true | |
65 | ||
66 | # s'ils n'existent pas, création des fichiers /etc/asterisk/auf/*.local | |
67 | # depuis des modèles contenus dans /usr/share/doc/asterisk-config-auf/auf/ | |
68 | for FROMDOC in /usr/share/doc/asterisk-config-auf/auf/*.local | |
69 | do | |
70 | CONFIGFILE=/etc/asterisk/auf/`basename ${FROMDOC}` | |
71 | if [ ! -e ${CONFIGFILE} ]; then | |
72 | cat < ${FROMDOC} > ${CONFIGFILE} | |
73 | chown root:asterisk $CONFIGFILE | |
74 | chmod 640 $CONFIGFILE | |
75 | fi | |
76 | done | |
77 | # si "fuseaulocal=UTC" on remplace par le timezone correct (celui de /etc/timezone, s'il existe) | |
78 | if grep -q "^fuseaulocal=UTC|" /etc/asterisk/auf/voicemail.local | |
79 | then | |
80 | ETCTZ=`cat /etc/timezone 2> /dev/null || echo UTC` | |
81 | if test -e "/usr/share/zoneinfo/${ETCTZ}" | |
82 | then | |
83 | sed -i -e 's#^fuseaulocal=UTC|\(.*\)$#fuseaulocal='"${ETCTZ}"'|\1#' /etc/asterisk/auf/voicemail.local | |
84 | fi | |
85 | fi | |
5bc84f52 MN |
86 | # on vérifie le locale et on met le bon au besoin |
87 | LOCALE_LC_ALL=`echo $LC_ALL` | |
88 | if [ "${LOCALE_LC_ALL}" != "fr_FR.utf8" -a -n "${LOCALE_LC_ALL}" ] | |
89 | then | |
90 | LOCALE_TO_SET=`echo ${LOCALE_LC_ALL%.*}` | |
91 | sed -i -e 's#^locale=fr_FR.UTF-8#locale='"${LOCALE_TO_SET}"'.UTF-8#' /etc/asterisk/auf/voicemail.local | |
92 | fi | |
a52025b1 MN |
93 | |
94 | # | |
95 | # Partie "debconf" pour la gestion de auf/extensions-globals.local | |
96 | # | |
97 | ||
98 | # Substitue les valeurs par celles dans la base de données de debconf. | |
99 | db_get asterisk-config-auf/implantation | |
100 | IMPLANTATION="$RET" | |
101 | db_get asterisk-config-auf/clef | |
102 | CLEF="$RET" | |
103 | db_get asterisk-config-auf/prefixe | |
104 | PREFIXE="$RET" | |
105 | ||
106 | AUFAUTH=$IMPLANTATION":["$CLEF"]" | |
107 | AUFPREFIX=$PREFIXE | |
108 | AUFPREFIXLEN=`echo -n $AUFPREFIX | wc -c` | |
109 | ||
110 | # On remplace les valeurs dans le fichier de configuration | |
111 | # (d'abord un "cp" pour garder les bons droits) | |
112 | CONFIGFILE=/etc/asterisk/auf/extensions-globals.local | |
113 | cp -a -f $CONFIGFILE $CONFIGFILE.postinst.tmp | |
114 | sed -e "s/^ *AUFAUTH=.*/AUFAUTH=$AUFAUTH/" \ | |
115 | -e "s/^ *AUFPREFIX=.*/AUFPREFIX=$AUFPREFIX/" \ | |
116 | -e "s/^ *AUFPREFIXLEN=.*/AUFPREFIXLEN=$AUFPREFIXLEN/" \ | |
117 | < $CONFIGFILE > $CONFIGFILE.postinst.tmp | |
118 | mv -f $CONFIGFILE.postinst.tmp $CONFIGFILE | |
119 | ||
120 | chown root:asterisk $CONFIGFILE | |
121 | chmod 0640 $CONFIGFILE | |
122 | ||
123 | #chown root:asterisk /etc/asterisk/auf/* || true | |
124 | #chmod 0640 /etc/asterisk/auf/* || true | |
125 | ||
126 | if [ -x /etc/init.d/asterisk ]; then | |
127 | invoke-rc.d asterisk reload || true | |
128 | fi | |
129 | ||
130 | set -e | |
131 | ||
132 | ;; | |
133 | ||
134 | abort-upgrade|abort-remove|abort-deconfigure) | |
135 | ||
136 | ;; | |
137 | ||
138 | *) | |
139 | echo "postinst called with unknown argument \`$1'" >&2 | |
140 | exit 1 | |
141 | ;; | |
142 | esac | |
143 | ||
144 | # dh_installdeb will replace this with shell code automatically | |
145 | # generated by other debhelper scripts. | |
146 | ||
147 | #DEBHELPER# | |
148 | ||
149 | exit 0 | |
150 | ||
151 |