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.png/;
138 /^[ ]*\\\$org_logo[ ]*=/s/sm_logo\.png/sm_carnet_logo.png/;
139 /^[ ]*\\\$org_logo[ ]*=/s/sm_carnet_logo\.jpg/sm_carnet_logo.png/;
140 /^[ ]*\\\$domain[ ]*=/s/mydomain\.com/$domainname/;
141 /^[ ]*\\\$default_charset[ ]*=/s/iso-8859-1/iso-8859-2/;
142 /^[ ]*\\\$org_logo_width[ ]*=/s/308/0/;
143 /^[ ]*\\\$org_logo_height[ ]*=/s/111/0/;
144 /^[ ]*\\\$squirrelmail_default_language[ ]*=/s/en_US/hr_HR/;
145 /^[ ]*\\\$data_dir[ ]*=/s/\.\.\/data\//\/var\/lib\/squirrelmail\/data\//;
148 # Check for our uw-imap package; if it is installed, assume it's used.
150 if dpkg -l uw-imap-ssl-cn 2>/dev/null | grep -q '^ii'; then
151 seddef="$seddef/^[ ]*\\\$imap_server_type[ ]*=/ {s/cyrus/uw/;s/other/uw/;}
155 # Check for our dovecot package; if it is installed, assume it's used.
157 if dpkg -l dovecot-cn 2>/dev/null | grep -q '^ii'; then
158 seddef="$seddef/^[ ]*\\\$imap_server_type[ ]*=/ {s/cyrus/dovecot/;s/other/dovecot/;s/uw/dovecot/}
162 # Would there be any changes, perhaps?
164 if cp_check_and_sed '.' "$seddef" "$CONF"; then
168 if grep -q x62 "$CONF"; then
177 # Global $config_version;
179 if ! egrep -q '^[ ]*global[ ]+\$config_version' "$CONF"; then
181 #echo "CN: Adding \"global \$config_version;\" to config.php."
182 perl -p -e 'print "global \$config_version;\n" if (/^\s*\$config_version/);' \
183 "$CONF" > "$CONF.tmp"
184 cp_mv "$CONF.tmp" "$CONF"
187 # This was missing on some machines
189 if ! egrep -q '^[ ]*\$allow_thread_sort' $CONF; then
190 to_add='\$allow_thread_sort = false;\n'
191 cp_echo "CN: Adding \"\$allow_thread_sort\"."
192 perl -p -e 'if (! $a && /^\s*\$edit_name/) {
193 $_ .= "'"$to_add"'"; $a = 1; }
194 elsif (! $a && /^\?>/) {
195 $_ = "'"$to_add"'" . $_; $a = 1; }' \
197 cp_mv "$CONF.tmp" "$CONF"
200 # Shouldn't use /etc/hostname, especially if it contains only the host part
202 # $domain = implode('', file('/etc/hostname'));
204 # $domain = trim(implode('',file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));
206 if egrep -q "^[[:blank:]]*\\\$domain[[:blank:]]*=[[:blank:]]*implode\\('',[[:blank:]]*file\\('/etc/hostname'\\)\\);" $CONF; then
209 grep -q '\.' /etc/hostname || nodots=1
210 [ -e /etc/mailname ] || nomailname=1
211 if cp_check_and_sed "^[[:blank:]]*\\\$domain[[:blank:]]*=[[:blank:]]*implode\\('',[[:blank:]]*file\\('/etc/hostname'\\)\\);" \
212 "s|^[ \t]*\\\$domain[ \t]*=[ \t]*implode('',[ \t]*file('/etc/hostname'));|\$domain = trim(implode('',file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));|" \
214 cp_echo "CN: config.php updated to use either /etc/mailname or /etc/hostname"
219 # Generate hr_HR locale if needed.
221 if ! egrep -q '^hr_HR ISO-8859-2\b' /etc/locale.gen; then
222 if [ -f /etc/locale.gen ]; then
223 echo "hr_HR ISO-8859-2" >> /etc/locale.gen
224 cp_echo "CN: Added hr_HR locale to /etc/locale.gen."
226 echo "hr_HR ISO-8859-2" > /etc/locale.gen
227 cp_echo "CN: /etc/locale.gen created."
229 dpkg-reconfigure -f noninteractive locales
233 # Check Apache2 web server for restart/reload.
235 if [ -n "$reload" ]; then
237 # Restart Apache2 web server.
238 if [ -x "/etc/init.d/apache2" ]; then
239 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
240 invoke-rc.d apache2 "$reload" || exit $?
242 /etc/init.d/apache2 "$reload" || exit $?
248 # Warn user of really old config file
250 if [ "$really_old_config" ]; then
252 echo "CN: You have a really old config file."
253 cp_echo -m "CN: Old \"$CONF\" detected during installation."
254 cp_echo "CN The known bad options were fixed, but it is _strongly_ recommended that"
255 cp_echo "CN you either copy over the new template, and reconfigure this package"
257 cp_echo " cp $TMPL $CONF"
258 cp_echo " dpkg-reconfigure squirrelmail-cn"
260 cp_echo "CN or use squirrelmail-configure (conf.pl) to generate a fresh"
261 cp_echo " ${CONF} file."
268 if [ "$nodots" -o "$nomailname" ]; then
270 cp_echo "CN: Make sure that /etc/mailname contains a fully qualified domain name"
271 cp_echo "CN of this machine! Sending mail via squirrelmail might fail if the FQDN"
272 cp_echo "CN cannot be found in either /etc/mailname or /etc/hostname."
273 cp_echo "CN Read mailname(5) man page for details."
274 cp_echo -mailonly "CN If this machine receives mail for both user@`hostname -f` and "
275 cp_echo -mailonly "CN user@`hostname -d`, you can also put just the domain in there."