Upgrade paketa za Debian lenny.
[squirrelmail-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -x 
6
7 # Source debconf library.
8 . /usr/share/debconf/confmodule
9
10 case "$1" in
11         configure)
12                 # continue below
13                 ;;
14
15         abort-upgrade|abort-remove|abort-deconfigure)
16                 exit 0
17                 ;;
18
19         *)
20                 echo "postinst called with unknown argument \`$1'" >&2
21                 exit 0
22                 ;;
23 esac
24
25
26 PKG=squirrelmail-cn
27 domainname=`dnsdomainname`
28 FQDN=`hostname --fqdn`
29
30 # Include CARNet functions
31 . /usr/share/carnet-tools/functions.sh
32 unset CP_ECHO_RETURN
33
34 mv_old_backups() {
35
36         # Clean up /etc, nove old jun^H^H^Hbackups where they belong
37         glob="$1.old.*-*-*.*:*:*"
38         
39         # ${glob%/*} (dirname $glob) does not work for files in root
40         if [ -n "$(find ${glob%/*} -name ${glob##*/})" ]; then
41                 for i in $(find ${glob%/*} -name ${glob##*/})
42                 do
43                         cp_backup_conffile "$i" "$2"
44                         rm -f "$i"
45                 done
46         fi
47 }
48
49 # listconffiles ()
50 #
51 #   Recursively walks /etc/apache2/apache2.conf for Include directives.
52 #   Returns all configfiles so defined.
53 #
54 listconffiles () {
55
56         local i incs
57
58         incs=`awk 'tolower($1) == "include" { sub("/$","/*",$2); print $2; }' $1`
59         if [ -n "$incs" ]; then
60             for i in $incs; do
61                 if [ -e "$i" ]; then echo "$i"; listconffiles "$i"; fi
62             done
63         fi
64 }
65
66
67 need_restart=0
68 DATE=`date +%Y-%m-%d.%H:%M:%S`
69 CONFDIR=/etc/squirrelmail
70 CONF=$CONFDIR/apache.conf
71
72 backup_name=squirrelmail_apache.conf
73 mv_old_backups $CONF $backup_name
74
75 # Check Apache2 web server configuration.
76 #
77 if [ -f "$CONF" ]; then
78
79         # Backup first.
80         if cp_check_and_backup "$CONF" "$backup_name"; then
81                 cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"."
82         fi
83
84         # Check if we already modified apache.conf
85         if ! egrep -q "^[       ]+RewriteRule \. https" "$CONF"; then
86                 
87                 echo -n "CN: Updating Apache2 configuration for Squirrelmail"
88                 perl -n -e 'print if ! m|^Alias\s*/webmail|' "$CONF" > $CONF.tmp
89                 
90                 cp-update -t squirrelmail-cn $CONF.tmp <<-EOF
91         # Force SSL for /webmail -> you can still use /squirrelmail
92         Alias /webmail /usr/share/squirrelmail
93         
94         <IfModule mod_rewrite.c>
95           <IfModule mod_ssl.c>
96             <Location /webmail>
97               RewriteEngine on
98               RewriteCond %{HTTPS} !=on
99               RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}  [L]
100             </Location>
101           </IfModule>
102         </IfModule>
103         
104         #
105         # WARNING: This file is automatically included in each VirtualHost
106         # entry you might have.  Do not enable the VirtualHost example provided
107         # in this file, it WILL break your Apache configuration. Copy the
108         # VirtualHost section to the standard webserver configuration file
109         # instead.
110         #
111         EOF
112                 cp_mv $CONF.tmp $CONF
113
114                 # This will break if cp_backup_conffile ever changes destination path
115                 if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then
116                         echo "."
117                         cp_echo "CN: Updated Apache2 configuration for Squirrelmail."
118                         need_restart=1
119                 else
120                         echo "... no changes."
121                 fi
122         fi
123 fi
124
125
126 hconf=/etc/apache2/apache2.conf
127 sconf=/etc/apache2/sites-available/ssl
128
129 # Include Squirrelmail apache.conf in Apache2 web server configuration
130 # (directory /etc/apache2/conf.d/), but only if we are not present in 
131 # Apache2 configuration at all.
132 #
133 # We're not using listconffiles from apache-common Debian package.
134 # apache-common is no longer available in Debian Lenny. We're using
135 # listconffiles() function instead.
136 #
137 apache2listconf=`listconffiles "$hconf" | grep "$CONF"` || true
138 apache2squirrel=`ls -l /etc/apache2/conf.d/ | grep "$CONF"` || true
139
140 if [ -z "$apache2listconf" -a -z "$apache2squirrel" ]; then
141         ln -s "$CONF" /etc/apache2/conf.d/squirrelmail-cn.conf
142         need_restart=1
143 fi
144
145
146 # Initial CARNet config tweaks.
147 #
148 CONF="$CONFDIR/config.php"
149 TMPL="$CONFDIR/config_default.php"
150 mv_old_backups "$CONF" "`basename $CONF`"
151 if cp_check_and_backup "$CONF"; then
152         cp_echo "CN: Old $CONF saved as \"/var/backups/${CONF##*/}.bak\"."
153 fi
154
155 # We use sed to replace old defaults with ours.
156 # Must escape \$ because of shell expansion.
157 #
158 seddef="/^[     ]*\\\$org_logo[         ]*=/s/sm_logo\.jpg/sm_carnet_logo.png/;
159         /^[     ]*\\\$org_logo[         ]*=/s/sm_logo\.png/sm_carnet_logo.png/;
160         /^[     ]*\\\$org_logo[         ]*=/s/sm_carnet_logo\.jpg/sm_carnet_logo.png/;
161         /^[     ]*\\\$domain[   ]*=/s/mydomain\.com/$domainname/;
162         /^[     ]*\\\$default_charset[  ]*=/s/iso-8859-1/iso-8859-2/;
163         /^[     ]*\\\$org_logo_width[   ]*=/s/308/0/;
164         /^[     ]*\\\$org_logo_height[  ]*=/s/111/0/;
165         /^[     ]*\\\$squirrelmail_default_language[    ]*=/s/en_US/hr_HR/;
166         /^[     ]*\\\$data_dir[         ]*=/s/\.\.\/data\//\/var\/lib\/squirrelmail\/data\//;
167         "
168
169 # Left frame size to 220px.
170 # $default_left_size = '220';
171 #
172 db_get squirrelmail-cn/leftwidth || true
173 if [ "$RET" = "true" ]; then
174   seddef="$seddef/^[    ]*\\\$default_left_size[        ]*=/s/'[0-9]*'/'220'/;
175         "
176 fi
177
178 # Change CSS file for Squirrelmail.
179 # $theme_css = SM_PATH . 'themes/css/squirrelmail-cn.css';
180 #
181 db_get squirrelmail-cn/themecss || true
182 if [ "$RET" = "true" ]; then
183   seddef="$seddef/^[    ]*\\\$theme_css[        ]*=/s/=.*/= SM_PATH . 'themes\/css\/squirrelmail-cn.css';/;
184         "
185 fi
186
187 db_stop || true
188
189 # Check for our dovecot package; if it is installed, assume it's used.
190 #
191 if dpkg -l dovecot-cn 2>/dev/null | grep -q '^ii'; then
192   seddef="$seddef/^[    ]*\\\$imap_server_type[         ]*=/ {s/cyrus/dovecot/;s/other/dovecot/;s/uw/dovecot/}
193         "
194 fi
195
196 # Would there be any changes, perhaps?
197 #
198 if cp_check_and_sed '.' "$seddef" "$CONF"; then
199         need_restart=1
200 fi
201
202
203 # Check /etc/hostname and /etc/mailname, because
204 #   $domain = trim(implode('', file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));
205 #
206 nodots=
207 nomailname=
208 grep -q '\.' /etc/hostname || nodots=1
209 [ -e /etc/mailname ] || nomailname=1
210
211
212 # Generate hr_HR locale if needed.
213 #
214 if ! egrep -q '^hr_HR ISO-8859-2\b' /etc/locale.gen; then
215         if [ -f /etc/locale.gen ]; then
216                 echo "hr_HR ISO-8859-2" >> /etc/locale.gen
217                 cp_echo "CN: Added hr_HR locale to /etc/locale.gen."
218         else
219                 echo "hr_HR ISO-8859-2" > /etc/locale.gen
220                 cp_echo "CN: /etc/locale.gen created."
221         fi
222         dpkg-reconfigure -f noninteractive locales
223         need_restart=1
224 fi
225
226
227 # Check Apache2 web server for restart.
228 #
229 if [ $need_restart -eq 1 ]; then
230
231         # Restart Apache2 web server.
232         if [ -x "/etc/init.d/apache2" ]; then
233                 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
234                     invoke-rc.d apache2 restart || exit $?
235                 else
236                     /etc/init.d/apache2 restart || exit $?
237                 fi
238         fi
239 fi
240
241
242 # Mailname info...
243 #
244 if [ "$nodots" -o "$nomailname" ]; then
245         cp_echo
246         cp_echo "CN: Make sure that /etc/mailname contains a fully qualified domain name"
247         cp_echo "CN  of this machine!  Sending mail via squirrelmail might fail if the FQDN"
248         cp_echo "CN  cannot be found in either /etc/mailname or /etc/hostname."
249         cp_echo "CN  Read mailname(5) man page for details."
250         cp_echo -mailonly "CN  If this machine receives mail for both user@`hostname -f` and "
251         cp_echo -mailonly "CN  user@`hostname -d`, you can also put just the domain in there."
252 fi
253
254 # Mail root
255 #
256 cp_mail "$PKG"
257
258 exit 0