5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -x
12 abort-upgrade|abort-remove|abort-deconfigure)
17 echo "postinst called with unknown argument \`$1'" >&2
24 domainname=`dnsdomainname`
25 FQDN=`hostname --fqdn`
27 # Include CARNet functions
28 . /usr/share/carnet-tools/functions.sh
33 # Clean up /etc, nove old jun^H^H^Hbackups where they belong
34 glob="$1.old.*-*-*.*:*:*"
36 # ${glob%/*} (dirname $glob) does not work for files in root
37 if [ -n "$(find ${glob%/*} -name ${glob##*/})" ]; then
38 for i in $(find ${glob%/*} -name ${glob##*/})
40 cp_backup_conffile "$i" "$2"
48 DATE=`date +%Y-%m-%d.%H:%M:%S`
49 CONFDIR=/etc/squirrelmail
50 CONF=$CONFDIR/apache.conf
52 backup_name=squirrelmail_apache.conf
53 mv_old_backups $CONF $backup_name
55 # Check Apache2 web server configuration.
57 if [ -f "$CONF" ]; then
60 if cp_check_and_backup "$CONF" "$backup_name"; then
61 cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"."
64 # Check if we already modified apache.conf
65 if ! egrep -q "^[ ]+RewriteRule \. https" "$CONF"; then
67 echo -n "CN: Updating Apache2 configuration for Squirrelmail"
68 perl -n -e 'print if ! m|^Alias\s*/webmail|' "$CONF" > $CONF.tmp
70 cp-update -t squirrelmail-cn $CONF.tmp <<-EOF
71 # Force SSL for /webmail -> you can still use /squirrelmail
72 Alias /webmail /usr/share/squirrelmail
74 <IfModule mod_rewrite.c>
78 RewriteCond %{HTTPS} !=on
79 RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]
85 # WARNING: This file is automatically included in each VirtualHost
86 # entry you might have. Do not enable the VirtualHost example provided
87 # in this file, it WILL break your Apache configuration. Copy the
88 # VirtualHost section to the standard webserver configuration file
94 # This will break if cp_backup_conffile ever changes destination path
95 if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then
97 cp_echo "CN: Updated Apache2 configuration for Squirrelmail."
100 echo "... no changes."
106 hconf=/etc/apache2/apache2.conf
107 sconf=/etc/apache2/sites-available/ssl
109 # Include Squirrelmail apache.conf in Apache2 web server configuration
110 # (directory /etc/apache2/conf.d/), but only if we are not present in
111 # Apache2 configuration at all.
113 # We're using listconffiles from apache-common Debian package. Yes,
114 # it works with Apache2 configurations too.
116 apache2listconf=`/usr/share/apache/listconffiles -V $hconf | tr '
\a' ' ' | grep "$CONF"` || true
117 apache2squirrel=`ls -l /etc/apache2/conf.d/ | grep "$CONF"` || true
119 if [ -z "$apache2listconf" -a -z "$apache2squirrel" ]; then
120 ln -s "$CONF" /etc/apache2/conf.d/squirrelmail-cn.conf
125 # Initial CARNet config tweaks.
127 CONF="$CONFDIR/config.php"
128 TMPL="$CONFDIR/config_default.php"
129 mv_old_backups "$CONF" "`basename $CONF`"
130 if cp_check_and_backup "$CONF"; then
131 cp_echo "CN: Old $CONF saved as \"/var/backups/${CONF##*/}.bak\"."
134 # We use sed to replace old defaults with ours.
135 # Must escape \$ because of shell expansion.
137 seddef="/^[ ]*\\\$org_logo[ ]*=/s/sm_logo\.jpg/sm_carnet_logo.jpg/;
138 /^[ ]*\\\$org_logo[ ]*=/s/sm_logo\.png/sm_carnet_logo.jpg/;
139 /^[ ]*\\\$domain[ ]*=/s/mydomain\.com/$domainname/;
140 /^[ ]*\\\$default_charset[ ]*=/s/iso-8859-1/iso-8859-2/;
141 /^[ ]*\\\$org_logo_width[ ]*=/s/308/0/;
142 /^[ ]*\\\$org_logo_height[ ]*=/s/111/0/;
143 /^[ ]*\\\$squirrelmail_default_language[ ]*=/s/en_US/hr_HR/;
144 /^[ ]*\\\$data_dir[ ]*=/s/\.\.\/data\//\/var\/lib\/squirrelmail\/data\//;
147 # Check for our uw-imap package; if it is installed, assume it's used.
149 if dpkg -l uw-imap-ssl-cn 2>/dev/null | grep -q '^ii'; then
150 seddef="$seddef/^[ ]*\\\$imap_server_type[ ]*=/ {s/cyrus/uw/;s/other/uw/;}
154 # Check for our dovecot package; if it is installed, assume it's used.
156 if dpkg -l dovecot-cn 2>/dev/null | grep -q '^ii'; then
157 seddef="$seddef/^[ ]*\\\$imap_server_type[ ]*=/ {s/cyrus/dovecot/;s/other/dovecot/;s/uw/dovecot/}
161 # Would there be any changes, perhaps?
163 if cp_check_and_sed '.' "$seddef" "$CONF"; then
167 if grep -q x62 "$CONF"; then
176 # Global $config_version;
178 if ! egrep -q '^[ ]*global[ ]+\$config_version' "$CONF"; then
180 #echo "CN: Adding \"global \$config_version;\" to config.php."
181 perl -p -e 'print "global \$config_version;\n" if (/^\s*\$config_version/);' \
182 "$CONF" > "$CONF.tmp"
183 cp_mv "$CONF.tmp" "$CONF"
186 # This was missing on some machines
188 if ! egrep -q '^[ ]*\$allow_thread_sort' $CONF; then
189 to_add='\$allow_thread_sort = false;\n'
190 cp_echo "CN: Adding \"\$allow_thread_sort\"."
191 perl -p -e 'if (! $a && /^\s*\$edit_name/) {
192 $_ .= "'"$to_add"'"; $a = 1; }
193 elsif (! $a && /^\?>/) {
194 $_ = "'"$to_add"'" . $_; $a = 1; }' \
196 cp_mv "$CONF.tmp" "$CONF"
199 # Shouldn't use /etc/hostname, especially if it contains only the host part
201 # $domain = implode('', file('/etc/hostname'));
203 # $domain = trim(implode('',file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));
205 if egrep -q "^[[:blank:]]*\\\$domain[[:blank:]]*=[[:blank:]]*implode\\('',[[:blank:]]*file\\('/etc/hostname'\\)\\);" $CONF; then
208 grep -q '\.' /etc/hostname || nodots=1
209 [ -e /etc/mailname ] || nomailname=1
210 if cp_check_and_sed "^[[:blank:]]*\\\$domain[[:blank:]]*=[[:blank:]]*implode\\('',[[:blank:]]*file\\('/etc/hostname'\\)\\);" \
211 "s|^[ \t]*\\\$domain[ \t]*=[ \t]*implode('',[ \t]*file('/etc/hostname'));|\$domain = trim(implode('',file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));|" \
213 cp_echo "CN: config.php updated to use either /etc/mailname or /etc/hostname"
218 # Generate hr_HR locale if needed.
220 if ! egrep -q '^hr_HR ISO-8859-2\b' /etc/locale.gen; then
221 if [ -f /etc/locale.gen ]; then
222 echo "hr_HR ISO-8859-2" >> /etc/locale.gen
223 cp_echo "CN: Added hr_HR locale to /etc/locale.gen."
225 echo "hr_HR ISO-8859-2" > /etc/locale.gen
226 cp_echo "CN: /etc/locale.gen created."
228 dpkg-reconfigure -f noninteractive locales
232 # Check Apache2 web server for restart/reload.
234 if [ -n "$reload" ]; then
236 # Restart Apache2 web server.
237 if [ -x "/etc/init.d/apache2" ]; then
238 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
239 invoke-rc.d apache2 "$reload" || exit $?
241 /etc/init.d/apache2 "$reload" || exit $?
247 # Warn user of really old config file
249 if [ "$really_old_config" ]; then
251 echo "CN: You have a really old config file."
252 cp_echo -m "CN: Old \"$CONF\" detected during installation."
253 cp_echo "CN The known bad options were fixed, but it is _strongly_ recommended that"
254 cp_echo "CN you either copy over the new template, and reconfigure this package"
256 cp_echo " cp $TMPL $CONF"
257 cp_echo " dpkg-reconfigure squirrelmail-cn"
259 cp_echo "CN or use squirrelmail-configure (conf.pl) to generate a fresh"
260 cp_echo " ${CONF} file."
267 if [ "$nodots" -o "$nomailname" ]; then
269 cp_echo "CN: Make sure that /etc/mailname contains a fully qualified domain name"
270 cp_echo "CN of this machine! Sending mail via squirrelmail might fail if the FQDN"
271 cp_echo "CN cannot be found in either /etc/mailname or /etc/hostname."
272 cp_echo "CN Read mailname(5) man page for details."
273 cp_echo -mailonly "CN If this machine receives mail for both user@`hostname -f` and "
274 cp_echo -mailonly "CN user@`hostname -d`, you can also put just the domain in there."