]> git.donarmstrong.com Git - roundcube.git/blob - debian/roundcube-core.postinst
Fix rights of files generated by UCF. Closes: #671474.
[roundcube.git] / debian / roundcube-core.postinst
1 #!/bin/sh
2 # postinst script for roundcube
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
8 . /usr/share/debconf/confmodule
9 . /usr/share/dbconfig-common/dpkg/postinst 
10 dbc_generate_include=php:/etc/roundcube/debian-db.php
11 dbc_generate_include_owner="root:www-data"
12 dbc_generate_include_perms="640"
13 dbc_dbfile_owner="www-data:www-data"
14 dbc_dbfile_perms="0660"
15 dbc_dbuser=roundcube
16 dbc_dbname=roundcube
17
18 dbc_go roundcube $@
19
20 lighttpd_install() {
21         if [ ! -f /etc/lighttpd/conf-available/50-roundcube.conf ] ; then
22                 if [ ! -x /usr/sbin/lighty-enable-mod ] ; then
23                         echo "Lighttpd not installed, skipping"
24                 else
25                         ln -s /etc/roundcube/lighttpd.conf /etc/lighttpd/conf-available/50-roundcube.conf
26                         lighty-enable-mod roundcube
27                 fi
28         fi
29 }
30
31 apache_install() {
32         webserver=$1
33         if [ -d /etc/$webserver/conf.d ] && [ ! -e /etc/$webserver/conf.d/roundcube ]; then
34                ln -s /etc/roundcube/apache.conf /etc/$webserver/conf.d/roundcube
35         fi
36 }
37
38
39 case "$1" in
40     configure)
41
42         # We try to fix an incomplete upgrade (see #610725 and #613586)
43         if [ -n "$2" ] && dpkg --compare-versions "$2" le 0.5.1+dfsg-5; then
44             db_get roundcube/dbconfig-upgrade || true
45             if [ x"$RET" = x"true" ]; then
46                 if [ x"$dbc_dbtype" = x"mysql" ]; then
47                     # Ok, we may need to do some upgrade steps.
48                     echo "Fixing MySQL installation..."
49                     if dpkg --compare-versions "$2" ge 0.5; then
50                         # Hack (ugly) to replace "mysql" by "mysql -f"
51                         real_mysql="$(which mysql)"
52                         workdir="$(mktemp -d)"
53                         oldpath="$PATH"
54                         cat <<EOF > "$workdir/mysql"
55 #!/bin/sh
56 "$real_mysql" "\$@" -f
57 EOF
58                         chmod +x "$workdir/mysql"
59                         PATH="$workdir:$PATH"
60                         dbc_mysql_exec_file \
61                             /usr/share/dbconfig-common/data/roundcube/upgrade/mysql/0.5-1 || true
62                         PATH="$oldpath"
63                         rm -rf "$workdir"
64                     fi
65                     cat <<EOF | while read command; do dbc_mysql_exec_command "$command" || true ; done
66 ALTER TABLE \`messages\` ADD INDEX \`index_index\` (\`user_id\`, \`cache_key\`, \`idx\`);
67 ALTER TABLE \`contacts\`ADD INDEX \`user_contacts_index\` (\`user_id\`,\`email\`);
68 ALTER TABLE \`identities\` ADD \`changed\` datetime NOT NULL DEFAULT '1000-01-01 00:00:00' AFTER \`user_id\`;
69 ALTER TABLE \`identities\` ADD INDEX \`user_identities_index\` (\`user_id\`, \`del\`);
70 EOF
71                 fi
72             fi
73         fi
74
75         CONFFILE=/etc/roundcube/main.inc.php
76         touch $CONFFILE.ucftmp
77         chmod 640 $CONFFILE.ucftmp
78         chown root:www-data $CONFFILE.ucftmp
79
80         db_get roundcube/hosts || true
81         hosts="$RET"
82         if [ "$hosts" != "" ]; then
83             hosts="array(\"$(echo $hosts | sed 's/ /\",\"/g')\")"
84         else
85             hosts="''"
86         fi
87
88         db_get roundcube/language || true
89         language="$RET"
90
91         # Get current 3DES key from /etc/roundcube/main.inc.php
92         [ -f /etc/roundcube/main.inc.php ] && {
93             deskey=$(sed -n "s+^\$rcmail_config\['des_key'\] = '\(.*\)';\$+\1+p" \
94                 /etc/roundcube/main.inc.php)
95         }
96         # If this is the default key, forget it !
97         [ "$deskey" = "rcmail-!24ByteDESkey*Str" ] && unset deskey
98         # Generate a new one
99         while [ -z "$deskey" ]; do
100             deskey=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | \
101                 tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
102         done
103
104         # Put hosts, language and key in main.inc.php
105         cat /usr/share/roundcube/main.inc.php.dist | while read line; do
106             case "$line" in
107                 "\$rcmail_config['default_host'] = "*)
108                     printf "\$rcmail_config['default_host'] = %s;\n" "${hosts}"
109                     ;;
110                 "\$rcmail_config['des_key'] = "*)
111                     printf "\$rcmail_config['des_key'] = '%s';\n" "${deskey}"
112                     ;;
113                 "\$rcmail_config['language'] = "*)
114                     printf "\$rcmail_config['language'] = '%s';\n" "${language}"
115                     ;;
116                 *)
117                     printf "%s\n" "$line"
118                     ;;
119             esac
120         done >> $CONFFILE.ucftmp
121
122         ucf --debconf-ok $CONFFILE.ucftmp $CONFFILE
123         chown root:www-data $CONFFILE
124         [ ! -f $CONFFILE.dpkg-dist ] || chown root:www-data $CONFFILE.dpkg-dist
125         rm -f $CONFFILE.ucftmp
126         
127         # Handle webserver reconfiguration/restart ; stolen from zabbix package
128         db_get roundcube/reconfigure-webserver || true
129         webservers="$RET"
130         restart=""
131
132         for webserver in $webservers; do
133             webserver=${webserver%,}
134             if [ "$webserver" = "lighttpd" ] ; then
135                 lighttpd_install
136             else
137                 apache_install $webserver
138             fi
139             test -x /usr/sbin/$webserver || continue
140             restart="$restart $webserver"
141         done
142
143         db_get roundcube/restart-webserver || true
144         res="$RET"
145         db_stop || true
146         if [ "$res" = "true" ]; then
147             for webserver in $restart; do
148                 webserver=${webserver%,}
149                 # Redirection of 3 is needed because Debconf uses it and it might
150                 # be inherited by webserver. See bug #446324.
151                 if [ -x /usr/sbin/invoke-rc.d ]; then
152                     invoke-rc.d $webserver reload 3>/dev/null || true
153                 else
154                     /etc/init.d/$webserver reload 3>/dev/null || true
155                 fi
156             done
157         fi
158
159         chown -R www-data:adm /var/log/roundcube
160         chmod -R 750 /var/log/roundcube
161         chown -R www-data:www-data /var/lib/roundcube/temp
162         chmod -R 750 /var/lib/roundcube/temp
163
164     ;;
165
166     abort-upgrade|abort-remove|abort-deconfigure)
167     ;;
168
169     *)
170         echo "postinst called with unknown argument \`$1'" >&2
171         exit 1
172     ;;
173 esac
174
175
176 #DEBHELPER#
177
178 exit 0
179
180