2 # postinst script for roundcube
4 # see: dh_installdeb(1)
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"
23 # From 0.1-beta2.2 to 0.1-rc1, a column was added to table
24 # `identities'. For MySQL and PostgreSQL, this is handled by
25 # dbconfig-common but for sqlite, there is no way to add a
26 # column to a table. Therefore, we dump here the table and add
30 db="${dbc_basepath}/${dbc_dbname}"
31 # OK, we need to check if the table contains html_signature
32 if ! sqlite "$db" '.schema identities' | grep -q html_signature; then
34 echo -n "Need to upgrade 'identities' table in $db... "
35 upgrade_tmp=$(mktemp -t roundcube.sqlite.XXXXXXXXXX)
39 DROP TABLE identities;
40 CREATE TABLE identities (
41 identity_id integer NOT NULL PRIMARY KEY,
42 user_id integer NOT NULL default '0',
43 del tinyint NOT NULL default '0',
44 standard tinyint NOT NULL default '0',
45 name varchar(128) NOT NULL default '',
46 organization varchar(128) default '',
47 email varchar(128) NOT NULL default '',
48 "reply-to" varchar(128) NOT NULL default '',
49 bcc varchar(128) NOT NULL default '',
50 signature text NOT NULL default '',
51 html_signature tinyint NOT NULL default '0'
54 CREATE INDEX ix_identities_user_id ON identities(user_id);
57 # We dump and keep only inserts
58 sqlite "$db" '.dump identities' | \
59 awk '/^INSERT INTO/ {start = 1} {if (start == 1) print}' | \
61 sed 's/^\(INSERT INTO identities \)/\1(identity_id, user_id, del, standard, name, organization, email, "reply-to", bcc, signature) /'
62 echo 'COMMIT;' ) > $upgrade_tmp
63 sqlite "$db" < $upgrade_tmp
73 CONFFILE=/etc/roundcube/main.inc.php
74 touch $CONFFILE.ucftmp
75 chmod 640 $CONFFILE.ucftmp
77 db_get roundcube/hosts || true
79 if [ "$hosts" != "" ]; then
80 hosts="array(\"$(echo $hosts | sed 's/ /\",\"/g')\")"
85 db_get roundcube/language || true
88 # Get current 3DES key from /etc/roundcube/main.inc.php
89 [ -f /etc/roundcube/main.inc.php ] && {
90 deskey=$(sed -n "s+^\$rcmail_config\['des_key'\] = '\(.*\)';\$+\1+p" \
91 /etc/roundcube/main.inc.php)
93 # If this is the default key, forget it !
94 [ "$deskey" = "rcmail-!24ByteDESkey*Str" ] && unset deskey
96 while [ -z "$deskey" ]; do
97 deskey=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | \
98 tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
101 # Put hosts, language and key in main.inc.php
102 zcat /usr/share/doc/roundcube/main.inc.php.dist.gz | \
103 sed -e "s+^\(\$rcmail_config\['default_host'\] = \)''\(;\)\$+\1${hosts}\2+" \
104 -e "s+^\(\$rcmail_config\['des_key'\] = '\).*\(';\)\$+\1$deskey\2+" \
105 -e "s+^\(\$rcmail_config\['locale_string'\] = '\).*\(';\)\$+\1${language}\2+" >> $CONFFILE.ucftmp
107 ucf --debconf-ok $CONFFILE.ucftmp $CONFFILE
108 chown root:www-data $CONFFILE
109 rm -f $CONFFILE.ucftmp
111 # Handle webserver reconfiguration/restart ; stolen from zabbix package
112 db_get roundcube/reconfigure-webserver || true
116 for webserver in $webservers; do
117 webserver=${webserver%,}
118 test -x /usr/sbin/$webserver || continue
120 if [ ! -f /etc/$webserver/conf.d/roundcube ] && [ ! -h /etc/$webserver/conf.d/roundcube ]; then
121 ln -s /etc/roundcube/apache.conf /etc/$webserver/conf.d/roundcube
123 restart="$restart $webserver"
126 db_get roundcube/restart-webserver || true
129 if [ "$res" = "true" ]; then
130 for webserver in $restart; do
131 webserver=${webserver%,}
132 if [ -x /usr/sbin/invoke-rc.d ]; then
133 invoke-rc.d $webserver restart
135 /etc/init.d/$webserver restart
140 chown -R www-data:adm /var/log/roundcube
141 chmod -R 750 /var/log/roundcube
142 chown -R www-data:www-data /var/lib/roundcube/temp
143 chmod -R 750 /var/lib/roundcube/temp
144 chown www-data:adm /var/lib/roundcube/skins
148 abort-upgrade|abort-remove|abort-deconfigure)
152 echo "postinst called with unknown argument \`$1'" >&2