change RSS mime type to application/rss+xml
[diogenes.git] / debian / diogenes.postinst
1 #! /bin/sh
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>
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   # Password may contain anything, so we need to descend to quoting
34   # hell.
35   safepass="$dbpass"
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')
44   sed -e "                              \
45     s#@dbname@#$dbname#;                \
46     s#@dbserver@#$dbserver#;    \
47     s#@dbuser@#$dbuser#;                \
48     s#@dbpass@#$safepass#;              \
49     " <$infile >$outfile
50 }
51
52
53 case "$1" in
54     configure)
55  
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
59
60 # get debconf started
61 . /usr/share/debconf/confmodule
62 db_version 2.0
63
64 ###############################################################################
65 ############################### Configure database ############################
66 ###############################################################################
67
68 # Type of the databasemgr to use.
69 db_get "diogenes/databasemgr_type"
70 dbtype="$RET"
71 if [ "$dbtype" = "Automatic" ] ; then
72   # Where it is located.
73   db_get "diogenes/databasemgr_server"
74   dbserver="$RET"
75   # Name of the database
76   db_get "diogenes/database_name"
77   dbname="$RET"
78   # Name of the user to have access.
79   db_get "diogenes/database_user"
80   dbuser="$RET"
81   # Its password.
82   db_get "diogenes/database_pass"
83   dbpass="$RET"
84
85   if [ ! -z $(which mysql) ]; then
86
87     # retrieve admin user and password
88     db_get "diogenes/dbmyadmin"
89     dbadmin="$RET"
90     db_get "diogenes/dbadmpass"
91     dbadmpass="$RET"
92     db_reset "diogenes/dbadmpass"
93
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
99       rm $sqlfile
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
103       rm $sqlfile
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."
107       fi
108     else
109       echo $error
110     fi
111     . /usr/share/wwwconfig-common/mysql-createuser.sh
112   else
113     echo "Not configuring MySQL database because we cannot locate"
114     echo "the mysql client executable (mysql-client package missing)."
115   fi
116 else
117     echo "Not configuring MySQL database at your request."
118 fi
119
120
121 ###############################################################################
122 ########################## Configure web servers ##############################
123 ###############################################################################
124
125 db_get "diogenes/webservers"
126 webservers="$RET"
127
128 for server in $webservers; do
129     server=$(echo $server | sed 's/,$//')
130     servers="$server $servers"
131     includefile=/etc/diogenes/apache.conf
132
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"
137     fi
138 done
139
140
141 ###############################################################################
142 ########################## Configure Diogenes #################################
143 ###############################################################################
144
145 db_get "diogenes/webuser"
146 webuser="$RET"
147 db_get "diogenes/webgroup"
148 webgroup="$RET"
149
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
153 )
154
155 # purge Smarty templates cache
156 rm -rf /var/spool/diogenes/templates_c/*
157
158 # correct ownership on Diogenes directories
159 chown -R $webuser /var/lib/diogenes
160 chown -R $webuser /var/spool/diogenes
161
162
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)."
168 fi
169
170     ;;
171
172     abort-upgrade|abort-remove|abort-deconfigure)
173
174     ;;
175
176     *)
177         echo "postinst called with unknown argument \`$1'" >&2
178         exit 0
179     ;;
180 esac
181
182 # dh_installdeb will replace this with shell code automatically
183 # generated by other debhelper scripts.
184
185 #DEBHELPER#
186
187 exit 0
188