72de9fbafc27a22aec43e3d7e046a5bdc2dcf739
[squirrelmail-change-pass-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$1" = "configure" ] || exit 0
6 [ $DEBIAN_SCRIPT_DEBUG ] && set -vx
7
8
9 PKG="squirrelmail-change-pass-cn"
10 SQCONF=/etc/squirrelmail/config.php
11
12 # Include CARNet functions
13 . /usr/share/carnet-tools/functions.sh
14
15
16 # Configure poppassd to refuse connection from all hosts
17 # but localhost (127.0.0.1).
18 #
19 if [ -e /etc/hosts.deny -a -e /etc/hosts.allow ]; then
20
21   if ! egrep -q '^poppassd:' /etc/hosts.deny; then
22         echo "poppassd: ALL" | cp-update "$PKG" /etc/hosts.deny
23   fi
24
25   if ! egrep -q '^poppassd:' /etc/hosts.allow; then
26         echo "poppassd: 127.0.0.1" | cp-update "$PKG" /etc/hosts.allow
27   fi
28 fi
29
30
31 # Enable change_pass plugin in SquirrelMail config.php.
32 #
33 if ! egrep '^\$plugins\[[0-9]+\][\ ]*=[\ ]*'\''change_pass'\' "$SQCONF"; then
34
35   sq_last_plugin=`egrep '^\\$plugins\[[0-9]+\][\ ]*=[\ ]*'\' "$SQCONF" | sed 's/^.*\[//;s/\].*//' | sort -n | tail -n1` || true
36   
37   if [ -n "$sq_last_plugin" ]; then
38
39         # Backup SquirrelMail configuration file.
40         cp_check_and_backup "$SQCONF"
41
42         change_pass_num=$sq_last_plugin
43         let change_pass_num++
44         
45         SQCONFTMP=`mktemp $SQCONF.tmp.XXXXXX`
46
47         echo -n "CN: Enabling SquirrelMail change_pass plugin in $SQCONF"
48         sed '/^$plugins\[.*'${sq_last_plugin}'\]/a $plugins['${change_pass_num}'] = '\''change_pass'\'';' "$SQCONF" > "$SQCONFTMP"
49         cp_mv "$SQCONFTMP" "$SQCONF"
50         echo "."
51   fi
52
53 fi
54
55
56 # Convert poppassd service from inetd.conf to xinetd.conf type.
57 # Service configuration is saved in /etc/xinetd.d/ directory.
58 #
59 if [ -x /etc/init.d/xinetd -a -d /etc/xinetd.d -a -x /usr/sbin/itox ]; then
60
61   if egrep -q '^poppassd' /etc/inetd.conf && \
62      [ ! -e /etc/xinetd.d/poppassd ]; then
63
64         echo -n "CN: Enabling poppassd in /etc/xinetd.d/poppassd"
65
66         touch /etc/xinetd.d/poppassd.$$
67         grep "^poppassd" /etc/inetd.conf  | \
68                 itox -daemon_dir /usr/sbin | cp-update "$PKG" /etc/xinetd.d/poppassd.$$
69         cp_mv /etc/xinetd.d/poppassd.$$ /etc/xinetd.d/poppassd
70
71         changed_config=1
72         echo "."
73   fi
74 fi
75
76
77 # Restart xinetd if needed.
78 #
79 [ "$changed_config" ] && do=reload
80 pgrep -u root -f /usr/sbin/xinetd > /dev/null || do=start
81
82 if [ "$do" ]; then
83
84         if [ -x "/etc/init.d/xinetd" ]; then
85                 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
86                         invoke-rc.d xinetd "$do" || exit $?
87                 else
88                         /etc/init.d/xinetd "$do" || exit $?
89                 fi
90         fi
91 fi
92
93 exit 0