start move to dbconfig-common based idb configuration
[diogenes.git] / debian / diogenes.postinst
1 #! /bin/sh
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>
6 #
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
10
11 set -e
12
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>
17 #          <new-version>
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/
22 #
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'.
29
30 create_file_from_template() {
31   infile=$1
32   outfile=$2
33   if [ -f /etc/dbconfig-common/diogenes.conf ]; then
34     . /etc/dbconfig-common/diogenes.conf
35   fi
36   # If dbc_dbserver is empty, use localhost
37   if [ -z "$dbc_dbserver" ]; then
38       dbc_dbserver="localhost"
39   fi
40   # Password may contain anything, so we need to descend to quoting
41   # hell.
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')
51   sed -e "                              \
52     s#@dbname@#$dbc_dbname#;            \
53     s#@dbserver@#$dbc_dbserver#;        \
54     s#@dbuser@#$dbc_dbuser#;            \
55     s#@dbpass@#$safepass#;              \
56     " <$infile >$outfile
57 }
58
59 # get debconf started
60 . /usr/share/debconf/confmodule
61 db_version 2.0
62
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 
66     dbc_go diogenes $@
67 fi
68
69 case "$1" in
70     configure)
71  
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
75
76 ###############################################################################
77 ########################## Configure web servers ##############################
78 ###############################################################################
79
80 db_get "diogenes/webservers"
81 webservers="$RET"
82
83 for server in $webservers; do
84     server=$(echo $server | sed 's/,$//')
85     servers="$server $servers"
86     includefile=/etc/diogenes/apache.conf
87
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"
92     fi
93 done
94
95
96 ###############################################################################
97 ########################## Configure Diogenes #################################
98 ###############################################################################
99
100 db_get "diogenes/webuser"
101 webuser="$RET"
102 db_get "diogenes/webgroup"
103 webgroup="$RET"
104
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
108 )
109
110 # purge Smarty templates cache
111 rm -rf /var/spool/diogenes/templates_c/*
112
113 # correct ownership on Diogenes directories
114 chown -R $webuser /var/lib/diogenes
115 chown -R $webuser /var/spool/diogenes
116
117
118 ###############################################################################
119 ############################# Servers restart #################################
120 ###############################################################################
121
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
127             else
128                 /etc/init.d/$server reload
129             fi
130         fi
131     done
132 fi
133     ;;
134
135     abort-upgrade|abort-remove|abort-deconfigure)
136
137     ;;
138
139     *)
140         echo "postinst called with unknown argument \`$1'" >&2
141         exit 0
142     ;;
143 esac
144
145 # dh_installdeb will replace this with shell code automatically
146 # generated by other debhelper scripts.
147
148 #DEBHELPER#
149
150 exit 0
151