2 # Diogenes postinst script using debconf and dbconfig-common
3 # Written by Ola Lundqvist <opal@debian.org>
4 # Adapted for Horde2 by Nils Rennebarth <nils@debian.org>
5 # Adapted for Diogenes by Jeremy Lainé <jeremy.laine@m4x.org>
7 # All questions should have been asked via debconf
8 # now we just go get those, build a temp file which we read in and
9 # then build our config files and set everthing up
13 # summary of how this script can be called:
14 # * <postinst> `configure' <most-recently-configured-version>
15 # * <old-postinst> `abort-upgrade' <new version>
16 # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
18 # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
19 # <failed-install-package> <version> `removing'
20 # <conflicting-package> <version>
21 # for details, see /usr/share/doc/packaging-manual/
23 # quoting from the policy:
24 # Any necessary prompting should almost always be confined to the
25 # post-installation script, and should be protected with a conditional
26 # so that unnecessary prompting doesn't happen if a package's
27 # installation fails and the `postinst' is called with `abort-upgrade',
28 # `abort-remove' or `abort-deconfigure'.
30 create_file_from_template() {
33 if [ -f /etc/dbconfig-common/diogenes.conf ]; then
34 . /etc/dbconfig-common/diogenes.conf
36 # If dbc_dbserver is empty, use localhost
37 if [ -z "$dbc_dbserver" ]; then
38 dbc_dbserver="localhost"
40 # Password may contain anything, so we need to descend to quoting
42 safepass="$dbc_dbpass"
43 # quote normal quote and final backslash because we need to write
44 # a single quoted PHP string
45 safepass=$(echo "$safepass" | sed -e "s/'/\\\\'/g" -e 's/\\$/\\\\'/)
46 # Now double backslashes because we will use sed
47 safepass=$(echo "$safepass" | sed -e 's/\\/\\\\/g')
48 # Finally escape an eventual hash sign with a backslash because
49 # we use the hash sign as a delimiter
50 safepass=$(echo "$safepass" | sed -e 's/#/\\#/g')
52 s#@dbname@#$dbc_dbname#; \
53 s#@dbserver@#$dbc_dbserver#; \
54 s#@dbuser@#$dbc_dbuser#; \
55 s#@dbpass@#$safepass#; \
60 . /usr/share/debconf/confmodule
63 # source dbconfig-common shell library, and call the hook function
64 if [ -f /usr/share/dbconfig-common/dpkg/postinst.mysql ]; then
65 . /usr/share/dbconfig-common/dpkg/postinst.mysql
72 # install ucf-managed files
73 ucf --debconf-ok /usr/share/diogenes/config/diogenes.debian.inc.php /etc/diogenes/diogenes.debian.inc.php
74 ucf --debconf-ok /usr/share/diogenes/config/apache.conf /etc/diogenes/apache.conf
76 ###############################################################################
77 ########################## Configure web servers ##############################
78 ###############################################################################
80 db_get "diogenes/webservers"
83 for server in $webservers; do
84 server=$(echo $server | sed 's/,$//')
85 servers="$server $servers"
86 includefile=/etc/diogenes/apache.conf
88 # If necessary, add a symlink to our apache.conf
89 if [ -d /etc/$server/conf.d ] && [ ! -e /etc/$server/conf.d/diogenes ] ; then
90 ln -s $includefile /etc/$server/conf.d/diogenes
91 restart_servers="$server $restart_servers"
96 ###############################################################################
97 ########################## Configure Diogenes #################################
98 ###############################################################################
100 db_get "diogenes/webuser"
102 db_get "diogenes/webgroup"
105 ( umask 0027 # File may contain passwords
106 create_file_from_template /usr/share/diogenes/config/diogenes.config.inc.php /etc/diogenes/diogenes.config.inc.php
107 chgrp $webgroup /etc/diogenes/diogenes.config.inc.php
110 # purge Smarty templates cache
111 rm -rf /var/spool/diogenes/templates_c/*
113 # correct ownership on Diogenes directories
114 chown -R $webuser /var/lib/diogenes
115 chown -R $webuser /var/spool/diogenes
118 ###############################################################################
119 ############################# Servers restart #################################
120 ###############################################################################
122 if [ -n "$restart_servers" ]; then
123 for server in $restart_servers; do
124 if [ -x /etc/init.d/$server ]; then
125 if which invoke-rc.d >/dev/null 2>&1; then
126 invoke-rc.d $server reload
128 /etc/init.d/$server reload
135 abort-upgrade|abort-remove|abort-deconfigure)
140 echo "postinst called with unknown argument \`$1'" >&2
145 # dh_installdeb will replace this with shell code automatically
146 # generated by other debhelper scripts.