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
39 cp_echo "CN: Enabling $PKG configuration for Apache2."
43 cp_echo "CN: Could not load Apache 2.4 maintainer script helper."
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/roundcube
99 CONF=$CONFDIR/apache.conf
101 backup_name=roundcube_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 Roundcube"
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 /roundcube
120 Alias /webmail /var/lib/roundcube
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 Roundcube."
147 echo "... no changes."
153 hconf=/etc/apache2/apache2.conf
154 sconf=/etc/apache2/sites-available/ssl
156 # Initial CARNET config tweaks.
158 CONF="$CONFDIR/config.inc.php"
159 mv_old_backups "$CONF" "`basename $CONF`"
160 if cp_check_and_backup "$CONF"; then
161 cp_echo "CN: Old $CONF saved as \"/var/backups/${CONF##*/}.bak\"."
164 # We use sed to replace old defaults with ours.
165 # Must escape \$ because of shell expansion.
167 seddef="/default_host/s/''/'localhost'/g;
168 /smtp_server/s/''/'localhost'/g;
171 cp_check_and_sed '.' "$seddef" "$CONF" || true
175 if [ "$nodots" -o "$nomailname" ]; then
177 cp_echo "CN: Make sure that /etc/mailname contains a fully qualified domain name"
178 cp_echo "CN of this machine! Sending mail via Roundcube might fail if the FQDN"
179 cp_echo "CN cannot be found in either /etc/mailname or /etc/hostname."
180 cp_echo "CN Read mailname(5) man page for details."
181 cp_echo -mailonly "CN If this machine receives mail for both user@`hostname -f` and "
182 cp_echo -mailonly "CN user@`hostname -d`, you can also put just the domain in there."
186 if roundcube_enable; then
187 apache2_invoke enconf roundcube
190 if ! apache2ctl configtest >/dev/null 2>&1; then
191 cp_echo "CN: Your Apache2 configuration seems to be broken."
192 cp_echo "CN: Please, check the service after the installation finishes!"