source: alternc/trunk/install/alternc.install @ 3142

Revision 3142, 13.6 KB checked in by squidly, 13 months ago (diff)

Mise à jour pour la génération du paquet alternc, pour tout ce qui est mail.

Gros changement : comme discuté sur la ML, alternc.install n'est plus lancé automatiquement lors de l'installation, l'utilisateur doit le lancer manuellement
pour finir l'installation.

Changements significatifs :

  • l'installation génére et applique les template dovecot et postfix
  • un utilisateur MySQL dédié est maintenant créé pour postfix et dovecot (mail_user).
  • ajout d'un utilisateur systeme pour dovecot pour le mail delivery
Line 
1#!/bin/sh
2#
3# AlternC Main install script.
4# This script should be launched only once, when installing AlternC
5# on a new server. THIS SCRIPT ERASE ALL DATA ON THE AlternC SYSTEM !!
6# YOU HAVE BEEN WARNED !
7
8# This script now assumes it has MySQL connectivity through
9# /etc/alternc/my.cnf
10
11set -e
12
13for i in $*; do
14    case "$i" in
15        -f|--force)
16            force=1; shift;;
17        -s|--slave)
18            slave=1; shift;;
19        --)
20            break;;
21        *)
22            echo "unknown option $i"; shift;;
23    esac
24done
25
26. /usr/lib/alternc/functions.sh
27
28#######################################################################
29# Script configuration
30#
31
32# Configuration template location
33TEMPLATE_DIR="/etc/alternc/templates"
34
35# Find needed configuration files (without the initial '/')
36# replace this one unconditionnally
37CONFIG_FILES="etc/alternc/bureau.conf"
38
39if [ -e /etc/bind/named.conf ]; then
40    CONFIG_FILES="$CONFIG_FILES etc/bind/templates/zone.template
41                  etc/bind/templates/named.template etc/bind/named.conf.options"
42fi
43if [ -d /etc/postfix ]; then
44    CONFIG_FILES="$CONFIG_FILES etc/postfix/myalias.cf etc/postfix/myrelay.cf
45                  etc/postfix/mydomain.cf etc/postfix/mygid.cf
46                  etc/postfix/myvirtual.cf etc/postfix/sasl/smtpd.conf"
47fi
48if [ -e /etc/proftpd/proftpd.conf ]; then
49    CONFIG_FILES="$CONFIG_FILES etc/proftpd/proftpd.conf etc/proftpd/welcome.msg etc/proftpd/modules.conf"
50fi
51if [ -e /etc/squirrelmail/apache.conf ]; then
52    CONFIG_FILES="$CONFIG_FILES etc/squirrelmail/apache.conf"
53fi
54
55if [ -e /etc/default/saslauthd ]; then
56    CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
57fi
58
59INSTALLED_CONFIG_TAR="/var/backups/alternc/etc-installed.tar.gz"
60
61#######################################################################
62# Look for modified configuration files
63#
64if [ -f "$INSTALLED_CONFIG_TAR" ]; then
65    CHANGED="`env LANG=C tar -zdf "$INSTALLED_CONFIG_TAR" -C / 2> /dev/null |
66              grep -v 'postfix/main.cf' | grep -v 'Uid differs'|grep -v 'Gid differs'  |grep -v 'Mode differs' |
67              sed -e 's/^\([^:]*\).*/    \1/' | sort -u`"
68    # " shutup emacs
69    if [ ! -z "$CHANGED" ]; then
70        echo "The following configuration files has changed since last AlternC"
71        echo "installation :"
72        echo "$CHANGED"
73        echo ""
74        if [ "$force" = "1" ]; then
75            echo "Replacing them as you requested."
76        else
77            echo "These configuration files should normally be modified by"
78            echo "changing the template in $TEMPLATE_DIR and then calling"
79            echo "$0 to perform the update."
80            echo ""
81            echo "Please examine the situation closely and call '$0 --force'"
82            echo "if you still want to actually overwrite these files."
83            exit 1
84        fi
85    fi
86fi
87
88#######################################################################
89# Prepare template expansions
90#
91
92. /etc/alternc/local.sh
93
94# Check ACL
95aclcheckfile="$ALTERNC_LOC/test-acl"
96touch "$aclcheckfile"
97setfacl -m u:root:rwx "$aclcheckfile" 2>/dev/null || ( echo "Error : ACL aren't activated on $ALTERNC_LOC . AlternC can't work without it." ; exit 2)
98
99# XXX: copy-paste from debian/config
100if [ -r /etc/alternc/my.cnf ]; then
101    # make mysql configuration available as shell variables
102    # to convert from .cnf to shell syntax, we:
103    # * match only lines with "equal" in them (/=/)
104    # * remove whitespace around the = and add a left quote operator ' (;s)
105    # * add a right quote operator at the end of line (;s)
106    # * convert mysql variables into our MYSQL_ naming convention (;s)
107    # * print the result (;p)
108    eval `sed -n -e "/=/{s/ *= *\"\?/='/;s/\"\?\$/'/;s/host/MYSQL_HOST/;s/user/MYSQL_USER/;s/password/MYSQL_PASS/;s/database/MYSQL_DATABASE/;p}" /etc/alternc/my.cnf`
109    chown root:alterncpanel /etc/alternc/my.cnf
110    chmod 640 /etc/alternc/my.cnf
111fi
112
113if [ -r /etc/alternc/my_mail.cnf ]; then
114    # make mysql configuration available as shell variables
115    # to convert from .cnf to shell syntax, we:
116    # * match only lines with "equal" in them (/=/)
117    # * remove whitespace around the = and add a left quote operator ' (;s)
118    # * add a right quote operator at the end of line (;s)
119    # * convert mysql variables into our MYSQL_ naming convention (;s)
120    # * print the result (;p)
121    eval `sed -n -e "/=/{s/ *= *\"\?/='/;s/\"\?\$/'/;s/host/MYSQL_HOST/;s/user/MYSQL_MAIL_USER/;s/password/MYSQL_MAIL_PASS/;s/database/MYSQL_DATABASE/;p}" /etc/alternc/my_mail.cnf`
122    chown root:alterncpanel /etc/alternc/my_mail.cnf
123    chmod 640 /etc/alternc/my_mail.cnf
124fi
125
126WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
127
128VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
129
130# /var/alternc/dns/d/www.example.com
131FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
132if [ "$FQDN_LETTER" = "$FQDN" ] 
133then
134       FQDN_LETTER="_" 
135fi
136
137NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
138                 @ip = unpack('C4', \\$h);
139                 print join (\".\", @ip);"`
140
141if [ -z "$MONITOR_IP" ]; then
142    MONITOR_IP="127.0.0.1"
143fi
144
145PUBLIC_IP_BEGIN=$(echo $PUBLIC_IP|cut -c 1)
146
147# XXX: I assume this is secure if /tmp is sticky (+t)
148# we should have a better way to deal with templating, of course.
149SED_SCRIPT=`mktemp`
150cat > $SED_SCRIPT <<EOF
151s\\%%hosting%%\\$HOSTING\\;
152s\\%%fqdn%%\\$FQDN\\;
153s\\%%public_ip%%\\$PUBLIC_IP\\;
154s\\%%public_ip_begin%%\\$PUBLIC_IP_BEGIN\\;
155s\\%%internal_ip%%\\$INTERNAL_IP\\;
156s\\%%monitor_ip%%\\$MONITOR_IP\\;
157s\\%%ns1%%\\$NS1_HOSTNAME\\;
158s\\%%ns2%%\\$NS2_HOSTNAME\\;
159s\\%%mx%%\\$DEFAULT_MX\\;
160s\\%%dbhost%%\\$MYSQL_HOST\\;
161s\\%%dbname%%\\$MYSQL_DATABASE\\;
162s\\%%dbuser%%\\$MYSQL_USER\\;
163s\\%%dbpwd%%\\$MYSQL_PASS\\;
164s\\%%db_mail_user%%\\$MYSQL_MAIL_USER\\;
165s\\%%db_mail_pwd%%\\$MYSQL_MAIL_PASS\\;
166s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
167s\\%%warning_message%%\\$WARNING\\;
168s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
169s\\%%version%%\\$VERSION\\;
170s\\%%ns2_ip%%\\$NS2_IP\\;
171EOF
172
173#######################################################################
174# Backup configuration files
175#
176BACKUP_FILE="/var/backups/alternc/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
177
178# Only backup what we are really going to replace
179BACKUPS=""
180for file in $CONFIG_FILES; do
181    TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
182    if [ -f "$TEMPLATE" ]; then
183        BACKUPS="$BACKUPS $file"
184    fi
185done
186
187# also backup main.cf since we're doing major changes to it
188BACKUPS="$BACKUPS etc/postfix/main.cf"
189tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
190
191#######################################################################
192# Expand templates in the right place
193#
194echo -n "Expanding variables in configuration files:"
195for file in $CONFIG_FILES; do
196    TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
197    echo -n " $file"
198    if [ -f "$TEMPLATE" ]; then
199        sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
200    fi
201done
202echo "."
203rm -f $SED_SCRIPT
204
205########################################################################
206# Ad-hoc fixes
207#
208
209php="`ls /usr/lib/apache*/*/*php*.so | sed -e 's/^.*libphp\(.\)\.so$/php\1/' | tail -1`"
210ln -fs /etc/alternc/alternc.ini /etc/$php/conf.d/alternc.ini || true
211if [ -x /usr/sbin/apache2 ]; then
212    s=""
213    if ! [ -L /etc/apache2/mods-enabled/vhost_alias.load ]
214    then
215        a2enmod vhost_alias
216        s="apache2"
217    fi
218    if ! [ -L /etc/apache2/mods-enabled/$php.load ]
219    then
220            a2enmod $php
221    fi
222    if ! [ -L /etc/apache2/mods-enabled/rewrite.load ]
223    then
224            a2enmod rewrite
225    fi
226    if [ -e /etc/alternc/apache.pem ]; then
227        # We enable proftpd tls module
228        cat /etc/proftpd/modules.conf | sed -e 's/^#LoadModule mod_tls.c/LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
229        mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
230        cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
231        # We enable apache2 SSL :
232        if [ ! -L /etc/apache2/mods-enabled/ssl.load ] ; then
233            a2enmod ssl
234            s="apache2"
235        fi
236        if [ ! -h /etc/apache2/conf.d/alternc-ssl.conf ] && [ -e /etc/apache2/conf.d/ ]; then
237            ln -sf /etc/alternc/apache2-ssl.conf /etc/apache2/conf.d/alternc-ssl.conf
238            s="apache2"
239        fi
240    else
241        # We disable proftpd tls module
242        cat /etc/proftpd/modules.conf | sed -e 's/^LoadModule mod_tls.c/#LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
243        mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
244        cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
245        echo "SSL not configured"
246        echo "create a certificate in /etc/alternc/apache.pem and rerun alternc.install"
247    fi
248    if [ ! -h /etc/apache2/conf.d/alternc.conf ] && [ -e /etc/apache2/conf.d/ ]; then
249        ln -sf /etc/alternc/apache2.conf /etc/apache2/conf.d/alternc.conf
250        s="apache2"
251    fi
252    if [ -e /etc/apache2/sites-enabled/000-default ]; then
253        a2dissite default
254        s="apache2"
255    fi
256    SERVICES="$SERVICES $s"
257fi
258
259# Copy postfix *_checks if they do not exist
260for file in body_checks header_checks; do
261    if [ ! -e "/etc/postfix/$file" ]; then
262        cp /usr/share/alternc/install/$file /etc/postfix
263    fi
264done
265
266# Attribute the correct rights to critical postfix files
267if [ -e /etc/postfix/myalias.cf -o -e /etc/postfix/mydomain.cf -o -e /etc/postfix/mygid.cf -o -e /etc/postfix/myvirtual.cf -o -e /etc/postfix/myrelay.cf ]; then
268    chown root:postfix /etc/postfix/my*
269    chmod 640 /etc/postfix/my*
270fi
271
272if [ ! -f /etc/postfix/main.cf ]
273then
274    echo "****************************************"
275    echo "POSTFIX is NOT configured properly"
276    echo "please launch dpkg-reconfigure -plow postfix" 
277    echo "and choose 'Internet Site'"
278    echo "then reinstall alternc"
279    echo "****************************************"
280    exit 1
281fi
282
283# configure Postfix appropriatly for our needs
284if [ "$slave" = "1" ]; then
285    postfix_conf=/etc/alternc/postfix-slave.cf
286else
287    postfix_conf=/etc/alternc/postfix.cf
288fi
289while read line ; do
290   postconf -e "$line"
291done < "$postfix_conf"
292
293# Conviguring delivery used bu Postfix FIXME change script name
294echo `/usr/bin/postfix-add-policy2 dovecot pipe DRhu vmail:vmail  '/usr/lib/dovecot/deliver -f ${sender} -d ${recipient} '`
295
296# Bug #1215: configure mydestination when $FQDN is not in
297OLDDESTINATION=`postconf mydestination | awk -F '=' '{print $2}'`
298echo "$OLDDESTINATION" | grep -q -v "$FQDN" && postconf -e "mydestination = $FQDN, $OLDDESTINATION"
299 
300if [ -e /etc/proftpd.conf ] ; then
301    chmod 640 /etc/proftpd/proftpd.conf
302fi
303
304if [ -x /usr/sbin/locale-gen ] ; then
305    touch /etc/locale.gen
306    LOCALECHANGED=""
307    # Add de_DE ISO-8859-1, en_US ISO-8859-1, es_ES ISO-8859-1, fr_FR ISO-8859-1 to the locales :
308    if ! grep -q "^de_DE ISO-8859-1$" /etc/locale.gen ; then
309        echo "de_DE ISO-8859-1" >>/etc/locale.gen
310        LOCALECHANGED=1
311    fi
312    if ! grep -q "^en_US ISO-8859-1$" /etc/locale.gen ; then
313        echo "en_US ISO-8859-1" >>/etc/locale.gen
314        LOCALECHANGED=1
315    fi
316    if ! grep -q "^es_ES ISO-8859-1$" /etc/locale.gen ; then
317        echo "es_ES ISO-8859-1" >>/etc/locale.gen
318        LOCALECHANGED=1
319    fi
320    if ! grep -q "^fr_FR ISO-8859-1$" /etc/locale.gen ; then
321        echo "fr_FR ISO-8859-1" >>/etc/locale.gen
322        LOCALECHANGED=1
323    fi
324    if [ "$LOCALECHANGED" ] ; then
325        locale-gen
326    fi
327fi
328
329#######################################################################
330# Save installed files to check them during next install
331#
332tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
333
334#######################################################################
335# Reload services
336#
337for service in postfix bind9 dovecot cron proftpd; do
338    invoke-rc.d $service force-reload || true
339done
340
341#######################################################################
342# Last touches
343#
344
345chown alterncpanel:alterncpanel "$ALTERNC_LOC/html/"*
346setfacl -b -k -m d:g:alterncpanel:rw- -m g:alterncpanel:rw- "$ALTERNC_LOC/html/"*
347
348# Creating admin user if needed
349HAS_ROOT=`mysql --defaults-file=/etc/alternc/my.cnf -e "SELECT COUNT(*) FROM membres WHERE login = 'admin' OR login = 'root' and su = 1" | tail -1`
350if [ "$HAS_ROOT" != "1" ]; then
351    echo "Creating admin user..."
352    echo ""
353
354    if su - alterncpanel -s /bin/bash -c /usr/share/alternc/install/newone.php
355      then
356      echo "*******************************************"
357      echo "*                                         *"
358      echo "*               Admin account             *"
359      echo "*               ------------              *"
360      echo "*                                         *"
361      echo "* user: admin             password: admin *"
362      echo "*                                         *"
363      echo "* Please change this as soon as possible! *"
364      echo "*                                         *"
365      echo "*******************************************"
366    else
367      echo "Il a été impossible de créer un nouveau membre alternc. newone.php a retourné un code d'erreur $?. Vérifiez si la base MySQL, PHP, ainsi que le fichier local.sh sont bien configurés. Vérifiez aussi si des erreurs ne sont pas apparues plus haut dans l'installation."
368    fi
369fi
370
371#giving vmail user read access on dovecot sql file
372chgrp vmail /etc/dovecot/dovecot.conf
373chmod g+r /etc/dovecot/dovecot.conf
374
375# Changing owner of web panel's files
376chown -R alterncpanel:alterncpanel "$ALTERNC_LOC/bureau"
377
378# We force the re-computing of the DNS zones, since we may have changed the IP address (see #460)
379/usr/bin/mysql --defaults-file="/etc/alternc/my.cnf" -B -e "update domaines set dns_action='update';"
380
381# We should restart apaches after all configuration stuff ...
382for service in $SERVICES; do
383    test -x /etc/init.d/$service && invoke-rc.d $service stop || true
384done
385for service in $SERVICES; do
386    test -x /etc/init.d/$service && invoke-rc.d $service start || true
387done
Note: See TracBrowser for help on using the repository browser.