0b88b432ab2d9fc1c350b56727f4f239b1b052d7
[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 # Include CARNet functions
9 . /usr/share/carnet-tools/functions.sh
10
11 PKG="squirrelmail-change-pass-cn"
12 VERSION="3.0.2"
13 SQCONFDIR="/etc/squirrelmail"
14 SQCONF="$SQCONFDIR/config.php"
15 SQCPCONF="$SQCONFDIR/config_change_pass.php"
16 CPCONF="/usr/share/squirrelmail/plugins/change_pass/config.php"
17 need_restart=0
18
19
20 # Configure poppassd to refuse connection from all hosts
21 # but localhost (127.0.0.1).
22 #
23 if [ ! -f /etc/hosts.deny ]; then
24     touch /etc/hosts.deny
25 fi
26 if ! egrep -q '^poppassd:' /etc/hosts.deny; then
27     echo "poppassd: ALL" | cp-update "$PKG" /etc/hosts.deny
28 fi
29 if [ ! -f /etc/hosts.allow ]; then
30     touch /etc/hosts.allow
31 fi
32 if ! egrep -q '^poppassd:' /etc/hosts.allow; then
33     echo "poppassd: 127.0.0.1" | cp-update "$PKG" /etc/hosts.allow
34 fi
35
36
37 # First of all, do the backup.
38 #
39 done_backup=0
40 for cpconf_file in $SQCPCONF $CPCONF; do
41     if [ -f "$cpconf_file" ] && [ ! -L "$cpconf_file" ]; then
42         cp_echo "CN: Doing backup for $cpconf_file"
43         cp_backup_conffile -d "/var/backups/$PKG" -p $cpconf_file
44         done_backup=1
45     fi
46 done
47 if [ $done_backup -eq 1 ]; then
48     cp_echo "CN: Backup is located in directory: /var/backups/$PKG/"
49 fi
50
51
52 # Enable change_pass plugin in SquirrelMail config.php.
53 #
54 if ! egrep -q '^\$plugins\[[0-9]+\][\ ]*=[\ ]*'\''change_pass'\' "$SQCONF"; then
55     /usr/sbin/squirrelmail-configure --install-plugin change_pass
56 fi
57
58
59 # Convert poppassd service from inetd.conf to xinetd.conf type.
60 # Service configuration is saved in /etc/xinetd.d/ directory.
61 #
62 if [ -x /etc/init.d/xinetd -a -d /etc/xinetd.d -a -x /usr/sbin/itox ]; then
63
64     if egrep -q '^poppassd' /etc/inetd.conf && \
65         [ ! -f /etc/xinetd.d/poppassd ]; then
66
67         cp_echo "CN: Enabling poppassd in /etc/xinetd.d/poppassd"
68
69         touch /etc/xinetd.d/poppassd.$$
70         grep "^poppassd" /etc/inetd.conf  | \
71             itox -daemon_dir /usr/sbin | cp-update "$PKG" /etc/xinetd.d/poppassd.$$
72         cp_mv /etc/xinetd.d/poppassd.$$ /etc/xinetd.d/poppassd
73
74         need_restart=1
75     fi
76 fi
77
78
79 # Restart xinetd if needed.
80 #
81 if [ $need_restart -eq 1 ]; then
82
83     if [ -x "/etc/init.d/xinetd" ]; then
84         if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
85             invoke-rc.d xinetd restart || exit $?
86         else
87             /etc/init.d/xinetd restart || exit $?
88         fi
89     fi
90 fi
91
92
93 # Mail root
94 #
95 cp_mail "$PKG"
96
97 #DEBHELPER#
98
99 exit 0