Prva verzija za Debian buster.
[roundcube-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -x
6
7 # Source debconf library.
8 . /usr/share/debconf/confmodule
9
10 case "$1" in
11     configure)
12         # continue below
13         ;;
14
15     abort-upgrade|abort-remove|abort-deconfigure)
16         exit 0
17         ;;
18
19     *)
20         echo "postinst called with unknown argument \`$1'" >&2
21         exit 0
22         ;;
23 esac
24
25
26 PKG=roundcube-cn
27 domainname=`dnsdomainname`
28 FQDN=`hostname --fqdn`
29
30 # Include CARNET functions
31 . /usr/share/carnet-tools/functions.sh
32 unset CP_ECHO_RETURN
33
34
35 if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
36     . /usr/share/apache2/apache2-maintscript-helper
37
38     roundcube_enable() {
39         cp_echo "CN: Enabling $PKG configuration for Apache2."
40         return 0
41     }
42 else
43     cp_echo "CN: Could not load Apache 2.4 maintainer script helper."
44
45     roundcube_enable() {
46         return 1
47     }
48 fi
49
50 mv_old_backups () {
51     # Clean up /etc, nove old jun^H^H^Hbackups where they belong
52     local glob="$1.old.*-*-*.*:*:*"
53
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##*/})
57         do
58             cp_backup_conffile "$i" "$2"
59             rm -f "$i"
60         done
61     fi
62 }
63
64 # listconffiles ()
65 #
66 #   Recursively walks /etc/apache2/apache2.conf for Include and
67 #   IncludeOptional directives.
68 #   Returns all configfiles so defined.
69 #
70 listconffiles () {
71     local i incs
72     local base_dir="`dirname $1`"
73
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
77         for i in $incs; do
78             if [ -e "$i" ]; then echo "`readlink -m -q $i`"; listconffiles "$i"; fi
79         done
80     fi
81 }
82
83 # genlocales ()
84 #
85 #   Update/generate localisation files from templates if locales-all
86 #   is not installed.
87 #
88 genlocales () {
89     if [ -f /usr/lib/locales-all/supported.tar.lzma ] ; then
90         cp_echo "CN: locales-all installed, skipping locales generation."
91     else
92         locale-gen
93     fi
94 }
95
96
97 DATE=`date +%Y-%m-%d.%H:%M:%S`
98 CONFDIR=/etc/roundcube
99 CONF=$CONFDIR/apache.conf
100
101 backup_name=roundcube_apache.conf
102 mv_old_backups $CONF $backup_name
103
104 # Check Apache2 web server configuration.
105 #
106 if [ -f "$CONF" ]; then
107
108     # Backup first.
109     if cp_check_and_backup "$CONF" "$backup_name"; then
110         cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"."
111     fi
112
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
117
118         cp-update -t $PKG $CONF.tmp <<-EOF
119 # Force SSL for /webmail -> you can still use /roundcube
120 Alias /webmail /var/lib/roundcube
121
122 <IfModule mod_rewrite.c>
123   <IfModule mod_ssl.c>
124     <Location /webmail>
125       RewriteEngine on
126       RewriteCond %{HTTPS} !=on
127       RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}  [L]
128     </Location>
129   </IfModule>
130 </IfModule>
131
132 #
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
137 # instead.
138 #
139 EOF
140         cp_mv $CONF.tmp $CONF
141
142         # This will break if cp_backup_conffile ever changes destination path
143         if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then
144             echo "."
145             cp_echo "CN: Updated Apache2 configuration for Roundcube."
146         else
147             echo "... no changes."
148         fi
149     fi
150 fi
151
152
153 hconf=/etc/apache2/apache2.conf
154 sconf=/etc/apache2/sites-available/ssl
155
156 # Initial CARNET config tweaks.
157 #
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\"."
162 fi
163
164 # We use sed to replace old defaults with ours.
165 # Must escape \$ because of shell expansion.
166 #
167 seddef="/default_host/s/''/'localhost'/g;
168         /smtp_server/s/''/'localhost'/g;
169         "
170
171 cp_check_and_sed '.' "$seddef" "$CONF" || true
172
173 # Mailname info...
174 #
175 if [ "$nodots" -o "$nomailname" ]; then
176     cp_echo
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."
183     cp_echo
184 fi
185
186 if roundcube_enable; then
187     apache2_invoke enconf roundcube
188 fi
189
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!"
193 fi
194
195 # Mail root
196 #
197 cp_mail "$PKG"
198
199
200 #DEBHELPER#