preparation adaptations SIP (NAT et domaines)
[asterisk-config-auf.git] / debian / postinst
CommitLineData
b2e905a6
TN
1#! /bin/sh
2# postinst script for asterisk-config-auf
3#
4# see: dh_installdeb(1)
5
6
7set -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
22case "$1" in
23 configure)
24
25 # extrait du postinst general a tous les paquets asterisk...
26
27 # add asterisk user and add it to dialout and audio groups
28 if ! getent passwd asterisk > /dev/null ; then
29 echo 'Adding system user for Asterisk' 1>&2
30 adduser --system --group --quiet \
31 --home /var/lib/asterisk \
32 --no-create-home --disabled-login \
33 --gecos "Asterisk PBX daemon" \
34 asterisk
35 for group in dialout audio; do
36 if groups asterisk | grep -w -q -v $group; then
37 adduser asterisk $group
38 fi
39 done
40 fi
41
42 # création du répertoire spécifique configs AUF
43 test -d /etc/asterisk/auf || mkdir -p /etc/asterisk/auf
44
45 chown -R root:asterisk /etc/asterisk
46 chmod 0755 /etc/asterisk
47 chmod 0755 /etc/asterisk/auf
48 chmod 0640 /etc/asterisk/*.conf 2> /dev/null || true
49 #chmod 0640 /etc/asterisk/auf/* 2> /dev/null || true
50
adb2451a
TN
51 # s'ils n'existent pas, création des fichiers /etc/asterisk/auf/*.local
52 # depuis des modèles contenus dans /usr/share/doc/asterisk-config-auf/auf/
53 for FROMDOC in /usr/share/doc/asterisk-config-auf/auf/*.local
54 do
55 CONFIGFILE=/etc/asterisk/auf/`basename ${FROMDOC}`
56 if [ ! -e ${CONFIGFILE} ]; then
57 cat < ${FROMDOC} > ${CONFIGFILE}
58 chown root:asterisk $CONFIGFILE
59 chmod 640 $CONFIGFILE
60 fi
61 done
b2e905a6
TN
62
63 #
64 # Partie "debconf" pour la gestion de auf/extensions-globals.local
65 #
66
67 # Substitue les valeurs par celles dans la base de données de debconf.
68 db_get asterisk-config-auf/implantation
69 IMPLANTATION="$RET"
70 db_get asterisk-config-auf/clef
71 CLEF="$RET"
72 db_get asterisk-config-auf/prefixe
73 PREFIXE="$RET"
74
75 AUFAUTH=$IMPLANTATION":["$CLEF"]"
76 AUFPREFIX=$PREFIXE
77 AUFPREFIXLEN=`echo -n $AUFPREFIX | wc -c`
78
79 # On remplace les valeurs dans le fichier de configuration
80 # (d'abord un "cp" pour garder les bons droits)
81 cp -a -f $CONFIGFILE $CONFIGFILE.postinst.tmp
82 sed -e "s/^ *AUFAUTH=.*/AUFAUTH=$AUFAUTH/" \
83 -e "s/^ *AUFPREFIX=.*/AUFPREFIX=$AUFPREFIX/" \
84 -e "s/^ *AUFPREFIXLEN=.*/AUFPREFIXLEN=$AUFPREFIXLEN/" \
85 < $CONFIGFILE > $CONFIGFILE.postinst.tmp
86 mv -f $CONFIGFILE.postinst.tmp $CONFIGFILE
87
88 chown root:asterisk $CONFIGFILE
89 chmod 0640 $CONFIGFILE
90
b2e905a6
TN
91 #chown root:asterisk /etc/asterisk/auf/* || true
92 #chmod 0640 /etc/asterisk/auf/* || true
93
94 if [ -x /etc/init.d/asterisk ]; then
95 /etc/init.d/asterisk reload || true
96 fi
97
98 ;;
99
100 abort-upgrade|abort-remove|abort-deconfigure)
101
102 ;;
103
104 *)
105 echo "postinst called with unknown argument \`$1'" >&2
106 exit 1
107 ;;
108esac
109
110# dh_installdeb will replace this with shell code automatically
111# generated by other debhelper scripts.
112
113#DEBHELPER#
114
115exit 0
116
117