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
28 [ "$dbc_upgrade" = "true" ] && {
31 db="${dbc_basepath}/${dbc_dbname}"
32 # OK, we need to check if the table contains html_signature
33 if ! sqlite "$db" '.schema identities' | grep -q html_signature; then
35 echo -n "Need to upgrade 'identities' table in $db... "
36 upgrade_tmp=$(mktemp -t roundcube.sqlite.XXXXXXXXXX)
40 DROP TABLE identities;
41 CREATE TABLE identities (
42 identity_id integer NOT NULL PRIMARY KEY,
43 user_id integer NOT NULL default '0',
44 del tinyint NOT NULL default '0',
45 standard tinyint NOT NULL default '0',
46 name varchar(128) NOT NULL default '',
47 organization varchar(128) default '',
48 email varchar(128) NOT NULL default '',
49 "reply-to" varchar(128) NOT NULL default '',
50 bcc varchar(128) NOT NULL default '',
51 signature text NOT NULL default '',
52 html_signature tinyint NOT NULL default '0'
55 CREATE INDEX ix_identities_user_id ON identities(user_id);
58 # We dump and keep only inserts
59 sqlite "$db" '.dump identities' | \
60 awk '/^INSERT INTO/ {start = 1} {if (start == 1) print}' | \
62 sed 's/^\(INSERT INTO identities \)/\1(identity_id, user_id, del, standard, name, organization, email, "reply-to", bcc, signature) /'
63 echo 'COMMIT;' ) > $upgrade_tmp
64 sqlite "$db" < $upgrade_tmp
75 CONFFILE=/etc/roundcube/main.inc.php
76 touch $CONFFILE.ucftmp
77 chmod 640 $CONFFILE.ucftmp
79 db_get roundcube/hosts || true
81 if [ "$hosts" != "" ]; then
82 hosts="array(\"$(echo $hosts | sed 's/ /\",\"/g')\")"
87 db_get roundcube/language || true
90 # Get current 3DES key from /etc/roundcube/main.inc.php
91 [ -f /etc/roundcube/main.inc.php ] && {
92 deskey=$(sed -n "s+^\$rcmail_config\['des_key'\] = '\(.*\)';\$+\1+p" \
93 /etc/roundcube/main.inc.php)
95 # If this is the default key, forget it !
96 [ "$deskey" = "rcmail-!24ByteDESkey*Str" ] && unset deskey
98 while [ -z "$deskey" ]; do
99 deskey=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | \
100 tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
103 # Put hosts, language and key in main.inc.php
104 cat /usr/share/roundcube/main.inc.php.dist | \
105 sed -e "s+^\(\$rcmail_config\['default_host'\] = \)''\(;\)\$+\1${hosts}\2+" \
106 -e "s+^\(\$rcmail_config\['des_key'\] = '\).*\(';\)\$+\1$deskey\2+" \
107 -e "s+^\(\$rcmail_config\['locale_string'\] = '\).*\(';\)\$+\1${language}\2+" >> $CONFFILE.ucftmp
109 ucf --debconf-ok $CONFFILE.ucftmp $CONFFILE
110 chown root:www-data $CONFFILE
111 rm -f $CONFFILE.ucftmp
113 # Handle webserver reconfiguration/restart ; stolen from zabbix package
114 db_get roundcube/reconfigure-webserver || true
118 for webserver in $webservers; do
119 webserver=${webserver%,}
120 test -x /usr/sbin/$webserver || continue
122 if [ ! -f /etc/$webserver/conf.d/roundcube ] && [ ! -h /etc/$webserver/conf.d/roundcube ]; then
123 ln -s /etc/roundcube/apache.conf /etc/$webserver/conf.d/roundcube
125 restart="$restart $webserver"
128 db_get roundcube/restart-webserver || true
131 if [ "$res" = "true" ]; then
132 for webserver in $restart; do
133 webserver=${webserver%,}
134 if [ -x /usr/sbin/invoke-rc.d ]; then
135 invoke-rc.d $webserver restart
137 /etc/init.d/$webserver restart
142 chown -R www-data:adm /var/log/roundcube
143 chmod -R 750 /var/log/roundcube
144 chown -R www-data:www-data /var/lib/roundcube/temp
145 chmod -R 750 /var/lib/roundcube/temp
146 chown www-data:adm /var/lib/roundcube/skins
150 abort-upgrade|abort-remove|abort-deconfigure)
154 echo "postinst called with unknown argument \`$1'" >&2