| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | set -e |
|---|
| 4 | |
|---|
| 5 | # summary of how this script can be called: |
|---|
| 6 | # * <postinst> `configure' <most-recently-configured-version> |
|---|
| 7 | # * <old-postinst> `abort-upgrade' <new version> |
|---|
| 8 | # * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
|---|
| 9 | # <new-version> |
|---|
| 10 | # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
|---|
| 11 | # <failed-install-package> <version> `removing' |
|---|
| 12 | # <conflicting-package> <version> |
|---|
| 13 | # for details, see http://www.debian.org/doc/debian-policy/ or |
|---|
| 14 | # the debian-policy package |
|---|
| 15 | # |
|---|
| 16 | # quoting from the policy: |
|---|
| 17 | # Any necessary prompting should almost always be confined to the |
|---|
| 18 | # post-installation script, and should be protected with a conditional |
|---|
| 19 | # so that unnecessary prompting doesn't happen if a package's |
|---|
| 20 | # installation fails and the `postinst' is called with `abort-upgrade', |
|---|
| 21 | # `abort-remove' or `abort-deconfigure'. |
|---|
| 22 | |
|---|
| 23 | alternc_conf=/etc/alternc/alternc.conf |
|---|
| 24 | |
|---|
| 25 | # helper to change variables in alternc.conf |
|---|
| 26 | change_var () { |
|---|
| 27 | varname=$1; shift; |
|---|
| 28 | value=$1; shift; |
|---|
| 29 | |
|---|
| 30 | echo "changing var $varname to $value" |
|---|
| 31 | sed -e "s#^${varname}=.*\$#${varname}=${value}#" < $alternc_conf > $alternc_conf.$$ && \ |
|---|
| 32 | mv $alternc_conf.$$ $alternc_conf |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | case "$1" in |
|---|
| 36 | configure) |
|---|
| 37 | |
|---|
| 38 | # Prepare the sasldb for postfix : |
|---|
| 39 | touch /etc/sasldb |
|---|
| 40 | chgrp 33 /etc/sasldb |
|---|
| 41 | chmod g+w /etc/sasldb |
|---|
| 42 | |
|---|
| 43 | # Source debconf library. |
|---|
| 44 | . /usr/share/debconf/confmodule |
|---|
| 45 | |
|---|
| 46 | # rebuild local.sh |
|---|
| 47 | cat > /etc/alternc/local.sh <<EOF |
|---|
| 48 | #!/bin/sh |
|---|
| 49 | # |
|---|
| 50 | # AlternC - Web Hosting System |
|---|
| 51 | # Purpose of file: Contient les données communes |
|---|
| 52 | # utilisées par les scripts shell |
|---|
| 53 | # Content will be overwritten by postinst on upgrades. Make |
|---|
| 54 | # modifications through debconf (dpkg-reconfigure alternc) |
|---|
| 55 | EOF |
|---|
| 56 | |
|---|
| 57 | chown www-data /etc/alternc/local.sh |
|---|
| 58 | |
|---|
| 59 | for pair in \ |
|---|
| 60 | "alternc/desktopname FQDN" \ |
|---|
| 61 | "alternc/default_ip DEFAULT_IP" \ |
|---|
| 62 | "alternc/default_mx DEFAULT_MX" \ |
|---|
| 63 | "alternc/data_part DATA_PART" \ |
|---|
| 64 | "alternc/mysql/host MYSQL_HOST" \ |
|---|
| 65 | "alternc/mysql/db MYSQL_DATABASE" \ |
|---|
| 66 | "alternc/mysql/user MYSQL_USER" \ |
|---|
| 67 | "alternc/mysql/password MYSQL_PASS" |
|---|
| 68 | do |
|---|
| 69 | skip=0 |
|---|
| 70 | for single in $pair |
|---|
| 71 | do |
|---|
| 72 | if [ "$skip" = "0" ]; then |
|---|
| 73 | db_get "$single" || true |
|---|
| 74 | skip=1 |
|---|
| 75 | else |
|---|
| 76 | echo "$single=$RET" >> /etc/alternc/local.sh |
|---|
| 77 | fi |
|---|
| 78 | done |
|---|
| 79 | done |
|---|
| 80 | |
|---|
| 81 | # forget the password |
|---|
| 82 | db_reset alternc/mysql/password || true |
|---|
| 83 | db_fset alternc/mysql/password "seen" "false" || true |
|---|
| 84 | |
|---|
| 85 | if [ -e /etc/alternc/local.sh ]; then |
|---|
| 86 | # source local.sh variables |
|---|
| 87 | . /etc/alternc/local.sh |
|---|
| 88 | fi |
|---|
| 89 | |
|---|
| 90 | # |
|---|
| 91 | # rewriting alternc.conf |
|---|
| 92 | # |
|---|
| 93 | change_var "mx" "$DEFAULT_MX" |
|---|
| 94 | change_var "DATA_PART" "$DATA_PART" |
|---|
| 95 | change_var "dbhost" "$MYSQL_HOST" |
|---|
| 96 | change_var "dbuser" "$MYSQL_USER" |
|---|
| 97 | change_var "dbpwd" "$MYSQL_PASS" |
|---|
| 98 | change_var "dbname" "$MYSQL_DATABASE" |
|---|
| 99 | change_var "fqdn" "$FQDN" |
|---|
| 100 | change_var "public_ip" "$DEFAULT_IP" |
|---|
| 101 | |
|---|
| 102 | for pair in \ |
|---|
| 103 | "alternc/internal_ip internal_ip" \ |
|---|
| 104 | "alternc/hostingname hosting" \ |
|---|
| 105 | "alternc/ns1 ns1" \ |
|---|
| 106 | "alternc/ns2 ns2" |
|---|
| 107 | do |
|---|
| 108 | skip=0 |
|---|
| 109 | for single in $pair |
|---|
| 110 | do |
|---|
| 111 | if [ "$skip" = "0" ]; then |
|---|
| 112 | var="$single" |
|---|
| 113 | skip=1 |
|---|
| 114 | else |
|---|
| 115 | db_get "$var" || true |
|---|
| 116 | change_var "$single" "$RET" |
|---|
| 117 | fi |
|---|
| 118 | done |
|---|
| 119 | done |
|---|
| 120 | |
|---|
| 121 | # those variables could eventually be prompted for |
|---|
| 122 | echo "The following variables have been left untouched in alternc.conf" |
|---|
| 123 | echo "You will have to review those before manually launching alternc.install" |
|---|
| 124 | |
|---|
| 125 | cat <<EOF |
|---|
| 126 | monitor_ip |
|---|
| 127 | bind_internal |
|---|
| 128 | myrandom |
|---|
| 129 | mynetwork |
|---|
| 130 | EOF |
|---|
| 131 | |
|---|
| 132 | echo "checking for upgrades" |
|---|
| 133 | /usr/share/alternc/install/upgrade_check.sh $2 |
|---|
| 134 | |
|---|
| 135 | ;; |
|---|
| 136 | |
|---|
| 137 | abort-upgrade|abort-remove|abort-deconfigure) |
|---|
| 138 | |
|---|
| 139 | ;; |
|---|
| 140 | |
|---|
| 141 | *) |
|---|
| 142 | echo "postinst called with unknown argument \`$1'" >&2 |
|---|
| 143 | exit 1 |
|---|
| 144 | ;; |
|---|
| 145 | |
|---|
| 146 | esac |
|---|
| 147 | |
|---|
| 148 | # dh_installdeb will replace this with shell code automatically |
|---|
| 149 | # generated by other debhelper scripts. |
|---|
| 150 | |
|---|
| 151 | #DEBHELPER# |
|---|
| 152 | |
|---|
| 153 | exit 0 |
|---|