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

Revision 1542, 8.3 KB checked in by anarcat, 7 years ago (diff)

activate a configuration file for the bureau, common for both SSL and non-SSL configs, requested by pierre-gilles et
benji.

activate variable substitution for bureau.conf in alternc.install

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