| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | set -e |
|---|
| 4 | |
|---|
| 5 | # Source debconf library. |
|---|
| 6 | . /usr/share/debconf/confmodule |
|---|
| 7 | |
|---|
| 8 | CONFIGFILE="/etc/alternc/local.sh" |
|---|
| 9 | |
|---|
| 10 | update_var() { |
|---|
| 11 | local question |
|---|
| 12 | local var |
|---|
| 13 | question="$1" |
|---|
| 14 | var="$2" |
|---|
| 15 | db_get "$question" |
|---|
| 16 | if [ ! -z "$RET" ]; then |
|---|
| 17 | grep -Eq "^ *$var=" $CONFIGFILE || echo "$var=" >> $CONFIGFILE |
|---|
| 18 | SED_SCRIPT="$SED_SCRIPT;s\\^ *$var=.*\\$var=\"$RET\"\\" |
|---|
| 19 | fi |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | # summary of how this script can be called: |
|---|
| 23 | # * <postinst> `configure' <most-recently-configured-version> |
|---|
| 24 | # * <old-postinst> `abort-upgrade' <new version> |
|---|
| 25 | # * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
|---|
| 26 | # <new-version> |
|---|
| 27 | # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
|---|
| 28 | # <failed-install-package> <version> `removing' |
|---|
| 29 | # <conflicting-package> <version> |
|---|
| 30 | # for details, see http://www.debian.org/doc/debian-policy/ or |
|---|
| 31 | # the debian-policy package |
|---|
| 32 | # |
|---|
| 33 | # quoting from the policy: |
|---|
| 34 | # Any necessary prompting should almost always be confined to the |
|---|
| 35 | # post-installation script, and should be protected with a conditional |
|---|
| 36 | # so that unnecessary prompting doesn't happen if a package's |
|---|
| 37 | # installation fails and the `postinst' is called with `abort-upgrade', |
|---|
| 38 | # `abort-remove' or `abort-deconfigure'. |
|---|
| 39 | |
|---|
| 40 | case "$1" in |
|---|
| 41 | configure) |
|---|
| 42 | |
|---|
| 43 | # ajoute l'user postfix au groupe sasl |
|---|
| 44 | adduser --quiet postfix sasl |
|---|
| 45 | |
|---|
| 46 | # corriger les permissions du chroot |
|---|
| 47 | mkdir -p /var/spool/postfix/var/run/saslauthd || true |
|---|
| 48 | dpkg-statoverride --quiet --update --add root sasl 710 /var/spool/postfix/var/run/saslauthd || true |
|---|
| 49 | |
|---|
| 50 | # build local.sh if it does not exist |
|---|
| 51 | if [ ! -f $CONFIGFILE ]; then |
|---|
| 52 | cat > $CONFIGFILE <<EOF |
|---|
| 53 | #!/bin/sh |
|---|
| 54 | # |
|---|
| 55 | # AlternC - Web Hosting System - Configuration |
|---|
| 56 | # This file will be modified on package configuration |
|---|
| 57 | # (e.g. upgrade or dpkg-reconfigure alternc) |
|---|
| 58 | |
|---|
| 59 | # Hosting service name |
|---|
| 60 | HOSTING="" |
|---|
| 61 | |
|---|
| 62 | # Primary hostname for this box (will be used to access the management panel) |
|---|
| 63 | FQDN="" |
|---|
| 64 | |
|---|
| 65 | # Public IP |
|---|
| 66 | PUBLIC_IP="" |
|---|
| 67 | |
|---|
| 68 | # Internal IP |
|---|
| 69 | # (most of the time, should be equal to PUBLIC_IP, unless you are behind |
|---|
| 70 | # firewall doing address translation) |
|---|
| 71 | INTERNAL_IP="" |
|---|
| 72 | |
|---|
| 73 | # Monitoring IP or network (will be allowed to access Apache status) |
|---|
| 74 | MONITOR_IP="" |
|---|
| 75 | |
|---|
| 76 | # Primary DNS hostname |
|---|
| 77 | NS1_HOSTNAME="" |
|---|
| 78 | |
|---|
| 79 | # Secondary DNS hostname |
|---|
| 80 | NS2_HOSTNAME="" |
|---|
| 81 | |
|---|
| 82 | # Mail server hostname |
|---|
| 83 | DEFAULT_MX="" |
|---|
| 84 | |
|---|
| 85 | # Note: MySQL username/password configuration now stored in /etc/alternc/my.cnf |
|---|
| 86 | |
|---|
| 87 | # quels clients mysql sont permis (%, localhost, etc) |
|---|
| 88 | MYSQL_CLIENT="" |
|---|
| 89 | |
|---|
| 90 | # Folder holding data (used for quota management) |
|---|
| 91 | ALTERNC_LOC="" |
|---|
| 92 | |
|---|
| 93 | # the type of backup created by the sql backup script |
|---|
| 94 | # valid options are "rotate" (newsyslog-style) or "date" (suffix is the date) |
|---|
| 95 | SQLBACKUP_TYPE="" |
|---|
| 96 | |
|---|
| 97 | # overwrite existing files when backing up |
|---|
| 98 | SQLBACKUP_OVERWRITE="" |
|---|
| 99 | EOF |
|---|
| 100 | |
|---|
| 101 | chown root:www-data $CONFIGFILE |
|---|
| 102 | chmod 640 $CONFIGFILE |
|---|
| 103 | fi |
|---|
| 104 | |
|---|
| 105 | # Update local.sh |
|---|
| 106 | # 1. use cp to keep permissions |
|---|
| 107 | # 2. add missing variable to local.sh |
|---|
| 108 | # 3. use sed to set variables with current values |
|---|
| 109 | echo "Updating $CONFIGFILE" |
|---|
| 110 | cp -a -f $CONFIGFILE $CONFIGFILE.tmp |
|---|
| 111 | # SED_SCRIPT will be modified by update_var |
|---|
| 112 | SED_SCRIPT="" |
|---|
| 113 | update_var alternc/hostingname HOSTING |
|---|
| 114 | update_var alternc/desktopname FQDN |
|---|
| 115 | update_var alternc/public_ip PUBLIC_IP |
|---|
| 116 | update_var alternc/internal_ip INTERNAL_IP |
|---|
| 117 | update_var alternc/monitor_ip MONITOR_IP |
|---|
| 118 | update_var alternc/ns1 NS1_HOSTNAME |
|---|
| 119 | update_var alternc/ns2 NS2_HOSTNAME |
|---|
| 120 | update_var alternc/default_mx DEFAULT_MX |
|---|
| 121 | update_var alternc/mysql/client MYSQL_CLIENT |
|---|
| 122 | update_var alternc/sql/backup_type SQLBACKUP_TYPE |
|---|
| 123 | update_var alternc/sql/backup_overwrite SQLBACKUP_OVERWRITE |
|---|
| 124 | update_var alternc/alternc_location ALTERNC_LOC |
|---|
| 125 | sed -e "$SED_SCRIPT" < $CONFIGFILE > $CONFIGFILE.tmp |
|---|
| 126 | mv -f $CONFIGFILE.tmp $CONFIGFILE |
|---|
| 127 | |
|---|
| 128 | # Setup grants |
|---|
| 129 | db_get "alternc/mysql/host" |
|---|
| 130 | MYSQL_HOST="$RET" |
|---|
| 131 | if [ "$MYSQL_HOST" != "localhost" -o -e /usr/sbin/mysqld ]; then |
|---|
| 132 | # compatibility shims with my.cnf |
|---|
| 133 | host="$RET" |
|---|
| 134 | db_get "alternc/mysql/db" |
|---|
| 135 | database="$RET" |
|---|
| 136 | db_get "alternc/mysql/user" |
|---|
| 137 | user="$RET" |
|---|
| 138 | db_get "alternc/mysql/password" |
|---|
| 139 | password="$RET" |
|---|
| 140 | |
|---|
| 141 | # we source (instead of forking) mysql.sh so that it gets the local environment above |
|---|
| 142 | . /usr/share/alternc/install/mysql.sh |
|---|
| 143 | fi |
|---|
| 144 | |
|---|
| 145 | # forget the password |
|---|
| 146 | db_reset alternc/mysql/password || true |
|---|
| 147 | db_fset alternc/mysql/password "seen" "false" || true |
|---|
| 148 | |
|---|
| 149 | if [ -e $CONFIGFILE ]; then |
|---|
| 150 | # source local.sh variables |
|---|
| 151 | . $CONFIGFILE |
|---|
| 152 | fi |
|---|
| 153 | |
|---|
| 154 | # /var/alternc/dns/d/www.example.com |
|---|
| 155 | FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`" |
|---|
| 156 | if [ "$FQDN_LETTER" = "$FQDN" ] |
|---|
| 157 | then |
|---|
| 158 | FQDN_LETTER="_" |
|---|
| 159 | fi |
|---|
| 160 | |
|---|
| 161 | # Erase all apacheconf file |
|---|
| 162 | # They will be regenerated without the bug by upgrade_check.sh below. |
|---|
| 163 | if dpkg --compare-versions "$2" le "0.9.3.9-globenet14"; then |
|---|
| 164 | rm -f /var/alternc/apacheconf/*/* |
|---|
| 165 | rm -f /var/alternc/apacheconf/override_php.conf |
|---|
| 166 | fi |
|---|
| 167 | |
|---|
| 168 | echo "checking for upgrades" |
|---|
| 169 | /usr/share/alternc/install/upgrade_check.sh $2 |
|---|
| 170 | |
|---|
| 171 | echo "config phpmyadmin" |
|---|
| 172 | include_str='include("/etc/alternc/phpmyadmin.inc.php")' |
|---|
| 173 | pma_config=/etc/phpmyadmin/config.inc.php |
|---|
| 174 | if ! grep -e "$include_str" $pma_config > /dev/null 2>&1; then |
|---|
| 175 | echo "<?php $include_str ?>" >> $pma_config |
|---|
| 176 | fi |
|---|
| 177 | |
|---|
| 178 | # Add access to the management panel |
|---|
| 179 | ln -nsf /var/alternc/bureau /var/alternc/dns/$FQDN_LETTER/$FQDN |
|---|
| 180 | |
|---|
| 181 | # Bind stuff |
|---|
| 182 | touch /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf |
|---|
| 183 | chown root:bind /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf |
|---|
| 184 | chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf |
|---|
| 185 | touch /var/run/alternc/refresh_slave |
|---|
| 186 | /usr/lib/alternc/slave_dns |
|---|
| 187 | # Apache will not start without this file |
|---|
| 188 | touch /var/alternc/apacheconf/override_php.conf |
|---|
| 189 | |
|---|
| 190 | # Update l18n files |
|---|
| 191 | /usr/share/alternc/install/dopo.sh |
|---|
| 192 | |
|---|
| 193 | # important: postinst gele sans ca |
|---|
| 194 | db_stop |
|---|
| 195 | |
|---|
| 196 | echo "running alternc.install" |
|---|
| 197 | alternc.install |
|---|
| 198 | |
|---|
| 199 | # Add basedir protection |
|---|
| 200 | /usr/lib/alternc/basedir_prot.sh |
|---|
| 201 | |
|---|
| 202 | if [ -x /usr/sbin/apache ]; then |
|---|
| 203 | if [ ! -h /etc/apache-ssl/conf.d/alternc.conf ]; then |
|---|
| 204 | ln -sf /etc/alternc/apache-ssl.conf \ |
|---|
| 205 | /etc/apache-ssl/conf.d/alternc.conf |
|---|
| 206 | fi |
|---|
| 207 | |
|---|
| 208 | if [ ! -h /etc/apache/conf.d/alternc.conf ]; then |
|---|
| 209 | ln -sf /etc/alternc/apache.conf \ |
|---|
| 210 | /etc/apache/conf.d/alternc.conf |
|---|
| 211 | fi |
|---|
| 212 | |
|---|
| 213 | if [ ! -h /etc/apache/conf.d/override_php.conf ]; then |
|---|
| 214 | ln -sf /var/alternc/apacheconf/override_php.conf \ |
|---|
| 215 | /etc/apache/conf.d/override_php.conf |
|---|
| 216 | fi |
|---|
| 217 | fi |
|---|
| 218 | if [ -x /usr/sbin/apache2 ]; then |
|---|
| 219 | if [ ! -h /etc/apache2/conf.d/alternc.conf ]; then |
|---|
| 220 | ln -sf /etc/alternc/apache.conf \ |
|---|
| 221 | /etc/apache/conf.d/alternc.conf |
|---|
| 222 | fi |
|---|
| 223 | if [ ! -h /etc/apache2/conf.d/override_php.conf ]; then |
|---|
| 224 | ln -sf /var/alternc/apacheconf/override_php.conf \ |
|---|
| 225 | /etc/apache/conf.d/override_php.conf |
|---|
| 226 | fi |
|---|
| 227 | |
|---|
| 228 | fi |
|---|
| 229 | ;; |
|---|
| 230 | |
|---|
| 231 | abort-upgrade|abort-remove|abort-deconfigure) |
|---|
| 232 | |
|---|
| 233 | ;; |
|---|
| 234 | |
|---|
| 235 | *) |
|---|
| 236 | echo "postinst called with unknown argument \`$1'" >&2 |
|---|
| 237 | exit 1 |
|---|
| 238 | ;; |
|---|
| 239 | |
|---|
| 240 | esac |
|---|
| 241 | |
|---|
| 242 | # dh_installdeb will replace this with shell code automatically |
|---|
| 243 | # generated by other debhelper scripts. |
|---|
| 244 | |
|---|
| 245 | #DEBHELPER# |
|---|
| 246 | |
|---|
| 247 | exit 0 |
|---|
| 248 | |
|---|
| 249 | # vim: et sw=4 |
|---|