source: trunk/debian/postinst @ 1020

Revision 1020, 5.1 KB checked in by anarcat, 7 years ago (diff)

symlink our apache configs in postinst and remove them on postrm

remove the now duplicate configuration from our httpd.conf
templates. this doesn't fix the original bug (see #562) because we
still overwrite the config to avoid conflicting configurations.

this makes 0.9.5 a obligatory migration stop for upgrade paths.

Line 
1#!/bin/sh
2
3set -e
4
5# Source debconf library.
6. /usr/share/debconf/confmodule
7
8CONFIGFILE="/etc/alternc/local.sh"
9
10update_var() {
11    local question="$1"
12    local var="$2"
13    db_get "$question"
14    if [ ! -z "$RET" ]; then
15        grep -Eq "^ *$var=" $CONFIGFILE || echo "$var=" >> $CONFIGFILE
16        SED_SCRIPT="$SED_SCRIPT;s\\^ *$var=.*\\$var=\"$RET\"\\"
17    fi
18}
19
20# summary of how this script can be called:
21#        * <postinst> `configure' <most-recently-configured-version>
22#        * <old-postinst> `abort-upgrade' <new version>
23#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
24#          <new-version>
25#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
26#          <failed-install-package> <version> `removing'
27#          <conflicting-package> <version>
28# for details, see http://www.debian.org/doc/debian-policy/ or
29# the debian-policy package
30#
31# quoting from the policy:
32#     Any necessary prompting should almost always be confined to the
33#     post-installation script, and should be protected with a conditional
34#     so that unnecessary prompting doesn't happen if a package's
35#     installation fails and the `postinst' is called with `abort-upgrade',
36#     `abort-remove' or `abort-deconfigure'.
37
38case "$1" in
39  configure)
40
41    # build local.sh if it does not exist
42    if [ ! -f $CONFIGFILE ]; then
43        cat > $CONFIGFILE <<EOF
44#!/bin/sh
45#
46# AlternC - Web Hosting System - Configuration
47# This file will be modified on package configuration
48# (e.g. upgrade or dpkg-reconfigure alternc)
49
50# Hosting service name
51HOSTING=""
52
53# Primary hostname for this box (will be used to access the management panel)
54FQDN=""
55
56# Public IP
57PUBLIC_IP=""
58
59# Internal IP
60# (most of the time, should be equal to PUBLIC_IP, unless you are behind
61# firewall doing address translation)
62INTERNAL_IP=""
63
64# Monitoring IP or network (will be allowed to access Apache status)
65MONITOR_IP=""
66
67# Primary DNS hostname
68NS1_HOSTNAME=""
69
70# Secondary DNS hostname
71NS2_HOSTNAME=""
72
73# IP that have privilegied access to the DNS server. Separated by ';'.
74BIND_INTERNAL=""
75
76# Mail server hostname
77DEFAULT_MX=""
78
79# MySQL configuration
80MYSQL_HOST=""
81MYSQL_DATABASE=""
82MYSQL_USER=""
83MYSQL_PASS=""
84# quels clients mysql sont permis (%, localhost, etc)
85MYSQL_CLIENT=""
86
87# Folder holding data (used for quota management)
88ALTERNC_LOC=""
89
90# Networks that SMTP should relay, separated with spaces
91SMTP_RELAY_NETWORKS=""
92EOF
93
94        chown root:www-data $CONFIGFILE
95        chmod 640 $CONFIGFILE
96    fi
97
98    # Update local.sh
99    # 1. use cp to keep permissions
100    # 2. add missing variable to local.sh
101    # 3. use sed to set variables with current values
102    echo "Updating $CONFIGFILE"
103    cp -a -f $CONFIGFILE $CONFIGFILE.tmp
104    # SED_SCRIPT will be modified by update_var
105    SED_SCRIPT=""
106    update_var alternc/hostingname HOSTING
107    update_var alternc/desktopname FQDN
108    update_var alternc/public_ip PUBLIC_IP
109    update_var alternc/internal_ip INTERNAL_IP
110    update_var alternc/monitor_ip MONITOR_IP
111    update_var alternc/ns1 NS1_HOSTNAME
112    update_var alternc/ns2 NS2_HOSTNAME
113    update_var alternc/bind_internal BIND_INTERNAL
114    update_var alternc/default_mx DEFAULT_MX
115    update_var alternc/mysql/host MYSQL_HOST
116    update_var alternc/mysql/db MYSQL_DATABASE
117    update_var alternc/mysql/user MYSQL_USER
118    update_var alternc/mysql/password MYSQL_PASS
119    update_var alternc/mysql/client MYSQL_CLIENT
120    update_var alternc/alternc_location ALTERNC_LOC
121    update_var alternc/mynetwork SMTP_RELAY_NETWORKS
122    sed -e "$SED_SCRIPT" < $CONFIGFILE > $CONFIGFILE.tmp
123    mv -f $CONFIGFILE.tmp $CONFIGFILE
124
125    # forget the password
126    db_reset alternc/mysql/password || true
127    db_fset alternc/mysql/password "seen" "false" || true
128
129    if [ -e $CONFIGFILE ]; then
130      # source local.sh variables
131      . $CONFIGFILE
132    fi
133
134    # Erase all apacheconf file
135    # They will be regenerated without the bug by upgrade_check.sh below.
136    if dpkg --compare-versions "$2" le "0.9.3.9-globenet14"; then
137        rm -f /var/alternc/apacheconf/*/*
138        rm -f /var/alternc/apacheconf/override_php.conf
139    fi
140
141    echo "checking for upgrades"
142    /usr/share/alternc/install/upgrade_check.sh $2
143
144    echo "config phpmyadmin"
145    include_str='include_once("/etc/alternc/phpmyadmin.inc.php")'
146    pma_config=/etc/phpmyadmin/config.inc.php
147    if ! grep -e "$include_str" $pma_config > /dev/null 2>&1; then
148        echo "<?php $include_str ?>" >> $pma_config
149    fi
150
151    # important: postinst gele sans ca
152    db_stop
153
154    echo "running alternc.install"
155    alternc.install
156
157    if [ ! -h /etc/apache/conf.d/alternc-ssl.conf ]; then
158        ln -sf /etc/apache/conf.d/alternc-ssl.conf \
159            /etc/apache/conf.d/alternc-ssl.conf
160    fi
161
162    if [ ! -h /etc/apache/conf.d/alternc.conf ]; then
163        ln -sf /etc/apache/conf.d/alternc.conf \
164            /etc/apache/conf.d/alternc.conf
165    fi
166
167    ;;
168
169    abort-upgrade|abort-remove|abort-deconfigure)
170
171    ;;
172
173    *)
174        echo "postinst called with unknown argument \`$1'" >&2
175        exit 1
176    ;;
177
178esac
179
180# dh_installdeb will replace this with shell code automatically
181# generated by other debhelper scripts.
182
183#DEBHELPER#
184
185exit 0
186
187# vim: et sw=4
Note: See TracBrowser for help on using the repository browser.