| 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 | # Make sure our web server has PHP support |
| 132 | phpver=php4 |
| 133 | phpini=/etc/$phpver/$server/php.ini |
| 134 | . /usr/share/wwwconfig-common/apache-php.sh |
| 135 | if [ "$status" = "uncomment" ] ; then |
| 136 | restart="$server $restart" |
| 137 | elif [ "$status" = "error" ] ; then |
| 138 | echo "Error while trying to enable $phpver support for '$server' : $error." |
| 139 | fi |
| 140 | |
| 141 | # Make sure that PHP has MySQL support enabled |
| 142 | checkextensions=mysql |
| 143 | . /usr/share/wwwconfig-common/php-extensions.sh |
| 144 | |
| 145 | includefile=/etc/diogenes/apache.conf |
| 146 | # For old versions of Diogenes, remove the include of ourapache.conf |
| 147 | if dpkg --compare-versions "$2" le-nl "0.9.9.3-6" ; then |
| 148 | . /usr/share/wwwconfig-common/apache-uninclude_all.sh |
| 149 | if [ "$status" = "uncomment" ] ; then |
| 150 | restart="$server $restart" |
| 151 | fi |
| 152 | fi |
| 153 | |
| 154 | # If necessary, add a symlink to our apache.conf |
| 155 | if [ -d /etc/$server/conf.d ] && [ ! -e /etc/$server/conf.d/diogenes ] ; then |
| 156 | ln -s $includefile /etc/$server/conf.d/diogenes |
| 157 | restart="$server $restart" |
| 158 | fi |
| 159 | done |
| 160 | |
| 161 | |
| 162 | ############################################################################### |
| 163 | ########################## Configure Diogenes ################################# |
| 164 | ############################################################################### |
| 165 | |
| 166 | db_get "diogenes/webuser" |
| 167 | webuser="$RET" |
| 168 | db_get "diogenes/webgroup" |
| 169 | webgroup="$RET" |
| 170 | |
| 171 | ( umask 0027 # File may contain passwords |
| 172 | create_file_from_template /usr/share/diogenes/config/diogenes.config.inc.php /etc/diogenes/diogenes.config.inc.php |
| 173 | chgrp $webgroup /etc/diogenes/diogenes.config.inc.php |
| 174 | ) |
| 175 | |
| 176 | # purge Smarty templates cache |
| 177 | rm -rf /var/spool/diogenes/templates_c/* |
| 178 | |
| 179 | # correct ownership on Diogenes directories |
| 180 | chown -R $webuser /var/lib/diogenes |
| 181 | chown -R $webuser /var/spool/diogenes |
| 182 | |
| 183 | |
| 184 | ############################################################################### |
| 185 | ############################# Servers restart ################################# |
| 186 | ############################################################################### |
| 187 | if ! eval . /usr/share/wwwconfig-common/restart.sh ; then |
| 188 | echo "There was a problem restarting web server(s)." |
| 189 | fi |
| 190 | |
| 191 | ;; |
| 192 | |
| 193 | abort-upgrade|abort-remove|abort-deconfigure) |
| 194 | |
| 195 | ;; |
| 196 | |
| 197 | *) |
| 198 | echo "postinst called with unknown argument \`$1'" >&2 |
| 199 | exit 0 |
| 200 | ;; |
| 201 | esac |
| 202 | |
| 203 | # dh_installdeb will replace this with shell code automatically |
| 204 | # generated by other debhelper scripts. |
| 205 | |
| 206 | #DEBHELPER# |
| 207 | |
| 208 | exit 0 |
| 209 | |