]> git.donarmstrong.com Git - roundcube.git/blob - debian/roundcube-core.postinst
Merge commit 'upstream/0.2_stable' into unstable-import
[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="www-data:www-data"
12 dbc_generate_include_perms="660"
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         # From 0.1-beta2.2 to 0.1-rc1, a column was added to table
43         # `identities'. For MySQL and PostgreSQL, this is handled by
44         # dbconfig-common but for sqlite, there is no way to add a
45         # column to a table. Therefore, we dump here the table and add
46         # the column.
47         [ "$dbc_upgrade" = "true" ] && {
48             case "$dbc_dbtype" in
49                 sqlite)
50                     db="${dbc_basepath}/${dbc_dbname}"
51                 # OK, we need to check if the table contains html_signature
52                     if ! sqlite "$db" '.schema identities' | grep -q html_signature; then
53                         # We need to add it
54                         echo -n "Need to upgrade 'identities' table in $db... "
55                         upgrade_tmp=$(mktemp -t roundcube.sqlite.XXXXXXXXXX)
56                         (
57                             cat <<EOF
58 BEGIN TRANSACTION;
59 DROP TABLE identities;
60 CREATE TABLE identities (
61   identity_id integer NOT NULL PRIMARY KEY,
62   user_id integer NOT NULL default '0',
63   del tinyint NOT NULL default '0',
64   standard tinyint NOT NULL default '0',
65   name varchar(128) NOT NULL default '',
66   organization varchar(128) default '',
67   email varchar(128) NOT NULL default '',
68   "reply-to" varchar(128) NOT NULL default '',
69   bcc varchar(128) NOT NULL default '',
70   signature text NOT NULL default '',
71   html_signature tinyint NOT NULL default '0'
72 );
73
74 CREATE INDEX ix_identities_user_id ON identities(user_id);
75
76 EOF
77                             # We dump and keep only inserts
78                             sqlite "$db" '.dump identities' | \
79                                 awk '/^INSERT INTO/ {start = 1} {if (start == 1) print}' | \
80                                 head -n -2 | \
81                                 sed 's/^\(INSERT INTO identities \)/\1(identity_id, user_id, del, standard, name, organization, email, "reply-to", bcc, signature) /'
82                             echo 'COMMIT;' ) > $upgrade_tmp
83                         sqlite "$db" < $upgrade_tmp
84                         rm $upgrade_tmp
85                         echo "OK"
86                     fi
87                     ;;
88                 *)
89                     # Do nothing
90                     ;;
91             esac
92         }
93
94         CONFFILE=/etc/roundcube/main.inc.php
95         touch $CONFFILE.ucftmp
96         chmod 640 $CONFFILE.ucftmp
97
98         db_get roundcube/hosts || true
99         hosts="$RET"
100         if [ "$hosts" != "" ]; then
101             hosts="array(\"$(echo $hosts | sed 's/ /\",\"/g')\")"
102         else
103             hosts="''"
104         fi
105
106         db_get roundcube/language || true
107         language="$RET"
108
109         # Get current 3DES key from /etc/roundcube/main.inc.php
110         [ -f /etc/roundcube/main.inc.php ] && {
111             deskey=$(sed -n "s+^\$rcmail_config\['des_key'\] = '\(.*\)';\$+\1+p" \
112                 /etc/roundcube/main.inc.php)
113         }
114         # If this is the default key, forget it !
115         [ "$deskey" = "rcmail-!24ByteDESkey*Str" ] && unset deskey
116         # Generate a new one
117         while [ -z "$deskey" ]; do
118             deskey=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | \
119                 tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
120         done
121
122         # Put hosts, language and key in main.inc.php
123         cat /usr/share/roundcube/main.inc.php.dist | \
124             sed -e "s+^\(\$rcmail_config\['default_host'\] = \)''\(;\)\$+\1${hosts}\2+" \
125                 -e "s+^\(\$rcmail_config\['des_key'\] = '\).*\(';\)\$+\1$deskey\2+" \
126                 -e "s+^\(\$rcmail_config\['locale_string'\] = '\).*\(';\)\$+\1${language}\2+" >> $CONFFILE.ucftmp
127
128         ucf --debconf-ok $CONFFILE.ucftmp $CONFFILE
129         chown root:www-data $CONFFILE
130         rm -f $CONFFILE.ucftmp
131         
132         # Handle webserver reconfiguration/restart ; stolen from zabbix package
133         db_get roundcube/reconfigure-webserver || true
134         webservers="$RET"
135         restart=""
136
137         for webserver in $webservers; do
138             webserver=${webserver%,}
139             if [ "$webserver" = "lighttpd" ] ; then
140                 lighttpd_install
141             else
142                 apache_install $webserver
143             fi
144             test -x /usr/sbin/$webserver || continue
145             restart="$restart $webserver"
146         done
147
148         db_get roundcube/restart-webserver || true
149         res="$RET"
150         db_stop || true
151         if [ "$res" = "true" ]; then
152             for webserver in $restart; do
153                 webserver=${webserver%,}
154                 # Redirection of 3 is needed because Debconf uses it and it might
155                 # be inherited by webserver. See bug #446324.
156                 if [ -x /usr/sbin/invoke-rc.d ]; then
157                     invoke-rc.d $webserver reload 3>/dev/null || true
158                 else
159                     /etc/init.d/$webserver reload 3>/dev/null || true
160                 fi
161             done
162         fi
163
164         chown -R www-data:adm /var/log/roundcube
165         chmod -R 750 /var/log/roundcube
166         chown -R www-data:www-data /var/lib/roundcube/temp
167         chmod -R 750 /var/lib/roundcube/temp
168         chown www-data:adm /var/lib/roundcube/skins
169
170     ;;
171
172     abort-upgrade|abort-remove|abort-deconfigure)
173     ;;
174
175     *)
176         echo "postinst called with unknown argument \`$1'" >&2
177         exit 1
178     ;;
179 esac
180
181
182 #DEBHELPER#
183
184 exit 0
185
186