source: alternc/trunk/debian/alternc.postinst @ 3200

Revision 3200, 9.6 KB checked in by squidly, 10 months ago (diff)

Bugfixes postinst script

Line 
1#!/bin/sh
2
3set -e
4
5# Source debconf library.
6. /usr/share/debconf/confmodule
7
8CONFIGFILE="/etc/alternc/local.sh"
9
10update_var() {
11    local question
12    local var
13    question="$1"
14    var="$2"
15    db_get "$question"
16
17    grep -Eq "^ *$var=" $CONFIGFILE || echo "$var=" >> $CONFIGFILE
18    SED_SCRIPT="$SED_SCRIPT;s\\^ *$var=.*\\$var=\"$RET\"\\"
19}
20
21# summary of how this script can be called:
22#        * <postinst> `configure' <most-recently-configured-version>
23#        * <old-postinst> `abort-upgrade' <new version>
24#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
25#          <new-version>
26#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
27#          <failed-install-package> <version> `removing'
28#          <conflicting-package> <version>
29# for details, see http://www.debian.org/doc/debian-policy/ or
30# the debian-policy package
31#
32# quoting from the policy:
33#     Any necessary prompting should almost always be confined to the
34#     post-installation script, and should be protected with a conditional
35#     so that unnecessary prompting doesn't happen if a package's
36#     installation fails and the `postinst' is called with `abort-upgrade',
37#     `abort-remove' or `abort-deconfigure'.
38
39case "$1" in
40  configure)
41
42    # ajoute l'user postfix au groupe sasl
43    adduser --quiet postfix sasl
44
45    # corriger les permissions du chroot
46    mkdir -p /var/spool/postfix/var/run/saslauthd || true
47    dpkg-statoverride --quiet --update --add root sasl 710 /var/spool/postfix/var/run/saslauthd  || true
48
49
50    db_get "alternc/alternc_location"
51    VMAIL_HOME="$RET"
52    #Create Dovecot user for mail handling FIXME change home with ALTERNC_LOC
53    if ! getent group vmail; then
54       addgroup --gid 1998 vmail
55    fi
56    if ! getent passwd vmail; then
57       useradd -g vmail -u 1998 vmail -d $VMAIL_HOME/mail -m
58    fi
59    chown -R vmail:vmail $VMAIL_HOME/mail
60    chmod u+w $VMAIL_HOME/mail
61    chmod -R g+w $VMAIL_HOME/mail
62
63    # build local.sh if it does not exist
64    if [ ! -f $CONFIGFILE ]; then
65        cat > $CONFIGFILE <<EOF
66#!/bin/sh
67#
68# AlternC - Web Hosting System - Configuration
69# This file will be modified on package configuration
70# (e.g. upgrade or dpkg-reconfigure alternc)
71
72# Hosting service name
73HOSTING=""
74
75# Primary hostname for this box (will be used to access the management panel)
76FQDN=""
77
78# Public IP
79PUBLIC_IP=""
80
81# Internal IP
82# (most of the time, should be equal to PUBLIC_IP, unless you are behind
83# firewall doing address translation)
84INTERNAL_IP=""
85
86# Monitoring IP or network (will be allowed to access Apache status)
87MONITOR_IP=""
88
89# Primary DNS hostname
90NS1_HOSTNAME=""
91
92# Secondary DNS hostname
93NS2_HOSTNAME=""
94
95# Mail server hostname
96DEFAULT_MX=""
97
98# Secondary mail server hostname
99DEFAULT_SECONDARY_MX=""
100
101# Note: MySQL username/password configuration now stored in /etc/alternc/my.cnf
102
103# quels clients mysql sont permis (%, localhost, etc)
104MYSQL_CLIENT=""
105
106# Folder holding data (used for quota management)
107ALTERNC_LOC=""
108
109# the type of backup created by the sql backup script
110# valid options are "rotate" (newsyslog-style) or "date" (suffix is the date)
111SQLBACKUP_TYPE=""
112
113# overwrite existing files when backing up
114SQLBACKUP_OVERWRITE=""
115
116# known slave servers, empty for none, localhost is special (no ssh)
117ALTERNC_SLAVES=""
118EOF
119
120        chown root:alterncpanel $CONFIGFILE
121        chmod 640 $CONFIGFILE
122    fi
123
124    # Update local.sh
125    # 1. use cp to keep permissions
126    # 2. add missing variable to local.sh
127    # 3. use sed to set variables with current values
128    echo "Updating $CONFIGFILE"
129    cp -a -f $CONFIGFILE $CONFIGFILE.tmp
130    # SED_SCRIPT will be modified by update_var
131    SED_SCRIPT=""
132    update_var alternc/hostingname HOSTING
133    update_var alternc/desktopname FQDN
134    update_var alternc/public_ip PUBLIC_IP
135    update_var alternc/internal_ip INTERNAL_IP
136    update_var alternc/monitor_ip MONITOR_IP
137    update_var alternc/ns1 NS1_HOSTNAME
138    update_var alternc/ns2 NS2_HOSTNAME
139    update_var alternc/default_mx DEFAULT_MX
140    update_var alternc/default_mx2 DEFAULT_SECONDARY_MX
141    update_var alternc/mysql/client MYSQL_CLIENT
142    update_var alternc/sql/backup_type SQLBACKUP_TYPE
143    update_var alternc/sql/backup_overwrite SQLBACKUP_OVERWRITE
144    update_var alternc/alternc_location ALTERNC_LOC
145    update_var alternc/slaves ALTERNC_SLAVES
146    sed -e "$SED_SCRIPT" < $CONFIGFILE > $CONFIGFILE.tmp
147    mv -f $CONFIGFILE.tmp $CONFIGFILE
148
149    # Setup grants
150    db_get "alternc/mysql/host"
151    MYSQL_HOST="$RET"
152    if [ "$MYSQL_HOST" != "localhost" -o -e /usr/sbin/mysqld ]; then
153        # compatibility shims with my.cnf
154        host="$RET"
155        db_get "alternc/mysql/db"
156        database="$RET"
157        db_get "alternc/mysql/user"
158        user="$RET"
159        db_get "alternc/mysql/password"
160        password="$RET"
161        db_get "alternc/mysql/alternc_mail_user"
162        alternc_mail_user="$RET"
163        db_get "alternc/mysql/alternc_mail_password"
164        alternc_mail_password="$RET"
165
166        # we source (instead of forking) mysql.sh so that it gets the local environment above
167        . /usr/share/alternc/install/mysql.sh
168    fi
169
170    if [ -e $CONFIGFILE ]; then
171      # source local.sh variables
172      . $CONFIGFILE
173    fi
174
175    # multi-server configuration: we create an alternc account with
176    # authorized keys. since this is the master, we do not give him a
177    # valid shell, but we still need the user for proper perms
178    if [ ! -z "$ALTERNC_SLAVES" ] && [ "$ALTERNC_SLAVES" != "localhost" ] ; then
179        if ! grep -q alternc /etc/passwd ; then
180            echo "Creating alternc account"
181            adduser --quiet --system --uid 342 --home $ALTERNC_LOC --shell /bin/false --ingroup adm alternc
182        fi
183        chown alternc /var/alternc
184        if [ -r ~root/.ssh/id_dsa.pub ]; then
185            key=`cat ~root/.ssh/id_dsa.pub`
186            if ! grep -q "$key" $ALTERNC_LOC/.ssh/authorized_keys ; then
187                echo "Authorizing root ssh key to access the common alternc account"
188                mkdir -p $ALTERNC_LOC/.ssh
189                echo "$key" >> $ALTERNC_LOC/.ssh/authorized_keys
190                chown -R alternc:adm $ALTERNC_LOC/.ssh
191                chmod -R og-rwx $ALTERNC_LOC/.ssh
192            fi
193        else
194            echo "No SSH key in "~root/.ssh/id_dsa.pub
195            echo "create one and reconfigure alternc to propagate SSH keys"
196        fi
197    else
198        echo "AlternC slaves not configured ($ALTERNC_SLAVES)"
199    fi
200
201    # /var/alternc/dns/d/www.example.com
202    FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
203    if [ "$FQDN_LETTER" = "$FQDN" ]
204    then
205           FQDN_LETTER="_"
206    fi
207
208    # Erase all apacheconf file
209    # They will be regenerated without the bug by upgrade_check.sh below.
210    if dpkg --compare-versions "$2" le "0.9.3.9-globenet14"; then
211        rm -f /var/alternc/apacheconf/*/*
212    fi
213
214    echo "checking for upgrades"
215    /usr/share/alternc/install/upgrade_check.sh $2
216
217    echo "config phpmyadmin"
218    # Mise à jour sur une configuration existante
219    # recherche la chaine include_str (avec les / echappées) et supprime les <?php ?>
220    # ${include_str//\//\\/}"'\) c'est uniquement BASH, on est en SH/DASH
221    include_str='include("/etc/alternc/phpmyadmin.inc.php")'
222    pma_config='/etc/phpmyadmin/config.inc.php'
223    bash -c "include_str='include(\"/etc/alternc/phpmyadmin.inc.php\")';pma_config='/etc/phpmyadmin/config.inc.php';sed 's/<?php \('\"\${include_str//\//\\/}\"'\) ?>/\1;/g' \$pma_config > \$pma_config'_2' && mv \$pma_config'_2' \$pma_config"
224
225    # Sur une configuration vierge, inclure la configuration alternc
226    if ! grep -e "$include_str" $pma_config > /dev/null 2>&1; then
227        echo "$include_str;" >> $pma_config
228    fi
229
230    #clean old access to the management panel
231    # We don't use this anymore : (FIXME : shall we remove /var/alternc/dns while upgrading ?)
232    #find /var/alternc/dns/ -type l -lname /var/alternc/bureau -exec rm {} \;
233
234    # Bind stuff
235    touch /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
236    chown root:bind /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
237    chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
238    touch /var/run/alternc/refresh_slave
239    /usr/lib/alternc/slave_dns
240    # Apache will not start without this file
241    touch /var/alternc/apache-vhost/vhosts_all.conf
242
243    # Update l18n files
244    /usr/share/alternc/install/dopo.sh
245
246          #squirrelmail fix             
247                chown -R :alterncpanel /var/lib/squirrelmail/data
248                chmod -R g+w /var/lib/squirrelmail
249                                #sudo stuff allowing alterncpanel to use quota
250                if [ -d /etc/sudoers.d ]; then
251                        cp /etc/alternc/alternc-sudoers /etc/sudoers.d/alternc-sudoers
252                        chmod 0440 /etc/sudoers.d/alternc-sudoers
253                else
254                        echo "running an older version of sudo"
255                        #FIXME
256                        echo "copy content of /usr/share/doc/examples/example.sudoers into /etc/sudoers.d for to run properly"
257         fi
258
259    # important: postinst gele sans ca
260    db_stop
261
262
263      echo "**********************************************"
264      echo "*                                            *"
265      echo "*                 ALTERNC                    *"
266      echo "*               ------------                 *"
267      echo "*                                            *"
268      echo "*                                            *"
269      echo "* Please run alternc.install to fully deploy *"
270      echo "*                                            *"
271      echo "**********************************************"
272
273
274
275    ;;
276
277    abort-upgrade|abort-remove|abort-deconfigure)
278
279    ;;
280
281    *)
282        echo "postinst called with unknown argument \`$1'" >&2
283        exit 1
284    ;;
285
286esac
287
288# dh_installdeb will replace this with shell code automatically
289# generated by other debhelper scripts.
290
291#DEBHELPER#
292
293exit 0
294
295# vim: et sw=4
Note: See TracBrowser for help on using the repository browser.