source: trunk/install/alternc.install @ 1022

Revision 1022, 8.1 KB checked in by anarcat, 7 years ago (diff)

remove remaining references to init.d. note that we rely on config files only if we are going to modify
those config files. if we rely on a service being running, we look for it's binary to see if it's installed.

Closes: #603

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