Prva inacica paketa za Debian jessie distribuciju.
[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
35 if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
36     . /usr/share/apache2/apache2-maintscript-helper
37
38     squirrelmail_enable() {
39         cp_echo "CN: Enabling $PKG configuration for Apache2."
40         return 0
41     }
42 else
43     cp_echo "CN: Could not load Apache 2.4 maintainer script helper."
44
45     squirrelmail_enable() {
46         return 1
47     }
48 fi
49
50 mv_old_backups () {
51     # Clean up /etc, nove old jun^H^H^Hbackups where they belong
52     local glob="$1.old.*-*-*.*:*:*"
53
54     # ${glob%/*} (dirname $glob) does not work for files in root
55     if [ -n "$(find ${glob%/*} -name ${glob##*/})" ]; then
56         for i in $(find ${glob%/*} -name ${glob##*/})
57         do
58             cp_backup_conffile "$i" "$2"
59             rm -f "$i"
60         done
61     fi
62 }
63
64 # listconffiles ()
65 #
66 #   Recursively walks /etc/apache2/apache2.conf for Include and
67 #   IncludeOptional directives.
68 #   Returns all configfiles so defined.
69 #
70 listconffiles () {
71     local i incs
72     local base_dir="`dirname $1`"
73
74     incs=`awk 'tolower($1) ~ /include(optional)?/ { sub("/$","/*",$2); print $2; }' $1`
75     incs=`echo "$incs" | sed -r "s#^([^/])#${base_dir}/\1#"`
76     if [ -n "$incs" ]; then
77         for i in $incs; do
78             if [ -e "$i" ]; then echo "`readlink -m -q $i`"; listconffiles "$i"; fi
79         done
80     fi
81 }
82
83 # genlocales ()
84 #
85 #   Update/generate localisation files from templates if locales-all
86 #   is not installed.
87 #
88 genlocales () {
89     if [ -f /usr/lib/locales-all/supported.tar.lzma ] ; then
90         cp_echo "CN: locales-all installed, skipping locales generation."
91     else
92         locale-gen
93     fi
94 }
95
96
97 DATE=`date +%Y-%m-%d.%H:%M:%S`
98 CONFDIR=/etc/squirrelmail
99 CONF=$CONFDIR/apache.conf
100
101 backup_name=squirrelmail_apache.conf
102 mv_old_backups $CONF $backup_name
103
104 # Check Apache2 web server configuration.
105 #
106 if [ -f "$CONF" ]; then
107
108     # Backup first.
109     if cp_check_and_backup "$CONF" "$backup_name"; then
110         cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"."
111     fi
112
113     # Check if we already modified apache.conf
114     if ! egrep -q "^[   ]+RewriteRule \. https" "$CONF"; then
115         echo -n "CN: Updating Apache2 configuration for Squirrelmail"
116         perl -n -e 'print if ! m|^Alias\s*/webmail|' "$CONF" > $CONF.tmp
117
118         cp-update -t $PKG $CONF.tmp <<-EOF
119 # Force SSL for /webmail -> you can still use /squirrelmail
120 Alias /webmail /usr/share/squirrelmail
121
122 <IfModule mod_rewrite.c>
123   <IfModule mod_ssl.c>
124     <Location /webmail>
125       RewriteEngine on
126       RewriteCond %{HTTPS} !=on
127       RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}  [L]
128     </Location>
129   </IfModule>
130 </IfModule>
131
132 #
133 # WARNING: This file is automatically included in each VirtualHost
134 # entry you might have.  Do not enable the VirtualHost example provided
135 # in this file, it WILL break your Apache configuration. Copy the
136 # VirtualHost section to the standard webserver configuration file
137 # instead.
138 #
139 EOF
140         cp_mv $CONF.tmp $CONF
141
142         # This will break if cp_backup_conffile ever changes destination path
143         if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then
144             echo "."
145             cp_echo "CN: Updated Apache2 configuration for Squirrelmail."
146         else
147             echo "... no changes."
148         fi
149     fi
150 fi
151
152
153 hconf=/etc/apache2/apache2.conf
154 sconf=/etc/apache2/sites-available/ssl
155
156 # Remove obsolete symbolic link.
157 #
158 if [ "`readlink -q -m /etc/apache2/conf.d/$PKG.conf`" = "$CONF" ]; then
159     rm -f /etc/apache2/conf.d/$PKG.conf
160 fi
161
162 # Include Squirrelmail apache.conf in Apache2 web server configuration,
163 # but only if we are not present in Apache2 configuration at all.
164 #
165 apache2listconf=`listconffiles "$hconf" | grep "$CONF"` || true
166
167 if [ -z "$apache2listconf" ]; then
168     if [ ! -L /etc/apache2/conf-available/$PKG.conf -a ! -f /etc/apache2/conf-available/$PKG.conf ]; then
169         ln -sf "$CONF" /etc/apache2/conf-available/$PKG.conf
170     fi
171 fi
172
173
174 # Initial CARNet config tweaks.
175 #
176 CONF="$CONFDIR/config.php"
177 TMPL="$CONFDIR/config_default.php"
178 mv_old_backups "$CONF" "`basename $CONF`"
179 if cp_check_and_backup "$CONF"; then
180     cp_echo "CN: Old $CONF saved as \"/var/backups/${CONF##*/}.bak\"."
181 fi
182
183 # We use sed to replace old defaults with ours.
184 # Must escape \$ because of shell expansion.
185 #
186 seddef="/^[     ]*\\\$org_logo[         ]*=/s/sm_logo\.jpg/sm_carnet_logo.png/;
187         /^[     ]*\\\$org_logo[         ]*=/s/sm_logo\.png/sm_carnet_logo.png/;
188         /^[     ]*\\\$org_logo[         ]*=/s/sm_carnet_logo\.jpg/sm_carnet_logo.png/;
189         /^[     ]*\\\$domain[   ]*=/s/mydomain\.com/$domainname/;
190         /^[     ]*\\\$default_charset[  ]*=/s/iso-8859-1/iso-8859-2/;
191         /^[     ]*\\\$org_logo_width[   ]*=/s/308/0/;
192         /^[     ]*\\\$org_logo_height[  ]*=/s/111/0/;
193         /^[     ]*\\\$squirrelmail_default_language[    ]*=/s/en_US/hr_HR/;
194         /^[     ]*\\\$data_dir[         ]*=/s/\.\.\/data\//\/var\/lib\/squirrelmail\/data\//;
195         "
196
197 # Left frame size to 220px.
198 # $default_left_size = '220';
199 #
200 db_get squirrelmail-cn/leftwidth || true
201 if [ "$RET" = "true" ]; then
202     seddef="$seddef/^[  ]*\\\$default_left_size[        ]*=/s/'[0-9]*'/'220'/;
203         "
204 fi
205
206 # Change CSS file for Squirrelmail.
207 # $theme_css = SM_PATH . 'themes/css/squirrelmail-cn.css';
208 #
209 db_get squirrelmail-cn/themecss || true
210 if [ "$RET" = "true" ]; then
211     seddef="$seddef/^[  ]*\\\$theme_css[        ]*=/s/=.*/= SM_PATH . 'themes\/css\/squirrelmail-cn.css';/;
212         "
213 fi
214
215 db_stop || true
216
217 # Check for our dovecot package; if it is installed, assume it's used.
218 #
219 if dpkg -l dovecot-cn 2>/dev/null | grep -q '^ii'; then
220     seddef="$seddef/^[  ]*\\\$imap_server_type[         ]*=/ {s/cyrus/dovecot/;s/other/dovecot/;s/uw/dovecot/}
221         "
222 fi
223
224 cp_check_and_sed '.' "$seddef" "$CONF" || true
225
226
227 # Check /etc/hostname and /etc/mailname, because
228 #   $domain = trim(implode('', file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));
229 #
230 nodots=
231 nomailname=
232 grep -q '\.' /etc/hostname || nodots=1
233 [ -e /etc/mailname ] || nomailname=1
234
235
236 # Check for hr_HR locale.
237 #
238 if [ -f /etc/locale.gen ]; then
239     if ! egrep -q '^hr_HR ISO-8859-2\b' /etc/locale.gen; then
240         echo "hr_HR ISO-8859-2" >> /etc/locale.gen
241         cp_echo "CN: Added hr_HR locale to /etc/locale.gen."
242         genlocales
243     fi
244 else
245     echo "hr_HR ISO-8859-2" > /etc/locale.gen
246     cp_echo "CN: /etc/locale.gen created."
247     genlocales
248 fi
249
250
251 # Mailname info...
252 #
253 if [ "$nodots" -o "$nomailname" ]; then
254     cp_echo
255     cp_echo "CN: Make sure that /etc/mailname contains a fully qualified domain name"
256     cp_echo "CN  of this machine!  Sending mail via squirrelmail might fail if the FQDN"
257     cp_echo "CN  cannot be found in either /etc/mailname or /etc/hostname."
258     cp_echo "CN  Read mailname(5) man page for details."
259     cp_echo -mailonly "CN  If this machine receives mail for both user@`hostname -f` and "
260     cp_echo -mailonly "CN  user@`hostname -d`, you can also put just the domain in there."
261     cp_echo
262 fi
263
264 if squirrelmail_enable; then
265     apache2_invoke enconf $PKG
266 fi
267
268 if ! apache2ctl configtest >/dev/null 2>&1; then
269     cp_echo "CN: Your Apache2 configuration seems to be broken."
270     cp_echo "CN: Please, check the service after the installation finishes!"
271 fi
272
273 # Mail root
274 #
275 cp_mail "$PKG"
276
277 #DEBHELPER#
278
279 exit 0