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

Revision 3148, 13.9 KB checked in by squidly, 12 months ago (diff)

Correction template pour postfix + bugfixes des classes de gestion des mails

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