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