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

Revision 1749, 7.9 KB checked in by anarcat, 6 years ago (diff)

use reload instead of force-reload since the latter doesn't seem to
work with apache

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