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

Revision 1938, 9.7 KB checked in by anarcat, 6 years ago (diff)

try to rely on the actual .so presence instead of the package for libapache-mod-php*

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