]> git.donarmstrong.com Git - roundcube.git/blob - debian/postinst
3b09dcc46e68a99a2413317fc86e2d2abe35cc7b
[roundcube.git] / debian / 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 case "$1" in
21     configure)
22
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
27         # the column.
28         case "$dbc_dbtype" in
29             sqlite)
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
33                     # We need to add it
34                     echo -n "Need to upgrade 'identities' table in $db... "
35                     upgrade_tmp=$(mktemp -t roundcube.sqlite.XXXXXXXXXX)
36                     (
37                         cat <<EOF
38 BEGIN TRANSACTION;
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'
52 );
53
54 CREATE INDEX ix_identities_user_id ON identities(user_id);
55
56 EOF
57                         # We dump and keep only inserts
58                         sqlite "$db" '.dump identities' | \
59                             awk '/^INSERT INTO/ {start = 1} {if (start == 1) print}' | \
60                             head -n -2 | \
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
64                     rm $upgrade_tmp
65                     echo "OK"
66                 fi
67                 ;;
68             *)
69                 # Do nothing
70                 ;;
71         esac
72
73         CONFFILE=/etc/roundcube/main.inc.php
74         touch $CONFFILE.ucftmp
75         chmod 640 $CONFFILE.ucftmp
76
77         db_get roundcube/hosts || true
78         hosts="$RET"
79         if [ "$hosts" != "" ]; then
80             hosts="array(\"$(echo $hosts | sed 's/ /\",\"/g')\")"
81         else
82             hosts="''"
83         fi
84
85         db_get roundcube/language || true
86         language="$RET"
87
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)
92         }
93         # If this is the default key, forget it !
94         [ "$deskey" = "rcmail-!24ByteDESkey*Str" ] && unset deskey
95         # Generate a new one
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')
99         done
100
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
106
107         ucf --debconf-ok $CONFFILE.ucftmp $CONFFILE
108         chown root:www-data $CONFFILE
109         rm -f $CONFFILE.ucftmp
110         
111         # Handle webserver reconfiguration/restart ; stolen from zabbix package
112         db_get roundcube/reconfigure-webserver || true
113         webservers="$RET"
114         restart=""
115
116         for webserver in $webservers; do
117             webserver=${webserver%,}
118             test -x /usr/sbin/$webserver || continue
119         
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
122             fi
123             restart="$restart $webserver"
124         done
125
126         db_get roundcube/restart-webserver || true
127         res="$RET"
128         db_stop || 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
134                 else
135                     /etc/init.d/$webserver restart
136                 fi
137             done
138         fi
139
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
145
146     ;;
147
148     abort-upgrade|abort-remove|abort-deconfigure)
149     ;;
150
151     *)
152         echo "postinst called with unknown argument \`$1'" >&2
153         exit 1
154     ;;
155 esac
156
157
158 #DEBHELPER#
159
160 exit 0
161
162