83198930629762c28d59f4e0c451454b9e938a19
[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 min_pass_changed=0
19
20
21 # Configure poppassd to refuse connection from all hosts
22 # but localhost (127.0.0.1).
23 #
24 if [ ! -f /etc/hosts.deny ]; then
25     touch /etc/hosts.deny
26 fi
27 if ! egrep -q '^poppassd:' /etc/hosts.deny; then
28     echo "poppassd: ALL" | cp-update "$PKG" /etc/hosts.deny
29 fi
30 if [ ! -f /etc/hosts.allow ]; then
31     touch /etc/hosts.allow
32 fi
33 if ! egrep -q '^poppassd:' /etc/hosts.allow; then
34     echo "poppassd: 127.0.0.1" | cp-update "$PKG" /etc/hosts.allow
35 fi
36
37
38 # First of all, do the backup.
39 #
40 done_backup=0
41 for cpconf_file in $SQCPCONF $CPCONF; do
42     if [ -f "$cpconf_file" ] && [ ! -L "$cpconf_file" ]; then
43         cp_echo "CN: Doing backup for $cpconf_file"
44         cp_backup_conffile -d "/var/backups/$PKG" -p $cpconf_file
45         done_backup=1
46     fi
47 done
48 if [ $done_backup -eq 1 ]; then
49     cp_echo "CN: Backup is located in directory: /var/backups/$PKG/"
50 fi
51
52
53 # Remove change_pass configuration files if earlier version is
54 # older than 3.0-1.
55 #
56 if [ "$2" ] && dpkg --compare-versions $2 lt 3.0-1; then
57
58     cp_echo "CN: This version of change_pass plugin contains major changes."
59     for cpconf_file in $SQCPCONF $CPCONF; do
60         if [ -f "$cpconf_file" ] || [ -L "$cpconf_file" ]; then
61             rm -f $cpconf_file
62             cp_echo "CN: Removed old $cpconf_file"
63         fi
64     done
65 fi
66
67
68 # Check for change_pass configuration files and notify user about
69 # minimum password length configuration.
70 #
71 if egrep -q '^\$plugins\[[0-9]+\][\ ]*=[\ ]*'\''change_pass'\' "$SQCONF"; then
72     /usr/sbin/squirrelmail-configure --remove-plugin change_pass
73 fi
74
75 if [ ! -f "$SQCPCONF" ]; then
76
77     if [ -f "$CPCONF" ]; then
78         cp -f "$CPCONF" "$SQCPCONF"
79         cp_echo "CN: $CPCONF copied to $SQCPCONF"
80     else
81
82         # Configuration file does not exist.
83         cp_echo "CN: Generating new file $SQCPCONF"
84         cat > "$SQCPCONF" <<EOF
85 <?php
86     // The default server is the configured IMAP server
87     #\$poppass_server = 'localhost';
88
89     // The default port is 106
90     #\$poppass_port = 106;
91
92     \$min_pass_length = 8;
93     \$max_pass_length = 9999999;
94 EOF
95         min_pass_changed=1
96     fi
97 fi
98
99 # Just to be sure.
100 ln -sf "$SQCPCONF" "$CPCONF"
101
102 if [ $min_pass_changed -eq 1 ]; then
103     cp_echo "CN: Minimum password length has been set to 8 characters."
104 fi
105
106
107 # Enable change_pass plugin in SquirrelMail config.php.
108 #
109 if ! egrep -q '^\$plugins\[[0-9]+\][\ ]*=[\ ]*'\''change_pass'\' "$SQCONF"; then
110     /usr/sbin/squirrelmail-configure --install-plugin change_pass
111 fi
112
113
114 # Convert poppassd service from inetd.conf to xinetd.conf type.
115 # Service configuration is saved in /etc/xinetd.d/ directory.
116 #
117 if [ -x /etc/init.d/xinetd -a -d /etc/xinetd.d -a -x /usr/sbin/itox ]; then
118
119     if egrep -q '^poppassd' /etc/inetd.conf && \
120         [ ! -f /etc/xinetd.d/poppassd ]; then
121
122         cp_echo "CN: Enabling poppassd in /etc/xinetd.d/poppassd"
123
124         touch /etc/xinetd.d/poppassd.$$
125         grep "^poppassd" /etc/inetd.conf  | \
126             itox -daemon_dir /usr/sbin | cp-update "$PKG" /etc/xinetd.d/poppassd.$$
127         cp_mv /etc/xinetd.d/poppassd.$$ /etc/xinetd.d/poppassd
128
129         need_restart=1
130     fi
131 fi
132
133
134 # Restart xinetd if needed.
135 #
136 if [ $need_restart -eq 1 ]; then
137
138     if [ -x "/etc/init.d/xinetd" ]; then
139         if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
140             invoke-rc.d xinetd restart || exit $?
141         else
142             /etc/init.d/xinetd restart || exit $?
143         fi
144     fi
145 fi
146
147
148 # Mail root
149 #
150 cp_mail "$PKG"
151
152 #DEBHELPER#
153
154 exit 0