Commit | Line | Data |
---|---|---|
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 | ||
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 | |
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 | |
61 | db_version 2.0 | |
62 | ||
eb8500fd | 63 | dbc_first_version=0.9.20-2 |
7e17ed74 JL |
64 | # source dbconfig-common shell library, and call the hook function |
65 | if [ -f /usr/share/dbconfig-common/dpkg/postinst.mysql ]; then | |
66 | . /usr/share/dbconfig-common/dpkg/postinst.mysql | |
67 | dbc_go diogenes $@ | |
68 | fi | |
6855525e JL |
69 | |
70 | case "$1" in | |
71 | configure) | |
72 | ||
73 | # install ucf-managed files | |
74 | ucf --debconf-ok /usr/share/diogenes/config/diogenes.debian.inc.php /etc/diogenes/diogenes.debian.inc.php | |
75 | ucf --debconf-ok /usr/share/diogenes/config/apache.conf /etc/diogenes/apache.conf | |
76 | ||
6855525e JL |
77 | ############################################################################### |
78 | ########################## Configure web servers ############################## | |
79 | ############################################################################### | |
80 | ||
81 | db_get "diogenes/webservers" | |
82 | webservers="$RET" | |
83 | ||
84 | for server in $webservers; do | |
85 | server=$(echo $server | sed 's/,$//') | |
86 | servers="$server $servers" | |
6855525e | 87 | includefile=/etc/diogenes/apache.conf |
3957bfef | 88 | |
6855525e JL |
89 | # If necessary, add a symlink to our apache.conf |
90 | if [ -d /etc/$server/conf.d ] && [ ! -e /etc/$server/conf.d/diogenes ] ; then | |
91 | ln -s $includefile /etc/$server/conf.d/diogenes | |
7e17ed74 | 92 | restart_servers="$server $restart_servers" |
6855525e JL |
93 | fi |
94 | done | |
95 | ||
96 | ||
97 | ############################################################################### | |
98 | ########################## Configure Diogenes ################################# | |
99 | ############################################################################### | |
100 | ||
101 | db_get "diogenes/webuser" | |
102 | webuser="$RET" | |
103 | db_get "diogenes/webgroup" | |
104 | webgroup="$RET" | |
105 | ||
106 | ( umask 0027 # File may contain passwords | |
107 | create_file_from_template /usr/share/diogenes/config/diogenes.config.inc.php /etc/diogenes/diogenes.config.inc.php | |
108 | chgrp $webgroup /etc/diogenes/diogenes.config.inc.php | |
109 | ) | |
110 | ||
111 | # purge Smarty templates cache | |
112 | rm -rf /var/spool/diogenes/templates_c/* | |
113 | ||
114 | # correct ownership on Diogenes directories | |
115 | chown -R $webuser /var/lib/diogenes | |
116 | chown -R $webuser /var/spool/diogenes | |
117 | ||
118 | ||
119 | ############################################################################### | |
120 | ############################# Servers restart ################################# | |
121 | ############################################################################### | |
6855525e | 122 | |
7e17ed74 JL |
123 | if [ -n "$restart_servers" ]; then |
124 | for server in $restart_servers; do | |
125 | if [ -x /etc/init.d/$server ]; then | |
126 | if which invoke-rc.d >/dev/null 2>&1; then | |
127 | invoke-rc.d $server reload | |
128 | else | |
129 | /etc/init.d/$server reload | |
130 | fi | |
131 | fi | |
132 | done | |
133 | fi | |
6855525e JL |
134 | ;; |
135 | ||
136 | abort-upgrade|abort-remove|abort-deconfigure) | |
137 | ||
138 | ;; | |
139 | ||
140 | *) | |
141 | echo "postinst called with unknown argument \`$1'" >&2 | |
142 | exit 0 | |
143 | ;; | |
144 | esac | |
145 | ||
146 | # dh_installdeb will replace this with shell code automatically | |
147 | # generated by other debhelper scripts. | |
148 | ||
149 | #DEBHELPER# | |
150 | ||
151 | exit 0 | |
152 |