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="root:www-data"
12 dbc_generate_include_perms="640"
13 dbc_dbfile_owner="www-data:www-data"
14 dbc_dbfile_perms="0660"
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"
25 ln -s /etc/roundcube/lighttpd.conf /etc/lighttpd/conf-available/50-roundcube.conf
26 lighty-enable-mod roundcube
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
39 # In 0.5.1-1, symlinks have been mangled. Before this version,
40 # /var/lib/roundcube and /usr/share/roundcube were using symlinks
42 # /usr/share/roundcube/config -> /var/lib/roundcube/config
43 # /usr/share/roundcube/logs -> /var/lib/roundcube/logs
44 # /usr/share/roundcube/plugins -> /var/lib/roundcube/plugins
45 # /usr/share/roundcube/skins -> /var/lib/roundcube/skins
46 # /usr/share/roundcube/temp -> /var/lib/roundcube/temp
47 # /var/lib/roundcube/logs -> ../../log/roundcube
48 # /var/lib/roundcube/.htaccess -> /usr/share/roundcube/.htaccess
49 # /var/lib/roundcube/bin -> /usr/share/roundcube/bin
50 # /var/lib/roundcube/index.php -> /usr/share/roundcube/bin
51 # /var/lib/roundcube/program -> /usr/share/roundcube/bin
52 # /var/lib/roundcube/robots.txt -> /usr/share/roundcube/bin
54 # As of 0.7.2-6, the user is expected to use /var/lib/roundcube
55 # since /usr/share/roundcube does not contain the appropriate
57 # /var/lib/roundcube/logs -> ../../log/roundcube
58 # /var/lib/roundcube/.htaccess -> /usr/share/roundcube/.htaccess
59 # /var/lib/roundcube/index.php -> /usr/share/roundcube/bin
60 # /var/lib/roundcube/program -> /usr/share/roundcube/bin
61 # /var/lib/roundcube/robots.txt -> /usr/share/roundcube/bin
62 # /var/lib/roundcube/plugins/* -> /usr/share/roundcube/plugins/*
63 # /var/lib/roundcube/skins/* -> /usr/share/roundcube/skins/*
65 # Because dpkg will not overwrite a symlink but follow them, an
66 # upgrade gives a confuse situation. We have the following
67 # symlinks in /usr/share/roundcube:
68 # /usr/share/roundcube/plugins -> /var/lib/roundcube/plugins
69 # /usr/share/roundcube/skins -> /var/lib/roundcube/skins
70 # And the following are not symlinks as they should be:
71 # /var/lib/roundcube/plugins/* -> /usr/share/roundcube/plugins/*
72 # /var/lib/roundcube/skins/* -> /usr/share/roundcube/skins/*
74 # We detect and fix that.
75 for dir in plugins skins; do
76 [ -L /usr/share/roundcube/${dir} ] || continue
77 echo "Fixing symbolic link /usr/share/roundcube/${dir}"
78 [ ! -L /var/lib/roundcube/${dir} ] || {
79 echo "/var/lib/roundcube/${dir} is not expected to be a symbolic link. Abort."
82 # Remove the symbolic link and make a real directory.
83 rm /usr/share/roundcube/${dir}
84 mkdir /usr/share/roundcube/${dir}
86 # We move each subdirectory regardless we own them or not. The
87 # ideal solution would be to leave files installed by the user
88 # in /var/lib/roundcube/${dir} but since other packages (like
89 # roundcube-plugins and roundcube-plugins-extra) may have
90 # installed files, it is something difficult to track. We do
91 # not want each package to fix this mess. What's important is
92 # that user installation will keep working as expected,
94 for d in /var/lib/roundcube/${dir}/*; do
95 mv ${d} /usr/share/roundcube/${dir}
96 ln -s /usr/share/roundcube/${dir}/${d##*/} /var/lib/roundcube/${dir}/${d##*/}
104 # We try to fix an incomplete upgrade (see #610725 and #613586)
105 if [ -n "$2" ] && dpkg --compare-versions "$2" le 0.5.1+dfsg-5; then
106 db_get roundcube/dbconfig-upgrade || true
107 if [ x"$RET" = x"true" ]; then
108 if [ x"$dbc_dbtype" = x"mysql" ]; then
109 # Ok, we may need to do some upgrade steps.
110 echo "Fixing MySQL installation..."
111 if dpkg --compare-versions "$2" ge 0.5; then
112 # Hack (ugly) to replace "mysql" by "mysql -f"
113 real_mysql="$(which mysql)"
114 workdir="$(mktemp -d)"
116 cat <<EOF > "$workdir/mysql"
118 "$real_mysql" "\$@" -f
120 chmod +x "$workdir/mysql"
121 PATH="$workdir:$PATH"
122 dbc_mysql_exec_file \
123 /usr/share/dbconfig-common/data/roundcube/upgrade/mysql/0.5-1 || true
127 cat <<EOF | while read command; do dbc_mysql_exec_command "$command" || true ; done
128 ALTER TABLE \`messages\` ADD INDEX \`index_index\` (\`user_id\`, \`cache_key\`, \`idx\`);
129 ALTER TABLE \`contacts\`ADD INDEX \`user_contacts_index\` (\`user_id\`,\`email\`);
130 ALTER TABLE \`identities\` ADD \`changed\` datetime NOT NULL DEFAULT '1000-01-01 00:00:00' AFTER \`user_id\`;
131 ALTER TABLE \`identities\` ADD INDEX \`user_identities_index\` (\`user_id\`, \`del\`);
138 if [ -n "$2" ] && dpkg --compare-versions "$2" lt 0.7.2-6; then
142 CONFFILE=/etc/roundcube/main.inc.php
143 touch $CONFFILE.ucftmp
144 chmod 640 $CONFFILE.ucftmp
145 chown root:www-data $CONFFILE.ucftmp
147 db_get roundcube/hosts || true
149 if [ "$hosts" != "" ]; then
150 hosts="array(\"$(echo $hosts | sed 's/ /\",\"/g')\")"
155 db_get roundcube/language || true
158 # Get current 3DES key from /etc/roundcube/main.inc.php
159 [ -f /etc/roundcube/main.inc.php ] && {
160 deskey=$(sed -n "s+^\$rcmail_config\['des_key'\] = '\(.*\)';\$+\1+p" \
161 /etc/roundcube/main.inc.php)
163 # If this is the default key, forget it !
164 [ "$deskey" = "rcmail-!24ByteDESkey*Str" ] && unset deskey
166 while [ -z "$deskey" ]; do
167 deskey=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | \
168 tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
171 # Put hosts, language and key in main.inc.php
172 cat /usr/share/roundcube/main.inc.php.dist | while read line; do
174 "\$rcmail_config['default_host'] = "*)
175 printf "\$rcmail_config['default_host'] = %s;\n" "${hosts}"
177 "\$rcmail_config['des_key'] = "*)
178 printf "\$rcmail_config['des_key'] = '%s';\n" "${deskey}"
180 "\$rcmail_config['language'] = "*)
181 printf "\$rcmail_config['language'] = '%s';\n" "${language}"
184 printf "%s\n" "$line"
187 done >> $CONFFILE.ucftmp
189 ucf --debconf-ok $CONFFILE.ucftmp $CONFFILE
190 chown root:www-data $CONFFILE
191 [ ! -f $CONFFILE.dpkg-dist ] || chown root:www-data $CONFFILE.dpkg-dist
192 rm -f $CONFFILE.ucftmp
194 # Handle webserver reconfiguration/restart ; stolen from zabbix package
195 db_get roundcube/reconfigure-webserver || true
199 for webserver in $webservers; do
200 webserver=${webserver%,}
201 if [ "$webserver" = "lighttpd" ] ; then
204 apache_install $webserver
206 test -x /usr/sbin/$webserver || continue
207 restart="$restart $webserver"
210 db_get roundcube/restart-webserver || true
213 if [ "$res" = "true" ]; then
214 for webserver in $restart; do
215 webserver=${webserver%,}
216 # Redirection of 3 is needed because Debconf uses it and it might
217 # be inherited by webserver. See bug #446324.
218 if [ -x /usr/sbin/invoke-rc.d ]; then
219 invoke-rc.d $webserver reload 3>/dev/null || true
221 /etc/init.d/$webserver reload 3>/dev/null || true
226 chown -R www-data:adm /var/log/roundcube
227 chmod -R 750 /var/log/roundcube
228 chown -R www-data:www-data /var/lib/roundcube/temp
229 chmod -R 750 /var/lib/roundcube/temp
233 abort-upgrade|abort-remove|abort-deconfigure)
237 echo "postinst called with unknown argument \`$1'" >&2