start move to dbconfig-common based idb configuration
[diogenes.git] / debian / diogenes.postinst
CommitLineData
6855525e 1#! /bin/sh
7e17ed74 2# Diogenes postinst script using debconf and dbconfig-common
6855525e
JL
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
11set -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
30create_file_from_template() {
31 infile=$1
32 outfile=$2
7e17ed74
JL
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
6855525e
JL
40 # Password may contain anything, so we need to descend to quoting
41 # hell.
7e17ed74 42 safepass="$dbc_dbpass"
6855525e
JL
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 " \
7e17ed74
JL
52 s#@dbname@#$dbc_dbname#; \
53 s#@dbserver@#$dbc_dbserver#; \
54 s#@dbuser@#$dbc_dbuser#; \
6855525e
JL
55 s#@dbpass@#$safepass#; \
56 " <$infile >$outfile
57}
58
7e17ed74
JL
59# get debconf started
60. /usr/share/debconf/confmodule
61db_version 2.0
62
63# source dbconfig-common shell library, and call the hook function
64if [ -f /usr/share/dbconfig-common/dpkg/postinst.mysql ]; then
65 . /usr/share/dbconfig-common/dpkg/postinst.mysql
66 dbc_go diogenes $@
67fi
6855525e
JL
68
69case "$1" in
70 configure)
71
72# install ucf-managed files
73ucf --debconf-ok /usr/share/diogenes/config/diogenes.debian.inc.php /etc/diogenes/diogenes.debian.inc.php
74ucf --debconf-ok /usr/share/diogenes/config/apache.conf /etc/diogenes/apache.conf
75
6855525e
JL
76###############################################################################
77########################## Configure web servers ##############################
78###############################################################################
79
80db_get "diogenes/webservers"
81webservers="$RET"
82
83for server in $webservers; do
84 server=$(echo $server | sed 's/,$//')
85 servers="$server $servers"
6855525e 86 includefile=/etc/diogenes/apache.conf
3957bfef 87
6855525e
JL
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
7e17ed74 91 restart_servers="$server $restart_servers"
6855525e
JL
92 fi
93done
94
95
96###############################################################################
97########################## Configure Diogenes #################################
98###############################################################################
99
100db_get "diogenes/webuser"
101webuser="$RET"
102db_get "diogenes/webgroup"
103webgroup="$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
111rm -rf /var/spool/diogenes/templates_c/*
112
113# correct ownership on Diogenes directories
114chown -R $webuser /var/lib/diogenes
115chown -R $webuser /var/spool/diogenes
116
117
118###############################################################################
119############################# Servers restart #################################
120###############################################################################
6855525e 121
7e17ed74
JL
122if [ -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
132fi
6855525e
JL
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 ;;
143esac
144
145# dh_installdeb will replace this with shell code automatically
146# generated by other debhelper scripts.
147
148#DEBHELPER#
149
150exit 0
151