alternc.postinst 9.48 KB
Newer Older
1
#!/bin/bash -e
2 3 4 5 6 7 8

# Source debconf library.
. /usr/share/debconf/confmodule

CONFIGFILE="/etc/alternc/local.sh"

update_var() {
9 10 11 12
    local question
    local var
    question="$1"
    var="$2"
13
    db_get "$question"
14 15 16

    grep -Eq "^ *$var=" $CONFIGFILE || echo "$var=" >> $CONFIGFILE
    SED_SCRIPT="$SED_SCRIPT;s\\^ *$var=.*\\$var=\"$RET\"\\"
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
}

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

case "$1" in
  configure)

40 41 42
    # ajoute l'user postfix au groupe sasl
    adduser --quiet postfix sasl

43 44 45 46
    # corriger les permissions du chroot
    mkdir -p /var/spool/postfix/var/run/saslauthd || true
    dpkg-statoverride --quiet --update --add root sasl 710 /var/spool/postfix/var/run/saslauthd  || true

47

48
    db_get "alternc/alternc_mail"
49
    VMAIL_HOME="$RET"
50 51 52 53
    if ! getent group vmail; then
       addgroup --gid 1998 vmail
    fi
    if ! getent passwd vmail; then
54
       useradd -g vmail -u 1998 vmail -d "$VMAIL_HOME" -m 
55
    fi 
56 57
    test -d "$VMAIL_HOME" || mkdir -p "$VMAIL_HOME"
    chown vmail:vmail "$VMAIL_HOME" 
58
    chown vmail:vmail "$VMAIL_HOME"/* 2>/dev/null || true # It may be empty
59
    chmod u+rxw "$VMAIL_HOME" 
60
    chmod u+rxw "$VMAIL_HOME"/* 2>/dev/null || true # It may be empty
61
    chmod g+rxw "$VMAIL_HOME" 
62
    chmod g+rxw "$VMAIL_HOME"/* 2>/dev/null || true # It may be empty
63

alban's avatar
alban committed
64
    chown alterncpanel:alterncpanel "/var/lib/alternc/panel"
65

66 67 68
    # build local.sh if it does not exist
    if [ ! -f $CONFIGFILE ]; then
        cat > $CONFIGFILE <<EOF
Alan Garcia's avatar
Alan Garcia committed
69
#!/bin/bash
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#
# AlternC - Web Hosting System - Configuration
# This file will be modified on package configuration
# (e.g. upgrade or dpkg-reconfigure alternc)

# Hosting service name
HOSTING=""

# Primary hostname for this box (will be used to access the management panel)
FQDN=""

# Public IP
PUBLIC_IP=""

# Internal IP
# (most of the time, should be equal to PUBLIC_IP, unless you are behind
# firewall doing address translation)
INTERNAL_IP=""

# Monitoring IP or network (will be allowed to access Apache status)
MONITOR_IP=""

# Primary DNS hostname
NS1_HOSTNAME=""

# Secondary DNS hostname
NS2_HOSTNAME=""

# Mail server hostname
DEFAULT_MX=""

101 102 103
# Secondary mail server hostname
DEFAULT_SECONDARY_MX=""

104 105
# Note: MySQL username/password configuration now stored in /etc/alternc/my.cnf

106 107 108
# quels clients mysql sont permis (%, localhost, etc)
MYSQL_CLIENT=""

109 110 111 112 113 114
# the type of backup created by the sql backup script
# valid options are "rotate" (newsyslog-style) or "date" (suffix is the date)
SQLBACKUP_TYPE=""

# overwrite existing files when backing up
SQLBACKUP_OVERWRITE=""
115 116 117

# known slave servers, empty for none, localhost is special (no ssh)
ALTERNC_SLAVES=""
118 119 120

# File to look at for forced launch of update_domain (use incron)
INOTIFY_UPDATE_DOMAIN="/var/run/alternc/inotify_update_domain.lock"
121

122
# File to look at for forced launch of do_actions (use incron)
123
INOTIFY_DO_ACTION="/var/run/alternc/inotify_do_action.lock"
124

125 126 127 128 129
# AlternC Locations
ALTERNC_HTML=""
ALTERNC_MAIL=""
ALTERNC_LOGS=""

130 131 132 133 134
# Custom directory for archived logs. ALTERNC_LOGS is used by default to view logs files on the panel.
# But you may merge your logs in other directory. In order to view them,
# Uncomment and complete the following variable to use it instead of ALTERNC_LOGS.
#ALTERNC_LOGS_ARCHIVE=""
 
135 136
EOF

Alan Garcia's avatar
Alan Garcia committed
137
        chown root:alterncpanel $CONFIGFILE
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
        chmod 640 $CONFIGFILE
    fi

    # Update local.sh
    # 1. use cp to keep permissions
    # 2. add missing variable to local.sh
    # 3. use sed to set variables with current values
    echo "Updating $CONFIGFILE"
    cp -a -f $CONFIGFILE $CONFIGFILE.tmp
    # SED_SCRIPT will be modified by update_var
    SED_SCRIPT=""
    update_var alternc/hostingname HOSTING
    update_var alternc/desktopname FQDN 
    update_var alternc/public_ip PUBLIC_IP
    update_var alternc/internal_ip INTERNAL_IP
    update_var alternc/monitor_ip MONITOR_IP
    update_var alternc/ns1 NS1_HOSTNAME
    update_var alternc/ns2 NS2_HOSTNAME
    update_var alternc/default_mx DEFAULT_MX 
157
    update_var alternc/default_mx2 DEFAULT_SECONDARY_MX
158
    update_var alternc/mysql/client MYSQL_CLIENT 
159 160
    update_var alternc/sql/backup_type SQLBACKUP_TYPE
    update_var alternc/sql/backup_overwrite SQLBACKUP_OVERWRITE
161
    update_var alternc/slaves ALTERNC_SLAVES
162 163 164
    update_var alternc/alternc_html ALTERNC_HTML
    update_var alternc/alternc_mail ALTERNC_MAIL
    update_var alternc/alternc_logs ALTERNC_LOGS
165 166 167
    sed -e "$SED_SCRIPT" < $CONFIGFILE > $CONFIGFILE.tmp
    mv -f $CONFIGFILE.tmp $CONFIGFILE

168 169 170
    # Erase all apacheconf file
    # They will be regenerated without the bug by upgrade_check.sh below.
    if dpkg --compare-versions "$2" le "0.9.3.9-globenet14"; then
171
        rm -f /var/alternc/apacheconf/*/*  # Old AlternC version
172 173
    fi

174 175 176
    # we store the version where we upgrade from, for AlternC < 3.1.1 || < 3.2.1
    # where we switch to database-based version control
    echo "$2" >/var/lib/alternc/backups/lastversion
177

178 179 180 181 182 183 184 185 186 187 188 189
    # Setup grants
    db_get "alternc/mysql/host"
    MYSQL_HOST="$RET"
    if [ "$MYSQL_HOST" != "localhost" -o -e /usr/sbin/mysqld ]; then
        # compatibility shims with my.cnf
        host="$RET"
        db_get "alternc/mysql/db"
        database="$RET"
        db_get "alternc/mysql/user"
        user="$RET"
        db_get "alternc/mysql/password"
        password="$RET"
190 191 192 193 194
        db_get "alternc/mysql/alternc_mail_user"
        alternc_mail_user="$RET"
        db_get "alternc/mysql/alternc_mail_password"
        alternc_mail_password="$RET"

195 196 197 198
        # we source (instead of forking) mysql.sh so that it gets the local environment above
        . /usr/share/alternc/install/mysql.sh
    fi

199 200 201 202 203
    if [ -e $CONFIGFILE ]; then
      # source local.sh variables
      . $CONFIGFILE
    fi

204 205 206
    # multi-server configuration: we create an alternc account with
    # authorized keys. since this is the master, we do not give him a
    # valid shell, but we still need the user for proper perms
207
    ALTERNC_USER_HOME="$ALTERNC_HTML"
208
    if [ ! -z "$ALTERNC_SLAVES" ] && [ "$ALTERNC_SLAVES" != "localhost" ] ; then
209 210
        if ! grep -q alternc /etc/passwd ; then
            echo "Creating alternc account"
211
            adduser --quiet --system --uid 342 --home $ALTERNC_HTML --shell /bin/false --ingroup adm alternc
212
        fi
213
        chown alternc "$ALTERNC_USER_HOME"
214 215
        if [ -r ~root/.ssh/id_dsa.pub ]; then
            key=`cat ~root/.ssh/id_dsa.pub`
216
            if ! grep -q "$key" $ALTERNC_USER_HOME/.ssh/authorized_keys ; then
217
                echo "Authorizing root ssh key to access the common alternc account"
218 219 220 221
                mkdir -p $ALTERNC_USER_HOME/.ssh
                echo "$key" >> $ALTERNC_USER_HOME/.ssh/authorized_keys
                chown -R alternc:adm $ALTERNC_USER_HOME/.ssh
                chmod -R og-rwx $ALTERNC_USER_HOME/.ssh
222 223 224 225
            fi
        else
            echo "No SSH key in "~root/.ssh/id_dsa.pub
            echo "create one and reconfigure alternc to propagate SSH keys"
226
        fi
227 228
    else
        echo "AlternC slaves not configured ($ALTERNC_SLAVES)"
229 230
    fi

231 232 233 234 235 236 237
    # /var/alternc/dns/d/www.example.com
    FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
    if [ "$FQDN_LETTER" = "$FQDN" ]
    then
           FQDN_LETTER="_"
    fi

238
    #clean old access to the management panel
239 240
    # We don't use this anymore : (FIXME : shall we remove /var/alternc/dns while upgrading ?)
    #find /var/alternc/dns/ -type l -lname /var/alternc/bureau -exec rm {} \;
241

242
    # Bind stuff
243 244 245
    touch           /var/lib/alternc/bind/automatic.conf /var/lib/alternc/bind/slaveip.conf
    chown root:bind /var/lib/alternc/bind/automatic.conf /var/lib/alternc/bind/slaveip.conf
    chmod 640       /var/lib/alternc/bind/automatic.conf /var/lib/alternc/bind/slaveip.conf
246
    mkdir -p /var/run/alternc && chown alterncpanel:alterncpanel /var/run/alternc
247 248 249
    touch /var/run/alternc/refresh_slave
    /usr/lib/alternc/slave_dns
    # Apache will not start without this file
250
    touch /var/lib/alternc/apache-vhost/vhosts_all.conf
251

252
    # important: postinst freezes without that:
253 254
    db_stop

255
    echo -e "\033[31m**********************************************"
Alan Garcia's avatar
Alan Garcia committed
256
    echo "*                                            *"
257
    echo "*   ALTERNC          ACTION REQUESTED        *"
Alan Garcia's avatar
Alan Garcia committed
258
    echo "*                                            *"
259
    echo "* Please run alternc.install to fully deploy *"
Alan Garcia's avatar
Alan Garcia committed
260
    echo "*                                            *"
261
    echo "**********************************************"
262
    echo -e "\033[0m"
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;

esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

281 282 283
# important: postrm freezes withtout that:
db_stop

284 285 286
exit 0

# vim: et sw=4