root/alternc/tags/0.9.6/install/alternc.install

Revision 1749, 7.9 kB (checked in by anarcat, 2 years ago)

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
8 set -e
9
10 #######################################################################
11 # Script configuration
12 #
13
14 # Configuration template location
15 TEMPLATE_DIR="/etc/alternc/templates"
16
17 # Find needed configuration files (without the initial '/')
18 # replace this one unconditionnally
19 CONFIG_FILES="etc/alternc/bureau.conf"
20
21 if [ -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"
24 fi
25 if [ -e /etc/courier/authdaemonrc ]; then
26     CONFIG_FILES="$CONFIG_FILES etc/courier/authdaemonrc
27                   etc/courier/authmysqlrc"
28 fi
29 if [ -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"
33 fi
34 if [ -e /etc/proftpd.conf ]; then
35     CONFIG_FILES="$CONFIG_FILES etc/proftpd.conf etc/welcome.msg"
36 fi
37 if [ -e /etc/squirrelmail/apache.conf ]; then
38     CONFIG_FILES="$CONFIG_FILES etc/squirrelmail/apache.conf"
39 fi
40
41 if [ -e /etc/default/saslauthd ]; then
42     CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
43 fi
44
45 INSTALLED_CONFIG_TAR="/var/backups/alternc/etc-installed.tar.gz"
46
47 #######################################################################
48 # Look for modified configuration files
49 #
50 if [ -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
71 fi
72
73 #######################################################################
74 # Prepare template expansions
75 #
76
77 . /etc/alternc/local.sh
78
79 WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
80
81 VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
82
83 # /var/alternc/dns/d/www.example.com
84 FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
85 if [ "$FQDN_LETTER" = "$FQDN" ]
86 then
87        FQDN_LETTER="_"
88 fi
89
90 NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
91                  @ip = unpack('C4', \\$h);
92                  print join (\".\", @ip);"`
93
94 if [ ! -z "$BIND_INTERNAL" ]; then
95     BIND_INTERNAL="$BIND_INTERNAL;"
96 fi
97
98 if [ -z "$MONITOR_IP" ]; then
99     MONITOR_IP="127.0.0.1"
100 fi
101
102 SED_SCRIPT="
103 s\\%%hosting%%\\$HOSTING\\;
104 s\\%%fqdn%%\\$FQDN\\;
105 s\\%%public_ip%%\\$PUBLIC_IP\\;
106 s\\%%internal_ip%%\\$INTERNAL_IP\\;
107 s\\%%monitor_ip%%\\$MONITOR_IP\\;
108 s\\%%ns1%%\\$NS1_HOSTNAME\\;
109 s\\%%ns2%%\\$NS2_HOSTNAME\\;
110 s\\%%bind_internal%%\\$BIND_INTERNAL\\;
111 s\\%%mx%%\\$DEFAULT_MX\\;
112 s\\%%dbhost%%\\$MYSQL_HOST\\;
113 s\\%%dbname%%\\$MYSQL_DATABASE\\;
114 s\\%%dbuser%%\\$MYSQL_USER\\;
115 s\\%%dbpwd%%\\$MYSQL_PASS\\;
116 s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
117 s\\%%mynetwork%%\\$SMTP_RELAY_NETWORKS\\;
118 s\\%%warning_message%%\\$WARNING\\;
119 s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
120 s\\%%version%%\\$VERSION\\;
121 s\\%%ns2_ip%%\\$NS2_IP\\;
122 "
123
124 #######################################################################
125 # Backup configuration files
126 #
127 BACKUP_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
130 BACKUPS=""
131 for file in $CONFIG_FILES; do
132     TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
133     if [ -f "$TEMPLATE" ]; then
134         BACKUPS="$BACKUPS $file"
135     fi
136 done
137
138 tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
139
140 #######################################################################
141 # Expand templates in the right place
142 #
143 for 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
148 done
149
150 #######################################################################
151 # Save installed files to check them during next install
152 #
153 tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
154
155 ######################################################################
156 # Initialize database
157 #
158 if [ -e /usr/sbin/mysqld ]; then
159     echo "Setup MySQL and database..."
160     /usr/share/alternc/install/mysql.sh "$MYSQL_USER" "$MYSQL_PASS" "$MYSQL_DATABASE"
161 fi
162
163 ########################################################################
164 # Ad-hoc fixes
165 #
166 # Add access to the management panel
167 ln -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
173 touch /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
174 chown root:bind /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
175 chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
176 touch /var/run/alternc/refresh_slave
177 /usr/lib/alternc/slave_dns
178
179 # Apache will not start without this file
180 touch /var/alternc/apacheconf/override_php.conf
181
182 # Copy postfix *_checks if they do not exist
183 for 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
187 done
188
189 # Attribute the correct rights to critical postfix files
190 if [ -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*
193 fi
194
195 if [ -e /etc/courier/authmysqlrc ] ; then
196     chown root:root /etc/courier/authmysqlrc
197     chmod 640 /etc/courier/authmysqlrc
198 fi
199
200 if [ -e /etc/proftpd.conf ] ; then
201     chmod 640 /etc/proftpd.conf
202 fi
203
204 #######################################################################
205 # Reload services
206 #
207 for 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
211 done
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
221 HAS_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`"
222 if [ "$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
241 fi
242
Note: See TracBrowser for help on using the browser.