alternc-slave.postinst 6.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#!/bin/sh

set -e

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

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

update_var() {
11
12
13
14
    local question
    local var
    question="$1"
    var="$2"
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    db_get "$question"
    if [ ! -z "$RET" ]; then
        grep -Eq "^ *$var=" $CONFIGFILE || echo "$var=" >> $CONFIGFILE
        SED_SCRIPT="$SED_SCRIPT;s\\^ *$var=.*\\$var=\"$RET\"\\"
    fi
}

# 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)

43
44
45
    # ajoute l'user postfix au groupe sasl
    adduser --quiet postfix sasl

46
47
48
49
    # 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

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    # build local.sh if it does not exist
    if [ ! -f $CONFIGFILE ]; then
        cat > $CONFIGFILE <<EOF
#!/bin/sh
#
# 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=""

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

87
88
89
90
91
92
# quels clients mysql sont permis (%, localhost, etc)
MYSQL_CLIENT=""

# Folder holding data (used for quota management)
ALTERNC_LOC=""

93
94
95
96
97
98
# 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=""
99
100
101
102
103
104
105
106
107
108
109
110
111
112
EOF

        chown root:www-data $CONFIGFILE
        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=""
Antoine Beaupré's avatar
Antoine Beaupré committed
113
114
115
116
117
118
119
120
121
122
123
124
    update_var alternc-slave/hostingname HOSTING
    update_var alternc-slave/desktopname FQDN 
    update_var alternc-slave/public_ip PUBLIC_IP
    update_var alternc-slave/internal_ip INTERNAL_IP
    update_var alternc-slave/monitor_ip MONITOR_IP
    update_var alternc-slave/ns1 NS1_HOSTNAME
    update_var alternc-slave/ns2 NS2_HOSTNAME
    update_var alternc-slave/default_mx DEFAULT_MX 
    update_var alternc-slave/mysql/client MYSQL_CLIENT 
    update_var alternc-slave/sql/backup_type SQLBACKUP_TYPE
    update_var alternc-slave/sql/backup_overwrite SQLBACKUP_OVERWRITE
    update_var alternc-slave/alternc_location ALTERNC_LOC
125
126
127
    sed -e "$SED_SCRIPT" < $CONFIGFILE > $CONFIGFILE.tmp
    mv -f $CONFIGFILE.tmp $CONFIGFILE

128
    # Setup grants
Antoine Beaupré's avatar
Antoine Beaupré committed
129
    db_get "alternc-slave/mysql/host"
130
131
132
133
    MYSQL_HOST="$RET"
    if [ "$MYSQL_HOST" != "localhost" -o -e /usr/sbin/mysqld ]; then
        # compatibility shims with my.cnf
        host="$RET"
Antoine Beaupré's avatar
Antoine Beaupré committed
134
        db_get "alternc-slave/mysql/db"
135
        database="$RET"
Antoine Beaupré's avatar
Antoine Beaupré committed
136
        db_get "alternc-slave/mysql/user"
137
        user="$RET"
Antoine Beaupré's avatar
Antoine Beaupré committed
138
        db_get "alternc-slave/mysql/password"
139
140
141
142
143
144
        password="$RET"
        
        # we source (instead of forking) mysql.sh so that it gets the local environment above
        . /usr/share/alternc/install/mysql.sh
    fi

145
    # forget the password
Antoine Beaupré's avatar
Antoine Beaupré committed
146
147
    db_reset alternc-slave/mysql/password || true
    db_fset alternc-slave/mysql/password "seen" "false" || true
148
149
150
151
152
153

    if [ -e $CONFIGFILE ]; then
      # source local.sh variables
      . $CONFIGFILE
    fi

154
155
156
157
    if grep -q alternc-mergelog /etc/passwd ; then
        echo "Reusing the alternc-mergelog account as a generic alternc account"
        # the uid is ugly. we should request allocation from
        # base-passwd instead
Antoine Beaupré's avatar
Antoine Beaupré committed
158
        usermod --uid 342 --shell /bin/rbash --login alternc alternc-mergelog
159
160
        # this is a separate step otherwise usermod will look for
        # files to chown in /var/alternc, which takes a long time
161
        usermod --home $ALTERNC_LOC alternc
162
163
164
165
166
167
168
169
170
    fi
    if [ -d /var/run/alternc-mergelog/.ssh ]; then
        echo "Cleaning up old alternc-mergelog home"
        mv /var/run/alternc-mergelog/.ssh $ALTERNC_LOC/.ssh && rmdir /var/run/alternc-mergelog
    fi
    if ! grep -q alternc /etc/passwd ; then
        echo "Creating alternc account"
        # this uid is ugly. we should request allocation from
        # base-password instead
Antoine Beaupré's avatar
Antoine Beaupré committed
171
        adduser --quiet --system --uid 342 --home $ALTERNC_LOC --shell /bin/rbash --ingroup adm alternc
172
173
    fi

174
    echo "config phpmyadmin"
175
    include_str='include("/etc/alternc/phpmyadmin.inc.php")'
176
177
178
179
180
    pma_config=/etc/phpmyadmin/config.inc.php
    if ! grep -e "$include_str" $pma_config > /dev/null 2>&1; then
        echo "<?php $include_str ?>" >> $pma_config
    fi

181
182
183
184
185
186
187
188
189
190
191
192
193
    if ! grep -q '## ALTERNC START' /etc/sudoers; then
        # XXX: this is not proper locking
        if [ -e /etc/sudoers.tmp ]; then
            echo "sudoers file being edited, aborting"
            exit 1
        else
            cp /etc/sudoers /etc/sudoers.tmp
            cat >> /etc/sudoers.tmp <<EOF
## ALTERNC START
## do not change anything between those lines
alternc ALL=NOPASSWD: /usr/sbin/invoke-rc.d apache reload
alternc ALL=NOPASSWD: /usr/sbin/invoke-rc.d apache2 reload
alternc ALL=NOPASSWD: /usr/sbin/rndc reload *
194
alternc ALL=NOPASSWD: /usr/sbin/rndc reload
195
196
197
198
199
200
## ALTERNC END
EOF
            mv /etc/sudoers.tmp /etc/sudoers
        fi
    fi

201
202
203
204
    # important: postinst gele sans ca
    db_stop

    echo "running alternc.install"
205
    alternc.install -s
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
    ;;

    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#

exit 0

# vim: et sw=4