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 # Update/generate localisation files from templates if locales-all
73 if [ -f /usr/lib/locales-all/supported.tar.lzma ] ; then
74 cp_echo "CN: locales-all installed, skipping locales generation."
82 DATE=`date +%Y-%m-%d.%H:%M:%S`
83 CONFDIR=/etc/squirrelmail
84 CONF=$CONFDIR/apache.conf
86 backup_name=squirrelmail_apache.conf
87 mv_old_backups $CONF $backup_name
89 # Check Apache2 web server configuration.
91 if [ -f "$CONF" ]; then
94 if cp_check_and_backup "$CONF" "$backup_name"; then
95 cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"."
98 # Check if we already modified apache.conf
99 if ! egrep -q "^[ ]+RewriteRule \. https" "$CONF"; then
101 echo -n "CN: Updating Apache2 configuration for Squirrelmail"
102 perl -n -e 'print if ! m|^Alias\s*/webmail|' "$CONF" > $CONF.tmp
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
108 <IfModule mod_rewrite.c>
112 RewriteCond %{HTTPS} !=on
113 RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]
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
126 cp_mv $CONF.tmp $CONF
128 # This will break if cp_backup_conffile ever changes destination path
129 if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then
131 cp_echo "CN: Updated Apache2 configuration for Squirrelmail."
134 echo "... no changes."
140 hconf=/etc/apache2/apache2.conf
141 sconf=/etc/apache2/sites-available/ssl
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.
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.
151 apache2listconf=`listconffiles "$hconf" | grep "$CONF"` || true
152 apache2squirrel=`ls -l /etc/apache2/conf.d/ | grep "$CONF"` || true
154 if [ -z "$apache2listconf" -a -z "$apache2squirrel" ]; then
155 ln -s "$CONF" /etc/apache2/conf.d/squirrelmail-cn.conf
160 # Initial CARNet config tweaks.
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\"."
169 # We use sed to replace old defaults with ours.
170 # Must escape \$ because of shell expansion.
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\//;
183 # Left frame size to 220px.
184 # $default_left_size = '220';
186 db_get squirrelmail-cn/leftwidth || true
187 if [ "$RET" = "true" ]; then
188 seddef="$seddef/^[ ]*\\\$default_left_size[ ]*=/s/'[0-9]*'/'220'/;
192 # Change CSS file for Squirrelmail.
193 # $theme_css = SM_PATH . 'themes/css/squirrelmail-cn.css';
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';/;
203 # Check for our dovecot package; if it is installed, assume it's used.
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/}
210 # Would there be any changes, perhaps?
212 if cp_check_and_sed '.' "$seddef" "$CONF"; then
217 # Check /etc/hostname and /etc/mailname, because
218 # $domain = trim(implode('', file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));
222 grep -q '\.' /etc/hostname || nodots=1
223 [ -e /etc/mailname ] || nomailname=1
226 # Check for hr_HR locale.
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."
236 echo "hr_HR ISO-8859-2" > /etc/locale.gen
237 cp_echo "CN: /etc/locale.gen created."
243 # Check Apache2 web server for restart.
245 if [ $need_restart -eq 1 ]; then
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 $?
252 /etc/init.d/apache2 restart || exit $?
260 if [ "$nodots" -o "$nomailname" ]; then
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."