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

Revision 2866, 11.6 KB checked in by fufroma, 4 years ago (diff)

Des morceaux de Apache1 qui restaient

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 [ -e /etc/courier/authdaemonrc ]; then
44    CONFIG_FILES="$CONFIG_FILES etc/courier/authdaemonrc
45                  etc/courier/authmysqlrc"
46fi
47if [ -d /etc/postfix ]; then
48    CONFIG_FILES="$CONFIG_FILES etc/postfix/myalias.cf etc/postfix/myrelay.cf
49                  etc/postfix/mydomain.cf etc/postfix/mygid.cf
50                  etc/postfix/myvirtual.cf etc/postfix/sasl/smtpd.conf"
51fi
52if [ -e /etc/proftpd/proftpd.conf ]; then
53    CONFIG_FILES="$CONFIG_FILES etc/proftpd/proftpd.conf etc/proftpd/welcome.msg etc/proftpd/modules.conf"
54fi
55if [ -e /etc/squirrelmail/apache.conf ]; then
56    CONFIG_FILES="$CONFIG_FILES etc/squirrelmail/apache.conf"
57fi
58
59if [ -e /etc/default/saslauthd ]; then
60    CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
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# XXX: copy-paste from debian/config
99if [ -r /etc/alternc/my.cnf ]; then
100    # make mysql configuration available as shell variables
101    # to convert from .cnf to shell syntax, we:
102    # * match only lines with "equal" in them (/=/)
103    # * remove whitespace around the = and add a left quote operator ' (;s)
104    # * add a right quote operator at the end of line (;s)
105    # * convert mysql variables into our MYSQL_ naming convention (;s)
106    # * print the result (;p)
107    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`
108    chown root:www-data /etc/alternc/my.cnf
109    chmod 640 /etc/alternc/my.cnf
110fi
111
112WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
113
114VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
115
116# /var/alternc/dns/d/www.example.com
117FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
118if [ "$FQDN_LETTER" = "$FQDN" ] 
119then
120       FQDN_LETTER="_" 
121fi
122
123NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
124                 @ip = unpack('C4', \\$h);
125                 print join (\".\", @ip);"`
126
127if [ -z "$MONITOR_IP" ]; then
128    MONITOR_IP="127.0.0.1"
129fi
130
131PUBLIC_IP_BEGIN=$(echo $PUBLIC_IP|cut -c 1)
132
133# XXX: I assume this is secure if /tmp is sticky (+t)
134# we should have a better way to deal with templating, of course.
135SED_SCRIPT=`mktemp`
136cat > $SED_SCRIPT <<EOF
137s\\%%hosting%%\\$HOSTING\\;
138s\\%%fqdn%%\\$FQDN\\;
139s\\%%public_ip%%\\$PUBLIC_IP\\;
140s\\%%public_ip_begin%%\\$PUBLIC_IP_BEGIN\\;
141s\\%%internal_ip%%\\$INTERNAL_IP\\;
142s\\%%monitor_ip%%\\$MONITOR_IP\\;
143s\\%%ns1%%\\$NS1_HOSTNAME\\;
144s\\%%ns2%%\\$NS2_HOSTNAME\\;
145s\\%%mx%%\\$DEFAULT_MX\\;
146s\\%%dbhost%%\\$MYSQL_HOST\\;
147s\\%%dbname%%\\$MYSQL_DATABASE\\;
148s\\%%dbuser%%\\$MYSQL_USER\\;
149s\\%%dbpwd%%\\$MYSQL_PASS\\;
150s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
151s\\%%warning_message%%\\$WARNING\\;
152s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
153s\\%%version%%\\$VERSION\\;
154s\\%%ns2_ip%%\\$NS2_IP\\;
155EOF
156
157#######################################################################
158# Backup configuration files
159#
160BACKUP_FILE="/var/backups/alternc/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
161
162# Only backup what we are really going to replace
163BACKUPS=""
164for file in $CONFIG_FILES; do
165    TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
166    if [ -f "$TEMPLATE" ]; then
167        BACKUPS="$BACKUPS $file"
168    fi
169done
170
171# also backup main.cf since we're doing major changes to it
172BACKUPS="$BACKUPS etc/postfix/main.cf"
173tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
174
175#######################################################################
176# Expand templates in the right place
177#
178echo -n "Expanding variables in configuration files:"
179for file in $CONFIG_FILES; do
180    TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
181    echo -n " $file"
182    if [ -f "$TEMPLATE" ]; then
183        sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
184    fi
185done
186echo "."
187rm -f $SED_SCRIPT
188
189########################################################################
190# Ad-hoc fixes
191#
192
193php="`ls /usr/lib/apache*/*/*php*.so | sed -e 's/^.*libphp\(.\)\.so$/php\1/' | tail -1`"
194ln -fs /etc/alternc/alternc.ini /etc/$php/conf.d/alternc.ini || true
195if [ -x /usr/sbin/apache2 ]; then
196    s=""
197    if ! ( [ -L /etc/apache2/mods-enabled/vhost_alias.load ] && [ -L /etc/apache2/mods-enabled/$php.load ] )
198    then
199        a2enmod vhost_alias
200        a2enmod rewrite
201        a2enmod $php
202        s="apache2"
203    fi
204    if [ -e /etc/alternc/apache.pem ]; then
205        # We enable proftpd tls module
206        cat /etc/proftpd/modules.conf | sed -e 's/^#LoadModule mod_tls.c/LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
207        mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
208        cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
209        # We enable apache2 SSL :
210        if [ ! -h /etc/apache2/mods-enabled/ssl.load ] ; then
211            a2enmod ssl
212            s="apache2"
213        fi
214        if [ ! -h /etc/apache2/conf.d/alternc-ssl.conf ] && [ -e /etc/apache2/conf.d/ ]; then
215            ln -sf /etc/alternc/apache2-ssl.conf /etc/apache2/conf.d/alternc-ssl.conf
216            s="apache2"
217        fi
218    else
219        # We disable proftpd tls module
220        cat /etc/proftpd/modules.conf | sed -e 's/^LoadModule mod_tls.c/#LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
221        mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
222        cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
223        echo "SSL not configured"
224        echo "create a certificate in /etc/alternc/apache.pem and rerun alternc.install"
225    fi
226    if [ ! -h /etc/apache2/conf.d/alternc.conf ] && [ -e /etc/apache2/conf.d/ ]; then
227        ln -sf /etc/alternc/apache2.conf /etc/apache2/conf.d/alternc.conf
228        s="apache2"
229    fi
230    if [ -e /etc/apache2/sites-enabled/000-default ]; then
231        a2dissite default
232        s="apache2"
233    fi
234    SERVICES="$SERVICES $s"
235fi
236
237# Copy postfix *_checks if they do not exist
238for file in body_checks header_checks; do
239    if [ ! -e "/etc/postfix/$file" ]; then
240        cp /usr/share/alternc/install/$file /etc/postfix
241    fi
242done
243
244# Attribute the correct rights to critical postfix files
245if [ -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
246    chown root:postfix /etc/postfix/my*
247    chmod 640 /etc/postfix/my*
248fi
249
250# configure postfix appropriatly for our needs
251if [ "$slave" = "1" ]; then
252    postfix_conf=/etc/alternc/postfix-slave.cf
253else
254    postfix_conf=/etc/alternc/postfix.cf
255fi
256while read line
257do
258   postconf -e "$line"
259done < $postfix_conf
260
261if [ -e /etc/courier/authmysqlrc ] ; then
262    chown root:root /etc/courier/authmysqlrc
263    chmod 640 /etc/courier/authmysqlrc
264fi
265
266if [ -e /etc/proftpd.conf ] ; then
267    chmod 640 /etc/proftpd/proftpd.conf
268fi
269
270if [ -x /usr/sbin/locale-gen ] ; then
271    touch /etc/locale.gen
272    LOCALECHANGED=""
273    # Add de_DE ISO-8859-1, en_US ISO-8859-1, es_ES ISO-8859-1, fr_FR ISO-8859-1 to the locales :
274    if ! grep -q "^de_DE ISO-8859-1$" /etc/locale.gen ; then
275        echo "de_DE ISO-8859-1" >>/etc/locale.gen
276        LOCALECHANGED=1
277    fi
278    if ! grep -q "^en_US ISO-8859-1$" /etc/locale.gen ; then
279        echo "en_US ISO-8859-1" >>/etc/locale.gen
280        LOCALECHANGED=1
281    fi
282    if ! grep -q "^es_ES ISO-8859-1$" /etc/locale.gen ; then
283        echo "es_ES ISO-8859-1" >>/etc/locale.gen
284        LOCALECHANGED=1
285    fi
286    if ! grep -q "^fr_FR ISO-8859-1$" /etc/locale.gen ; then
287        echo "fr_FR ISO-8859-1" >>/etc/locale.gen
288        LOCALECHANGED=1
289    fi
290    if [ "$LOCALECHANGED" ] ; then
291        locale-gen
292    fi
293fi
294
295#######################################################################
296# Save installed files to check them during next install
297#
298tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
299
300#######################################################################
301# Reload services
302#
303for service in postfix bind9 courier-authdaemon \
304               courier-imap courier-imap-ssl courier-pop courier-pop-ssl \
305               cron proftpd; do
306    invoke-rc.d $service force-reload || true
307done
308
309#######################################################################
310# Last touches
311#
312
313
314# Creating admin user if needed
315HAS_ROOT=`mysql --defaults-file=/etc/alternc/my.cnf -e "SELECT COUNT(*) FROM membres WHERE login = 'admin' OR login = 'root' and su = 1" | tail -1`
316if [ "$HAS_ROOT" != "1" ]; then
317    echo "Creating admin user..."
318    echo ""
319
320    if su - www-data -c /usr/share/alternc/install/newone.php
321      then
322      echo "*******************************************"
323      echo "*                                         *"
324      echo "*               Admin account             *"
325      echo "*               ------------              *"
326      echo "*                                         *"
327      echo "* user: admin             password: admin *"
328      echo "*                                         *"
329      echo "* Please change this as soon as possible! *"
330      echo "*                                         *"
331      echo "*******************************************"
332    else
333      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."
334    fi
335fi
336
337# We should restart apaches after all configuration stuff ...
338for service in $SERVICES; do
339    test -x /etc/init.d/$service && invoke-rc.d $service stop || true
340done
341for service in $SERVICES; do
342    test -x /etc/init.d/$service && invoke-rc.d $service start || true
343done
Note: See TracBrowser for help on using the repository browser.