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

Revision 1572, 8.3 KB checked in by benjamin, 7 years ago (diff)

on ne prends pas en compte les gid / uid / mode differs lors du diff des fichiers de conf

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
8set -e
9
10#######################################################################
11# Script configuration
12#
13
14# Configuration template location
15TEMPLATE_DIR="/etc/alternc/templates"
16
17# Find needed configuration files (without the initial '/')
18# replace this one unconditionnally
19CONFIG_FILES="etc/alternc/bureau.conf"
20
21if [ -e /etc/apache/httpd.conf ]; then
22    CONFIG_FILES="$CONFIG_FILES etc/apache/httpd.conf"
23fi
24if [ -e /etc/php4/apache/php.ini ]; then
25    CONFIG_FILES="$CONFIG_FILES etc/php4/apache/php.ini"
26fi
27if [ -e /etc/apache-ssl/httpd.conf ]; then
28    CONFIG_FILES="$CONFIG_FILES etc/apache-ssl/httpd.conf"
29fi
30if [ -e /etc/php4/cgi/php.ini ]; then
31    CONFIG_FILES="$CONFIG_FILES etc/php4/cgi/php.ini"
32fi
33if [ -e /etc/bind/named.conf ]; then
34    CONFIG_FILES="$CONFIG_FILES etc/bind/templates/zone.template
35                  etc/bind/templates/named.template etc/bind/named.conf"
36fi
37if [ -e /etc/courier/authdaemonrc ]; then
38    CONFIG_FILES="$CONFIG_FILES etc/courier/authdaemonrc
39                  etc/courier/authmysqlrc"
40fi
41if [ -e /etc/postfix/main.cf ]; then
42    CONFIG_FILES="$CONFIG_FILES etc/postfix/main.cf etc/postfix/myalias.cf
43                  etc/postfix/mydomain.cf etc/postfix/mygid.cf
44                  etc/postfix/myvirtual.cf etc/postfix/sasl/smtpd.conf"
45fi
46if [ -e /etc/proftpd.conf ]; then
47    CONFIG_FILES="$CONFIG_FILES etc/proftpd.conf etc/welcome.msg"
48fi
49if [ -e /etc/squirrelmail/apache.conf ]; then
50    CONFIG_FILES="$CONFIG_FILES etc/squirrelmail/apache.conf"
51fi
52
53if [ -e /etc/default/saslauthd ]; then
54    CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
55fi
56
57INSTALLED_CONFIG_TAR="/var/backups/alternc/etc-installed.tar.gz"
58
59#######################################################################
60# Look for modified configuration files
61#
62if [ -f "$INSTALLED_CONFIG_TAR" ]; then
63    CHANGED="`tar -zdf "$INSTALLED_CONFIG_TAR" -C / 2> /dev/null |
64              grep -v 'Uid differs'|grep -v 'Gid differs'  |grep -v 'Mode differs' |
65              sed -e 's/^\([^:]*\).*/    \1/' | sort -u`"
66    if [ ! -z "$CHANGED" ]; then
67        echo "The following configuration files has changed since last AlternC"
68        echo "installation :"
69        echo "$CHANGED"
70        echo ""
71        if [ "$1" = "force" ]; then
72            echo "Replacing them as you requested."
73        else
74            echo "These configuration files should normally be modified by"
75            echo "changing the template in $TEMPLATE_DIR and then calling"
76            echo "$0 to perform the update."
77            echo ""
78            echo "Please examine the situation closely and call '$0 force'"
79            echo "if you still want to actually overwrite these files."
80            exit 1
81        fi
82    fi
83fi
84
85#######################################################################
86# Prepare template expansions
87#
88
89. /etc/alternc/local.sh
90
91WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
92
93VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
94
95# /var/alternc/dns/d/www.example.com
96FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
97if [ "$FQDN_LETTER" = "$FQDN" ] 
98then
99       FQDN_LETTER="_" 
100fi
101
102NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
103                 @ip = unpack('C4', \\$h);
104                 print join (\".\", @ip);"`
105
106if [ ! -z "$BIND_INTERNAL" ]; then
107    BIND_INTERNAL="$BIND_INTERNAL;"
108fi
109
110if [ -z "$MONITOR_IP" ]; then
111    MONITOR_IP="127.0.0.1"
112fi
113
114SED_SCRIPT="
115s\\%%hosting%%\\$HOSTING\\;
116s\\%%fqdn%%\\$FQDN\\;
117s\\%%public_ip%%\\$PUBLIC_IP\\;
118s\\%%internal_ip%%\\$INTERNAL_IP\\;
119s\\%%monitor_ip%%\\$MONITOR_IP\\;
120s\\%%ns1%%\\$NS1_HOSTNAME\\;
121s\\%%ns2%%\\$NS2_HOSTNAME\\;
122s\\%%bind_internal%%\\$BIND_INTERNAL\\;
123s\\%%mx%%\\$DEFAULT_MX\\;
124s\\%%dbhost%%\\$MYSQL_HOST\\;
125s\\%%dbname%%\\$MYSQL_DATABASE\\;
126s\\%%dbuser%%\\$MYSQL_USER\\;
127s\\%%dbpwd%%\\$MYSQL_PASS\\;
128s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
129s\\%%mynetwork%%\\$SMTP_RELAY_NETWORKS\\;
130s\\%%warning_message%%\\$WARNING\\;
131s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
132s\\%%version%%\\$VERSION\\;
133s\\%%ns2_ip%%\\$NS2_IP\\;
134"
135
136#######################################################################
137# Backup configuration files
138#
139BACKUP_FILE="/var/backups/alternc/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
140
141# Only backup what we are really going to replace
142BACKUPS=""
143for file in $CONFIG_FILES; do
144    TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
145    if [ -f "$TEMPLATE" ]; then
146        BACKUPS="$BACKUPS $file"
147    fi
148done
149
150tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
151
152#######################################################################
153# Expand templates in the right place
154#
155for file in $CONFIG_FILES; do
156    TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
157    if [ -f "$TEMPLATE" ]; then
158        sed -e "$SED_SCRIPT" < $TEMPLATE > /$file
159    fi
160done
161
162#######################################################################
163# Save installed files to check them during next install
164#
165tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
166
167######################################################################
168# Initialize database
169#
170if [ -e /usr/sbin/mysqld ]; then
171    echo "Setup MySQL and database..."
172    /usr/share/alternc/install/mysql.sh "$MYSQL_USER" "$MYSQL_PASS" "$MYSQL_DATABASE"
173fi
174
175########################################################################
176# Ad-hoc fixes
177#
178# Add access to the management panel
179ln -nsf /var/alternc/bureau /var/alternc/dns/$FQDN_LETTER/$FQDN
180
181# Update l18n files
182/usr/share/alternc/install/dopo.sh
183
184# Bind stuff
185touch /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
186chown root:bind /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
187chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
188touch /var/run/alternc/refresh_slave
189/usr/lib/alternc/slave_dns
190
191# Apache will not start without this file
192touch /var/alternc/apacheconf/override_php.conf
193
194# Copy postfix *_checks if they do not exist
195for file in body_checks header_checks; do
196    if [ ! -e "/etc/postfix/$file" ]; then
197        cp /usr/share/alternc/install/$file /etc/postfix
198    fi
199done
200
201# Attribute the correct rights to critical postfix files
202if [ -e /etc/postfix/myalias.cf -o -e /etc/postfix/mydomain.cf -o -e /etc/postfix/mygid.cf -o -e /etc/postfix/myvirtual.cf ]; then
203    chown root:postfix /etc/postfix/my*
204    chmod 640 /etc/postfix/my*
205fi
206
207if [ -e /etc/courier/authmysqlrc ] ; then
208    chown root:root /etc/courier/authmysqlrc
209    chmod 640 /etc/courier/authmysqlrc
210fi
211
212if [ -e /etc/proftpd.conf ] ; then
213    chmod 640 /etc/proftpd.conf
214fi
215
216#######################################################################
217# Reload services
218#
219for service in apache apache-ssl postfix bind9 courier-authdaemon \
220               courier-imap courier-imap-ssl courier-pop courier-pop-ssl \
221               cron proftpd; do
222    test -x /etc/init.d/$service && invoke-rc.d $service force-reload || true
223done
224
225#######################################################################
226# Last touches
227#
228
229# Add basedir protection
230/usr/lib/alternc/basedir_prot.sh
231
232# Creating admin user if needed
233HAS_ROOT="`mysql -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" -e "SELECT COUNT(*) FROM membres WHERE login = 'admin' OR login = 'root' and su = 1" | tail -1`"
234if [ "$HAS_ROOT" != "1" ]; then
235    echo "Creating admin user..."
236    echo ""
237
238    if su - www-data -c /usr/share/alternc/install/newone.php
239      then
240      echo "*******************************************"
241      echo "*                                         *"
242      echo "*               Admin account             *"
243      echo "*               ------------              *"
244      echo "*                                         *"
245      echo "* user: admin             password: admin *"
246      echo "*                                         *"
247      echo "* Please change this as soon as possible! *"
248      echo "*                                         *"
249      echo "*******************************************"
250    else
251      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."
252    fi
253fi
254
Note: See TracBrowser for help on using the repository browser.