2 # Horde postinst script using debconf
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 # Password may contain anything, so we need to descend to quoting
36 # quote normal quote and final backslash because we need to write
37 # a single quoted PHP string
38 safepass=$(echo "$safepass" | sed -e "s/'/\\\\'/g" -e 's/\\$/\\\\'/)
39 # Now double backslashes because we will use sed
40 safepass=$(echo "$safepass" | sed -e 's/\\/\\\\/g')
41 # Finally escape an eventual hash sign with a backslash because
42 # we use the hash sign as a delimiter
43 safepass=$(echo "$safepass" | sed -e 's/#/\\#/g')
45 s#@dbname@#$dbname#; \
46 s#@dbserver@#$dbserver#; \
47 s#@dbuser@#$dbuser#; \
48 s#@dbpass@#$safepass#; \
56 # install ucf-managed files
57 ucf --debconf-ok /usr/share/diogenes/config/diogenes.debian.inc.php /etc/diogenes/diogenes.debian.inc.php
58 ucf --debconf-ok /usr/share/diogenes/config/apache.conf /etc/diogenes/apache.conf
61 . /usr/share/debconf/confmodule
64 ###############################################################################
65 ############################### Configure database ############################
66 ###############################################################################
68 # Type of the databasemgr to use.
69 db_get "diogenes/databasemgr_type"
71 if [ "$dbtype" = "Automatic" ] ; then
72 # Where it is located.
73 db_get "diogenes/databasemgr_server"
75 # Name of the database
76 db_get "diogenes/database_name"
78 # Name of the user to have access.
79 db_get "diogenes/database_user"
82 db_get "diogenes/database_pass"
85 if [ ! -z $(which mysql) ]; then
87 # retrieve admin user and password
88 db_get "diogenes/dbmyadmin"
90 db_get "diogenes/dbadmpass"
92 db_reset "diogenes/dbadmpass"
94 . /usr/share/wwwconfig-common/mysql-createdb.sh
95 if [ "$status" = "create" ] ; then
96 sqlfile=/usr/share/diogenes/scripts/diogenes.tables.sql
97 create_file_from_template $sqlfile.in $sqlfile
98 . /usr/share/wwwconfig-common/mysql-exec.sh
100 sqlfile=/usr/share/diogenes/scripts/diogenes.logactions.sql
101 create_file_from_template $sqlfile.in $sqlfile
102 . /usr/share/wwwconfig-common/mysql-exec.sh
104 elif [ "$status" = "nothing" ] ; then
105 if ! /usr/share/diogenes/scripts/updatedb.php -q -s "$dbserver" -d "$dbname" -u "$dbadmin" -p "$dbadmpass" ; then
106 echo "There was an error while upgrading the Diogenes database."
111 . /usr/share/wwwconfig-common/mysql-createuser.sh
113 echo "Not configuring MySQL database because we cannot locate"
114 echo "the mysql client executable (mysql-client package missing)."
117 echo "Not configuring MySQL database at your request."
121 ###############################################################################
122 ########################## Configure web servers ##############################
123 ###############################################################################
125 db_get "diogenes/webservers"
128 for server in $webservers; do
129 server=$(echo $server | sed 's/,$//')
130 servers="$server $servers"
131 includefile=/etc/diogenes/apache.conf
133 # If necessary, add a symlink to our apache.conf
134 if [ -d /etc/$server/conf.d ] && [ ! -e /etc/$server/conf.d/diogenes ] ; then
135 ln -s $includefile /etc/$server/conf.d/diogenes
136 restart="$server $restart"
141 ###############################################################################
142 ########################## Configure Diogenes #################################
143 ###############################################################################
145 db_get "diogenes/webuser"
147 db_get "diogenes/webgroup"
150 ( umask 0027 # File may contain passwords
151 create_file_from_template /usr/share/diogenes/config/diogenes.config.inc.php /etc/diogenes/diogenes.config.inc.php
152 chgrp $webgroup /etc/diogenes/diogenes.config.inc.php
155 # purge Smarty templates cache
156 rm -rf /var/spool/diogenes/templates_c/*
158 # correct ownership on Diogenes directories
159 chown -R $webuser /var/lib/diogenes
160 chown -R $webuser /var/spool/diogenes
163 ###############################################################################
164 ############################# Servers restart #################################
165 ###############################################################################
166 if ! eval . /usr/share/wwwconfig-common/restart.sh ; then
167 echo "There was a problem restarting web server(s)."
172 abort-upgrade|abort-remove|abort-deconfigure)
177 echo "postinst called with unknown argument \`$1'" >&2
182 # dh_installdeb will replace this with shell code automatically
183 # generated by other debhelper scripts.