source: trunk/install/alternc.install @ 951

Revision 951, 7.8 KB checked in by nahuel, 7 years ago (diff)

Rajout d'attribution des droits corrects lors d'une install et lors de la prochaine mise à jour.
Closes: #610

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