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
35 if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
36 . /usr/share/apache2/apache2-maintscript-helper
38 squirrelmail_enable() {
39 cp_echo "CN: Enabling $PKG configuration for Apache2."
43 cp_echo "CN: Could not load Apache 2.4 maintainer script helper."
45 squirrelmail_enable() {
51 # Clean up /etc, nove old jun^H^H^Hbackups where they belong
52 local glob="$1.old.*-*-*.*:*:*"
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##*/})
58 cp_backup_conffile "$i" "$2"
66 # Recursively walks /etc/apache2/apache2.conf for Include and
67 # IncludeOptional directives.
68 # Returns all configfiles so defined.
72 local base_dir="`dirname $1`"
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
78 if [ -e "$i" ]; then echo "`readlink -m -q $i`"; listconffiles "$i"; fi
85 # Update/generate localisation files from templates if locales-all
89 if [ -f /usr/lib/locales-all/supported.tar.lzma ] ; then
90 cp_echo "CN: locales-all installed, skipping locales generation."
97 DATE=`date +%Y-%m-%d.%H:%M:%S`
98 CONFDIR=/etc/squirrelmail
99 CONF=$CONFDIR/apache.conf
101 backup_name=squirrelmail_apache.conf
102 mv_old_backups $CONF $backup_name
104 # Check Apache2 web server configuration.
106 if [ -f "$CONF" ]; then
109 if cp_check_and_backup "$CONF" "$backup_name"; then
110 cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"."
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
118 cp-update -t $PKG $CONF.tmp <<-EOF
119 # Force SSL for /webmail -> you can still use /squirrelmail
120 Alias /webmail /usr/share/squirrelmail
122 <IfModule mod_rewrite.c>
126 RewriteCond %{HTTPS} !=on
127 RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]
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
140 cp_mv $CONF.tmp $CONF
142 # This will break if cp_backup_conffile ever changes destination path
143 if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then
145 cp_echo "CN: Updated Apache2 configuration for Squirrelmail."
147 echo "... no changes."
153 hconf=/etc/apache2/apache2.conf
154 sconf=/etc/apache2/sites-available/ssl
156 # Remove obsolete symbolic link.
158 if [ "`readlink -q -m /etc/apache2/conf.d/$PKG.conf`" = "$CONF" ]; then
159 rm -f /etc/apache2/conf.d/$PKG.conf
162 # Include Squirrelmail apache.conf in Apache2 web server configuration,
163 # but only if we are not present in Apache2 configuration at all.
165 apache2listconf=`listconffiles "$hconf" | grep "$CONF"` || true
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
174 # Initial CARNet config tweaks.
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\"."
183 # We use sed to replace old defaults with ours.
184 # Must escape \$ because of shell expansion.
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\//;
197 # Left frame size to 220px.
198 # $default_left_size = '220';
200 db_get squirrelmail-cn/leftwidth || true
201 if [ "$RET" = "true" ]; then
202 seddef="$seddef/^[ ]*\\\$default_left_size[ ]*=/s/'[0-9]*'/'220'/;
206 # Change CSS file for Squirrelmail.
207 # $theme_css = SM_PATH . 'themes/css/squirrelmail-cn.css';
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';/;
217 # Check for our dovecot package; if it is installed, assume it's used.
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/}
224 cp_check_and_sed '.' "$seddef" "$CONF" || true
227 # Check /etc/hostname and /etc/mailname, because
228 # $domain = trim(implode('', file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));
232 grep -q '\.' /etc/hostname || nodots=1
233 [ -e /etc/mailname ] || nomailname=1
236 # Check for hr_HR locale.
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."
245 echo "hr_HR ISO-8859-2" > /etc/locale.gen
246 cp_echo "CN: /etc/locale.gen created."
253 if [ "$nodots" -o "$nomailname" ]; then
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."
264 if squirrelmail_enable; then
265 apache2_invoke enconf $PKG
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!"