Izbacen 'dpkg-reconfigure -f noninteractive locales'.
[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 # genlocales ()
67 #
68 #   Update/generate localisation files from templates if locales-all
69 #   is not installed.
70 #
71 genlocales () {
72
73         if [ -f /usr/lib/locales-all/supported.tar.lzma ] ; then
74             cp_echo "CN: locales-all installed, skipping locales generation."
75         else
76             /usr/sbin/locale-gen
77         fi
78 }
79
80
81 need_restart=0
82 DATE=`date +%Y-%m-%d.%H:%M:%S`
83 CONFDIR=/etc/squirrelmail
84 CONF=$CONFDIR/apache.conf
85
86 backup_name=squirrelmail_apache.conf
87 mv_old_backups $CONF $backup_name
88
89 # Check Apache2 web server configuration.
90 #
91 if [ -f "$CONF" ]; then
92
93         # Backup first.
94         if cp_check_and_backup "$CONF" "$backup_name"; then
95                 cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"."
96         fi
97
98         # Check if we already modified apache.conf
99         if ! egrep -q "^[       ]+RewriteRule \. https" "$CONF"; then
100                 
101                 echo -n "CN: Updating Apache2 configuration for Squirrelmail"
102                 perl -n -e 'print if ! m|^Alias\s*/webmail|' "$CONF" > $CONF.tmp
103                 
104                 cp-update -t squirrelmail-cn $CONF.tmp <<-EOF
105         # Force SSL for /webmail -> you can still use /squirrelmail
106         Alias /webmail /usr/share/squirrelmail
107         
108         <IfModule mod_rewrite.c>
109           <IfModule mod_ssl.c>
110             <Location /webmail>
111               RewriteEngine on
112               RewriteCond %{HTTPS} !=on
113               RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}  [L]
114             </Location>
115           </IfModule>
116         </IfModule>
117         
118         #
119         # WARNING: This file is automatically included in each VirtualHost
120         # entry you might have.  Do not enable the VirtualHost example provided
121         # in this file, it WILL break your Apache configuration. Copy the
122         # VirtualHost section to the standard webserver configuration file
123         # instead.
124         #
125         EOF
126                 cp_mv $CONF.tmp $CONF
127
128                 # This will break if cp_backup_conffile ever changes destination path
129                 if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then
130                         echo "."
131                         cp_echo "CN: Updated Apache2 configuration for Squirrelmail."
132                         need_restart=1
133                 else
134                         echo "... no changes."
135                 fi
136         fi
137 fi
138
139
140 hconf=/etc/apache2/apache2.conf
141 sconf=/etc/apache2/sites-available/ssl
142
143 # Include Squirrelmail apache.conf in Apache2 web server configuration
144 # (directory /etc/apache2/conf.d/), but only if we are not present in 
145 # Apache2 configuration at all.
146 #
147 # We're not using listconffiles from apache-common Debian package.
148 # apache-common is no longer available in Debian Lenny. We're using
149 # listconffiles() function instead.
150 #
151 apache2listconf=`listconffiles "$hconf" | grep "$CONF"` || true
152 apache2squirrel=`ls -l /etc/apache2/conf.d/ | grep "$CONF"` || true
153
154 if [ -z "$apache2listconf" -a -z "$apache2squirrel" ]; then
155         ln -s "$CONF" /etc/apache2/conf.d/squirrelmail-cn.conf
156         need_restart=1
157 fi
158
159
160 # Initial CARNet config tweaks.
161 #
162 CONF="$CONFDIR/config.php"
163 TMPL="$CONFDIR/config_default.php"
164 mv_old_backups "$CONF" "`basename $CONF`"
165 if cp_check_and_backup "$CONF"; then
166         cp_echo "CN: Old $CONF saved as \"/var/backups/${CONF##*/}.bak\"."
167 fi
168
169 # We use sed to replace old defaults with ours.
170 # Must escape \$ because of shell expansion.
171 #
172 seddef="/^[     ]*\\\$org_logo[         ]*=/s/sm_logo\.jpg/sm_carnet_logo.png/;
173         /^[     ]*\\\$org_logo[         ]*=/s/sm_logo\.png/sm_carnet_logo.png/;
174         /^[     ]*\\\$org_logo[         ]*=/s/sm_carnet_logo\.jpg/sm_carnet_logo.png/;
175         /^[     ]*\\\$domain[   ]*=/s/mydomain\.com/$domainname/;
176         /^[     ]*\\\$default_charset[  ]*=/s/iso-8859-1/iso-8859-2/;
177         /^[     ]*\\\$org_logo_width[   ]*=/s/308/0/;
178         /^[     ]*\\\$org_logo_height[  ]*=/s/111/0/;
179         /^[     ]*\\\$squirrelmail_default_language[    ]*=/s/en_US/hr_HR/;
180         /^[     ]*\\\$data_dir[         ]*=/s/\.\.\/data\//\/var\/lib\/squirrelmail\/data\//;
181         "
182
183 # Left frame size to 220px.
184 # $default_left_size = '220';
185 #
186 db_get squirrelmail-cn/leftwidth || true
187 if [ "$RET" = "true" ]; then
188   seddef="$seddef/^[    ]*\\\$default_left_size[        ]*=/s/'[0-9]*'/'220'/;
189         "
190 fi
191
192 # Change CSS file for Squirrelmail.
193 # $theme_css = SM_PATH . 'themes/css/squirrelmail-cn.css';
194 #
195 db_get squirrelmail-cn/themecss || true
196 if [ "$RET" = "true" ]; then
197   seddef="$seddef/^[    ]*\\\$theme_css[        ]*=/s/=.*/= SM_PATH . 'themes\/css\/squirrelmail-cn.css';/;
198         "
199 fi
200
201 db_stop || true
202
203 # Check for our dovecot package; if it is installed, assume it's used.
204 #
205 if dpkg -l dovecot-cn 2>/dev/null | grep -q '^ii'; then
206   seddef="$seddef/^[    ]*\\\$imap_server_type[         ]*=/ {s/cyrus/dovecot/;s/other/dovecot/;s/uw/dovecot/}
207         "
208 fi
209
210 # Would there be any changes, perhaps?
211 #
212 if cp_check_and_sed '.' "$seddef" "$CONF"; then
213         need_restart=1
214 fi
215
216
217 # Check /etc/hostname and /etc/mailname, because
218 #   $domain = trim(implode('', file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));
219 #
220 nodots=
221 nomailname=
222 grep -q '\.' /etc/hostname || nodots=1
223 [ -e /etc/mailname ] || nomailname=1
224
225
226 # Check for hr_HR locale.
227 #
228 if [ -f /etc/locale.gen ]; then
229         if ! egrep -q '^hr_HR ISO-8859-2\b' /etc/locale.gen; then
230             echo "hr_HR ISO-8859-2" >> /etc/locale.gen
231             cp_echo "CN: Added hr_HR locale to /etc/locale.gen."
232             genlocales
233             need_restart=1
234         fi
235 else
236         echo "hr_HR ISO-8859-2" > /etc/locale.gen
237         cp_echo "CN: /etc/locale.gen created."
238         genlocales
239         need_restart=1
240 fi
241
242
243 # Check Apache2 web server for restart.
244 #
245 if [ $need_restart -eq 1 ]; then
246
247         # Restart Apache2 web server.
248         if [ -x "/etc/init.d/apache2" ]; then
249                 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
250                     invoke-rc.d apache2 restart || exit $?
251                 else
252                     /etc/init.d/apache2 restart || exit $?
253                 fi
254         fi
255 fi
256
257
258 # Mailname info...
259 #
260 if [ "$nodots" -o "$nomailname" ]; then
261         cp_echo
262         cp_echo "CN: Make sure that /etc/mailname contains a fully qualified domain name"
263         cp_echo "CN  of this machine!  Sending mail via squirrelmail might fail if the FQDN"
264         cp_echo "CN  cannot be found in either /etc/mailname or /etc/hostname."
265         cp_echo "CN  Read mailname(5) man page for details."
266         cp_echo -mailonly "CN  If this machine receives mail for both user@`hostname -f` and "
267         cp_echo -mailonly "CN  user@`hostname -d`, you can also put just the domain in there."
268 fi
269
270 # Mail root
271 #
272 cp_mail "$PKG"
273
274 exit 0