| 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 | cp /dev/null /etc/alternc/local.sh |
|---|
| 48 | |
|---|
| 49 | chown www-data /etc/alternc/local.sh |
|---|
| 50 | |
|---|
| 51 | for pair in \ |
|---|
| 52 | "alternc/default_ip DEFAULT_IP" \ |
|---|
| 53 | "alternc/default_mx DEFAULT_MX" \ |
|---|
| 54 | "alternc/data_part DATA_PART" \ |
|---|
| 55 | "alternc/mysql/host MYSQL_HOST" \ |
|---|
| 56 | "alternc/mysql/db MYSQL_DATABASE" \ |
|---|
| 57 | "alternc/mysql/user MYSQL_USER" \ |
|---|
| 58 | "alternc/mysql/password MYSQL_PASS" |
|---|
| 59 | do |
|---|
| 60 | skip=0 |
|---|
| 61 | for single in $pair |
|---|
| 62 | do |
|---|
| 63 | if [ "$skip" = "0" ]; then |
|---|
| 64 | db_get "$single" || true |
|---|
| 65 | skip=1 |
|---|
| 66 | else |
|---|
| 67 | echo "$single=$RET" >> /etc/alternc/local.sh |
|---|
| 68 | fi |
|---|
| 69 | done |
|---|
| 70 | done |
|---|
| 71 | |
|---|
| 72 | # forget the password |
|---|
| 73 | db_reset alternc/mysql/password || true |
|---|
| 74 | db_fset alternc/mysql/password "seen" "false" || true |
|---|
| 75 | db_reset alternc/mysql/root_password || true |
|---|
| 76 | db_fset alternc/mysql/root_password "seen" "false" || true |
|---|
| 77 | |
|---|
| 78 | if [ -e /etc/alternc/local.sh ]; then |
|---|
| 79 | # source local.sh variables |
|---|
| 80 | . /etc/alternc/local.sh |
|---|
| 81 | fi |
|---|
| 82 | |
|---|
| 83 | # |
|---|
| 84 | # rewriting alternc.conf |
|---|
| 85 | # |
|---|
| 86 | change_var "mx" "$DEFAULT_MX" |
|---|
| 87 | change_var "DATA_PART" "$DATA_PART" |
|---|
| 88 | change_var "dbhost" "$MYSQL_HOST" |
|---|
| 89 | change_var "dbuser" "$MYSQL_USER" |
|---|
| 90 | change_var "dbpwd" "$MYSQL_PASS" |
|---|
| 91 | change_var "dbname" "$MYSQL_DATABASE" |
|---|
| 92 | change_var "myip" "$DEFAULT_IP" |
|---|
| 93 | |
|---|
| 94 | for pair in \ |
|---|
| 95 | "alternc/desktopname fqdn" \ |
|---|
| 96 | "alternc/hostingname hosting" \ |
|---|
| 97 | "alternc/ns1 ns1" \ |
|---|
| 98 | "alternc/ns2 ns2" |
|---|
| 99 | do |
|---|
| 100 | skip=0 |
|---|
| 101 | for single in $pair |
|---|
| 102 | do |
|---|
| 103 | if [ "$skip" = "0" ]; then |
|---|
| 104 | var="$single" |
|---|
| 105 | skip=1 |
|---|
| 106 | else |
|---|
| 107 | db_get "$var" || true |
|---|
| 108 | change_var "$single" "$RET" |
|---|
| 109 | fi |
|---|
| 110 | done |
|---|
| 111 | done |
|---|
| 112 | |
|---|
| 113 | # those variables could eventually be prompted for |
|---|
| 114 | echo "The following variables have been left untouched in alternc.conf" |
|---|
| 115 | echo "You will have to review those before manually launching alternc.install" |
|---|
| 116 | |
|---|
| 117 | cat <<EOF |
|---|
| 118 | monitor_ip |
|---|
| 119 | bind_internal |
|---|
| 120 | dnsip |
|---|
| 121 | myrandom |
|---|
| 122 | mynetwork |
|---|
| 123 | EOF |
|---|
| 124 | |
|---|
| 125 | echo "checking for upgrades" |
|---|
| 126 | /usr/share/alternc/install/upgrade_check.sh $2 |
|---|
| 127 | |
|---|
| 128 | ;; |
|---|
| 129 | |
|---|
| 130 | abort-upgrade|abort-remove|abort-deconfigure) |
|---|
| 131 | |
|---|
| 132 | ;; |
|---|
| 133 | |
|---|
| 134 | *) |
|---|
| 135 | echo "postinst called with unknown argument \`$1'" >&2 |
|---|
| 136 | exit 1 |
|---|
| 137 | ;; |
|---|
| 138 | |
|---|
| 139 | esac |
|---|
| 140 | |
|---|
| 141 | # dh_installdeb will replace this with shell code automatically |
|---|
| 142 | # generated by other debhelper scripts. |
|---|
| 143 | |
|---|
| 144 | #DEBHELPER# |
|---|
| 145 | |
|---|
| 146 | exit 0 |
|---|