root/alternc/tags/0.9.7/install/alternc.install

Revision 1995, 10.0 kB (checked in by pierre-gilles, 1 year ago)

Another fix to allow alternc to consider the php5 in an apache2 environnement

AlternC isn't ready to be install in an apache2 only environnement

- proftd depend on apache-ssl
- the link are built by the deb package and if /etc/apache(-ssl)/conf.d didn't exist the installation failed ...

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 . /usr/lib/alternc/functions.sh
11
12 #######################################################################
13 # Script configuration
14 #
15
16 # Configuration template location
17 TEMPLATE_DIR="/etc/alternc/templates"
18
19 # Find needed configuration files (without the initial '/')
20 # replace this one unconditionnally
21 CONFIG_FILES="etc/alternc/bureau.conf"
22
23 if [ -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"
26 fi
27 if [ -e /etc/courier/authdaemonrc ]; then
28     CONFIG_FILES="$CONFIG_FILES etc/courier/authdaemonrc
29                   etc/courier/authmysqlrc"
30 fi
31 if [ -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"
35 fi
36 if [ -e /etc/proftpd/proftpd.conf ]; then
37     CONFIG_FILES="$CONFIG_FILES etc/proftpd/proftpd.conf etc/proftpd/welcome.msg etc/proftpd/modules.conf"
38 fi
39 if [ -e /etc/squirrelmail/apache.conf ]; then
40     CONFIG_FILES="$CONFIG_FILES etc/squirrelmail/apache.conf"
41 fi
42
43 if [ -e /etc/default/saslauthd ]; then
44     CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
45 fi
46
47 INSTALLED_CONFIG_TAR="/var/backups/alternc/etc-installed.tar.gz"
48
49 #######################################################################
50 # Look for modified configuration files
51 #
52 if [ -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
73 fi
74
75 #######################################################################
76 # Prepare template expansions
77 #
78
79 . /etc/alternc/local.sh
80
81 WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
82
83 VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
84
85 # /var/alternc/dns/d/www.example.com
86 FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
87 if [ "$FQDN_LETTER" = "$FQDN" ]
88 then
89        FQDN_LETTER="_"
90 fi
91
92 NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
93                  @ip = unpack('C4', \\$h);
94                  print join (\".\", @ip);"`
95
96 if [ ! -z "$BIND_INTERNAL" ]; then
97     BIND_INTERNAL="$BIND_INTERNAL;"
98 fi
99
100 if [ -z "$MONITOR_IP" ]; then
101     MONITOR_IP="127.0.0.1"
102 fi
103
104 SED_SCRIPT="
105 s\\%%hosting%%\\$HOSTING\\;
106 s\\%%fqdn%%\\$FQDN\\;
107 s\\%%public_ip%%\\$PUBLIC_IP\\;
108 s\\%%internal_ip%%\\$INTERNAL_IP\\;
109 s\\%%monitor_ip%%\\$MONITOR_IP\\;
110 s\\%%ns1%%\\$NS1_HOSTNAME\\;
111 s\\%%ns2%%\\$NS2_HOSTNAME\\;
112 s\\%%bind_internal%%\\$BIND_INTERNAL\\;
113 s\\%%mx%%\\$DEFAULT_MX\\;
114 s\\%%dbhost%%\\$MYSQL_HOST\\;
115 s\\%%dbname%%\\$MYSQL_DATABASE\\;
116 s\\%%dbuser%%\\$MYSQL_USER\\;
117 s\\%%dbpwd%%\\$MYSQL_PASS\\;
118 s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
119 s\\%%mynetwork%%\\$SMTP_RELAY_NETWORKS\\;
120 s\\%%warning_message%%\\$WARNING\\;
121 s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
122 s\\%%version%%\\$VERSION\\;
123 s\\%%ns2_ip%%\\$NS2_IP\\;
124 "
125
126 #######################################################################
127 # Backup configuration files
128 #
129 BACKUP_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
132 BACKUPS=""
133 for file in $CONFIG_FILES; do
134     TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
135     if [ -f "$TEMPLATE" ]; then
136         BACKUPS="$BACKUPS $file"
137     fi
138 done
139
140 tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
141
142 #######################################################################
143 # Expand templates in the right place
144 #
145 for 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
150 done
151
152 #######################################################################
153 # Save installed files to check them during next install
154 #
155 tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
156
157 ######################################################################
158 # Initialize database
159 #
160 if [ "$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"
163 fi
164
165 ########################################################################
166 # Ad-hoc fixes
167 #
168 # Add access to the management panel
169 ln -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
175 touch /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
176 chown root:bind /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
177 chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
178 touch /var/run/alternc/refresh_slave
179 /usr/lib/alternc/slave_dns
180
181 # Apache will not start without this file
182 touch /var/alternc/apacheconf/override_php.conf
183 php="`ls /usr/lib/apache*/*/*php*.so | sed -e 's/^.*libphp\(.\)\.so$/php\1/' | tail -1`"
184 if [ -x /usr/sbin/apache ]
185 then
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"
194 fi
195 if [ -x /usr/sbin/apache2 ] &&  ! ( [ -L /etc/apache2/mods-enabled/vhost_alias.load ] && [ -L /etc/apache2/mods-enabled/$php.load ] )
196 then
197     a2enmod vhost_alias
198     a2enmod $php
199     SERVICES="$SERVICES apache2"
200 fi
201
202 # Copy postfix *_checks if they do not exist
203 for 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
207 done
208
209 # Attribute the correct rights to critical postfix files
210 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
211     chown root:postfix /etc/postfix/my*
212     chmod 640 /etc/postfix/my*
213 fi
214
215 if [ -e /etc/courier/authmysqlrc ] ; then
216     chown root:root /etc/courier/authmysqlrc
217     chmod 640 /etc/courier/authmysqlrc
218 fi
219
220 if [ -e /etc/proftpd.conf ] ; then
221     chmod 640 /etc/proftpd/proftpd.conf
222 fi
223
224 if [ -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
247 fi
248
249 #######################################################################
250 # Reload services
251 #
252 for 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
256 done
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
266 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`"
267 if [ "$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
286 fi
287
288 # We should restart apaches after all configuration stuff ...
289 for service in apache apache-ssl apache2 ; do
290     test -x /etc/init.d/$service && invoke-rc.d $service stop || true
291 done
292 for service in apache apache-ssl apache2 ; do
293     test -x /etc/init.d/$service && invoke-rc.d $service start || true
294 done
Note: See TracBrowser for help on using the browser.