5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -x
7 # Source debconf library.
8 . /usr/share/debconf/confmodule
15 abort-upgrade|abort-remove|abort-deconfigure)
20 echo "postinst called with unknown argument \`$1'" >&2
27 domainname=`dnsdomainname`
28 FQDN=`hostname --fqdn`
30 # Include CARNet functions
31 . /usr/share/carnet-tools/functions.sh
36 # Clean up /etc, nove old jun^H^H^Hbackups where they belong
37 glob="$1.old.*-*-*.*:*:*"
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##*/})
43 cp_backup_conffile "$i" "$2"
51 # Recursively walks /etc/apache2/apache2.conf for Include directives.
52 # Returns all configfiles so defined.
58 incs=`awk 'tolower($1) == "include" { sub("/$","/*",$2); print $2; }' $1`
59 if [ -n "$incs" ]; then
61 if [ -e "$i" ]; then echo "$i"; listconffiles "$i"; fi
68 DATE=`date +%Y-%m-%d.%H:%M:%S`
69 CONFDIR=/etc/squirrelmail
70 CONF=$CONFDIR/apache.conf
72 backup_name=squirrelmail_apache.conf
73 mv_old_backups $CONF $backup_name
75 # Check Apache2 web server configuration.
77 if [ -f "$CONF" ]; then
80 if cp_check_and_backup "$CONF" "$backup_name"; then
81 cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"."
84 # Check if we already modified apache.conf
85 if ! egrep -q "^[ ]+RewriteRule \. https" "$CONF"; then
87 echo -n "CN: Updating Apache2 configuration for Squirrelmail"
88 perl -n -e 'print if ! m|^Alias\s*/webmail|' "$CONF" > $CONF.tmp
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
94 <IfModule mod_rewrite.c>
98 RewriteCond %{HTTPS} !=on
99 RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]
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
112 cp_mv $CONF.tmp $CONF
114 # This will break if cp_backup_conffile ever changes destination path
115 if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then
117 cp_echo "CN: Updated Apache2 configuration for Squirrelmail."
120 echo "... no changes."
126 hconf=/etc/apache2/apache2.conf
127 sconf=/etc/apache2/sites-available/ssl
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.
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.
137 apache2listconf=`listconffiles "$hconf" | grep "$CONF"` || true
138 apache2squirrel=`ls -l /etc/apache2/conf.d/ | grep "$CONF"` || true
140 if [ -z "$apache2listconf" -a -z "$apache2squirrel" ]; then
141 ln -s "$CONF" /etc/apache2/conf.d/squirrelmail-cn.conf
146 # Initial CARNet config tweaks.
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\"."
155 # We use sed to replace old defaults with ours.
156 # Must escape \$ because of shell expansion.
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\//;
169 # Left frame size to 220px.
170 # $default_left_size = '220';
172 db_get squirrelmail-cn/leftwidth || true
173 if [ "$RET" = "true" ]; then
174 seddef="$seddef/^[ ]*\\\$default_left_size[ ]*=/s/'[0-9]*'/'220'/;
178 # Change CSS file for Squirrelmail.
179 # $theme_css = SM_PATH . 'themes/css/squirrelmail-cn.css';
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';/;
189 # Check for our dovecot package; if it is installed, assume it's used.
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/}
196 # Would there be any changes, perhaps?
198 if cp_check_and_sed '.' "$seddef" "$CONF"; then
203 # Check /etc/hostname and /etc/mailname, because
204 # $domain = trim(implode('', file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));
208 grep -q '\.' /etc/hostname || nodots=1
209 [ -e /etc/mailname ] || nomailname=1
212 # Generate hr_HR locale if needed.
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."
219 echo "hr_HR ISO-8859-2" > /etc/locale.gen
220 cp_echo "CN: /etc/locale.gen created."
222 dpkg-reconfigure -f noninteractive locales
227 # Check Apache2 web server for restart.
229 if [ $need_restart -eq 1 ]; then
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 $?
236 /etc/init.d/apache2 restart || exit $?
244 if [ "$nodots" -o "$nomailname" ]; then
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."