root/alternc/trunk/install/alternc.install

Revision 2433, 12.3 kB (checked in by anarcat, 2 months ago)

move sessions to a shared /var/alternc/sessions

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 # This script now assumes it has MySQL connectivity through
9 # /etc/alternc/my.cnf
10
11 set -e
12
13 opts=`getopt "sf" $*`
14 if [ $? -ne 0 ]; then
15     echo invalid syntax: $?
16 fi
17 set -- $opts
18 for i; do
19     case "$i" in
20         -f|--force)
21             force=1; shift;;
22         -s|--slave)
23             slave=1; shift;;
24         --)
25             break;;
26         *)
27             echo "unknown option $i"; shift;;
28     esac
29 done
30
31 . /usr/lib/alternc/functions.sh
32
33 #######################################################################
34 # Script configuration
35 #
36
37 # Configuration template location
38 TEMPLATE_DIR="/etc/alternc/templates"
39
40 # Find needed configuration files (without the initial '/')
41 # replace this one unconditionnally
42 CONFIG_FILES="etc/alternc/bureau.conf"
43
44 if [ -e /etc/bind/named.conf ]; then
45     CONFIG_FILES="$CONFIG_FILES etc/bind/templates/zone.template
46                   etc/bind/templates/named.template etc/bind/named.conf etc/bind/named.conf.options"
47 fi
48 if [ -e /etc/courier/authdaemonrc ]; then
49     CONFIG_FILES="$CONFIG_FILES etc/courier/authdaemonrc
50                   etc/courier/authmysqlrc"
51 fi
52 if [ -d /etc/postfix ]; then
53     CONFIG_FILES="$CONFIG_FILES etc/postfix/myalias.cf etc/postfix/myrelay.cf
54                   etc/postfix/mydomain.cf etc/postfix/mygid.cf
55                   etc/postfix/myvirtual.cf etc/postfix/sasl/smtpd.conf"
56 fi
57 if [ -e /etc/proftpd/proftpd.conf ]; then
58     CONFIG_FILES="$CONFIG_FILES etc/proftpd/proftpd.conf etc/proftpd/welcome.msg etc/proftpd/modules.conf"
59 fi
60 if [ -e /etc/squirrelmail/apache.conf ]; then
61     CONFIG_FILES="$CONFIG_FILES etc/squirrelmail/apache.conf"
62 fi
63
64 if [ -e /etc/default/saslauthd ]; then
65     CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
66 fi
67
68 INSTALLED_CONFIG_TAR="/var/backups/alternc/etc-installed.tar.gz"
69
70 #######################################################################
71 # Look for modified configuration files
72 #
73 if [ -f "$INSTALLED_CONFIG_TAR" ]; then
74     CHANGED="`env LANG=C tar -zdf "$INSTALLED_CONFIG_TAR" -C / 2> /dev/null |
75               grep -v 'postfix/main.cf' | grep -v 'Uid differs'|grep -v 'Gid differs'  |grep -v 'Mode differs' |
76               sed -e 's/^\([^:]*\).*/    \1/' | sort -u`"
77     # " shutup emacs
78     if [ ! -z "$CHANGED" ]; then
79         echo "The following configuration files has changed since last AlternC"
80         echo "installation :"
81         echo "$CHANGED"
82         echo ""
83         if [ "$force" = "1" ]; then
84             echo "Replacing them as you requested."
85         else
86             echo "These configuration files should normally be modified by"
87             echo "changing the template in $TEMPLATE_DIR and then calling"
88             echo "$0 to perform the update."
89             echo ""
90             echo "Please examine the situation closely and call '$0 force'"
91             echo "if you still want to actually overwrite these files."
92             exit 1
93         fi
94     fi
95 fi
96
97 #######################################################################
98 # Prepare template expansions
99 #
100
101 . /etc/alternc/local.sh
102
103 # XXX: copy-paste from debian/config
104 if [ -r /etc/alternc/my.cnf ]; then
105     # make mysql configuration available as shell variables
106     # to convert from .cnf to shell syntax, we:
107     # * match only lines with "equal" in them (/=/)
108     # * remove whitespace around the = and add a left quote operator ' (;s)
109     # * add a right quote operator at the end of line (;s)
110     # * convert mysql variables into our MYSQL_ naming convention (;s)
111     # * print the result (;p)
112     eval `sed -n -e "/=/{s/ *= *\"\?/='/;s/\"\?\$/'/;s/host/MYSQL_HOST/;s/user/MYSQL_USER/;s/password/MYSQL_PASS/;s/database/MYSQL_DATABASE/;p}" /etc/alternc/my.cnf`
113     chown root:www-data /etc/alternc/my.cnf
114     chmod 640 /etc/alternc/my.cnf
115 fi
116
117 WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
118
119 VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
120
121 # /var/alternc/dns/d/www.example.com
122 FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
123 if [ "$FQDN_LETTER" = "$FQDN" ]
124 then
125        FQDN_LETTER="_"
126 fi
127
128 NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
129                  @ip = unpack('C4', \\$h);
130                  print join (\".\", @ip);"`
131
132 if [ -z "$MONITOR_IP" ]; then
133     MONITOR_IP="127.0.0.1"
134 fi
135
136 # XXX: I assume this is secure if /tmp is sticky (+t)
137 # we should have a better way to deal with templating, of course.
138 SED_SCRIPT=`mktemp`
139 cat > $SED_SCRIPT <<EOF
140 s\\%%hosting%%\\$HOSTING\\;
141 s\\%%fqdn%%\\$FQDN\\;
142 s\\%%public_ip%%\\$PUBLIC_IP\\;
143 s\\%%internal_ip%%\\$INTERNAL_IP\\;
144 s\\%%monitor_ip%%\\$MONITOR_IP\\;
145 s\\%%ns1%%\\$NS1_HOSTNAME\\;
146 s\\%%ns2%%\\$NS2_HOSTNAME\\;
147 s\\%%mx%%\\$DEFAULT_MX\\;
148 s\\%%dbhost%%\\$MYSQL_HOST\\;
149 s\\%%dbname%%\\$MYSQL_DATABASE\\;
150 s\\%%dbuser%%\\$MYSQL_USER\\;
151 s\\%%dbpwd%%\\$MYSQL_PASS\\;
152 s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
153 s\\%%warning_message%%\\$WARNING\\;
154 s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
155 s\\%%version%%\\$VERSION\\;
156 s\\%%ns2_ip%%\\$NS2_IP\\;
157 EOF
158
159 #######################################################################
160 # Backup configuration files
161 #
162 BACKUP_FILE="/var/backups/alternc/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
163
164 # Only backup what we are really going to replace
165 BACKUPS=""
166 for file in $CONFIG_FILES; do
167     TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
168     if [ -f "$TEMPLATE" ]; then
169         BACKUPS="$BACKUPS $file"
170     fi
171 done
172
173 # also backup main.cf since we're doing major changes to it
174 BACKUPS="$BACKUPS etc/postfix/main.cf"
175 tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
176
177 #######################################################################
178 # Expand templates in the right place
179 #
180 echo -n "Expanding variables in configuration files:"
181 for file in $CONFIG_FILES; do
182     TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
183     echo -n " $file"
184     if [ -f "$TEMPLATE" ]; then
185         sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
186     fi
187 done
188 echo "."
189 rm -f $SED_SCRIPT
190
191 #######################################################################
192 # Save installed files to check them during next install
193 #
194 tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
195
196 ########################################################################
197 # Ad-hoc fixes
198 #
199
200 php="`ls /usr/lib/apache*/*/*php*.so | sed -e 's/^.*libphp\(.\)\.so$/php\1/' | tail -1`"
201 ln -fs /etc/alternc/alternc.ini /etc/$php/conf.d/alternc.ini || true
202 if [ -x /usr/sbin/apache ]
203 then
204     # Enable vhost_alias apache module at the right place (ie: BEFORE mod_alias)
205     if ! grep -q "vhost_alias_module" /etc/apache/modules.conf
206     then
207         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
208     fi
209     echo "LoadModule ${php}_module /usr/lib/apache/1.3/lib${php}.so" | append_no_dupe /etc/apache/modules.conf
210     echo "LoadModule ${php}_module /usr/lib/apache/1.3/lib${php}.so" | append_no_dupe /etc/apache-ssl/modules.conf
211
212     if [ ! -h /etc/apache-ssl/conf.d/alternc.conf ] && [ -e /etc/apache-ssl/conf.d/ ]; then
213             ln -sf /etc/alternc/apache-ssl.conf /etc/apache-ssl/conf.d/alternc.conf
214     fi
215
216     if [ ! -h /etc/apache/conf.d/alternc.conf ] && [ -e /etc/apache/conf.d/ ]; then
217             ln -sf /etc/alternc/apache.conf /etc/apache/conf.d/alternc.conf
218     fi
219
220     if [ ! -h /etc/apache/conf.d/override_php.conf ] && [ -e /etc/apache/conf.d/ ]; then
221             ln -sf /var/alternc/apacheconf/override_php.conf /etc/apache/conf.d/override_php.conf
222     fi
223     SERVICES="$SERVICES apache apache-ssl"
224 fi
225 if [ -x /usr/sbin/apache2 ]; then
226     s=""
227     if ! ( [ -L /etc/apache2/mods-enabled/vhost_alias.load ] && [ -L /etc/apache2/mods-enabled/$php.load ] )
228     then
229         a2enmod vhost_alias
230         a2enmod $php
231         s="apache2"
232     fi
233     if [ -e /etc/alternc/apache.pem ]; then
234         if [ ! -h /etc/apache2/mods-enabled/ssl.load ] ; then
235             a2enmod ssl
236             s="apache2"
237         fi
238         if [ ! -h /etc/apache2/conf.d/alternc-ssl.conf ] && [ -e /etc/apache2/conf.d/ ]; then
239             ln -sf /etc/alternc/apache2-ssl.conf /etc/apache2/conf.d/alternc-ssl.conf
240             s="apache2"
241         fi
242     else
243         echo "SSL not configured"
244         echo "create a certificate in /etc/alternc/apache.pem and rerun alternc.install"
245     fi
246     if [ ! -h /etc/apache2/conf.d/alternc.conf ] && [ -e /etc/apache2/conf.d/ ]; then
247         ln -sf /etc/alternc/apache2.conf /etc/apache2/conf.d/alternc.conf
248         s="apache2"
249     fi
250     if [ ! -h /etc/apache2/conf.d/override_php.conf ] && [ -e /etc/apache2/conf.d/ ]; then
251         ln -sf /var/alternc/apacheconf/override_php.conf /etc/apache2/conf.d/override_php.conf
252         s="apache2"
253     fi
254     if [ -e /etc/apache2/sites-enabled/000-default ]; then
255         a2dissite default
256         s="apache2"
257     fi
258     SERVICES="$SERVICES $s"
259 fi
260
261 # Copy postfix *_checks if they do not exist
262 for file in body_checks header_checks; do
263     if [ ! -e "/etc/postfix/$file" ]; then
264         cp /usr/share/alternc/install/$file /etc/postfix
265     fi
266 done
267
268 # Attribute the correct rights to critical postfix files
269 if [ -e /etc/postfix/myalias.cf -o -e /etc/postfix/mydomain.cf -o -e /etc/postfix/mygid.cf -o -e /etc/postfix/myvirtual.cf -o -e /etc/postfix/myrelay.cf ]; then
270     chown root:postfix /etc/postfix/my*
271     chmod 640 /etc/postfix/my*
272 fi
273
274 # configure postfix appropriatly for our needs
275 if [ "$slave" = "1" ]; then
276     postfix_conf=/etc/alternc/postfix-slave.cf
277 else
278     postfix_conf=/etc/alternc/postfix.cf
279 fi
280 while read line
281 do
282    postconf -e "$line"
283 done < $postfix_conf
284
285 if [ -e /etc/courier/authmysqlrc ] ; then
286     chown root:root /etc/courier/authmysqlrc
287     chmod 640 /etc/courier/authmysqlrc
288 fi
289
290 if [ -e /etc/proftpd.conf ] ; then
291     chmod 640 /etc/proftpd/proftpd.conf
292 fi
293
294 if [ -x /usr/sbin/locale-gen ] ; then
295     touch /etc/locale.gen
296     LOCALECHANGED=""
297     # Add de_DE ISO-8859-1, en_US ISO-8859-1, es_ES ISO-8859-1, fr_FR ISO-8859-1 to the locales :
298     if ! grep -q "^de_DE ISO-8859-1$" /etc/locale.gen ; then
299         echo "de_DE ISO-8859-1" >>/etc/locale.gen
300         LOCALECHANGED=1
301     fi
302     if ! grep -q "^en_US ISO-8859-1$" /etc/locale.gen ; then
303         echo "en_US ISO-8859-1" >>/etc/locale.gen
304         LOCALECHANGED=1
305     fi
306     if ! grep -q "^es_ES ISO-8859-1$" /etc/locale.gen ; then
307         echo "es_ES ISO-8859-1" >>/etc/locale.gen
308         LOCALECHANGED=1
309     fi
310     if ! grep -q "^fr_FR ISO-8859-1$" /etc/locale.gen ; then
311         echo "fr_FR ISO-8859-1" >>/etc/locale.gen
312         LOCALECHANGED=1
313     fi
314     if [ "$LOCALECHANGED" ] ; then
315         locale-gen
316     fi
317 fi
318
319 #######################################################################
320 # Reload services
321 #
322 for service in postfix bind9 courier-authdaemon \
323                courier-imap courier-imap-ssl courier-pop courier-pop-ssl \
324                cron proftpd; do
325     invoke-rc.d $service reload || true
326 done
327
328 #######################################################################
329 # Last touches
330 #
331
332 # Creating admin user if needed
333 HAS_ROOT=`mysql --defaults-file=/etc/alternc/my.cnf -e "SELECT COUNT(*) FROM membres WHERE login = 'admin' OR login = 'root' and su = 1" | tail -1`
334 if [ "$HAS_ROOT" != "1" ]; then
335     echo "Creating admin user..."
336     echo ""
337
338     if su - www-data -c /usr/share/alternc/install/newone.php
339       then
340       echo "*******************************************"
341       echo "*                                         *"
342       echo "*               Admin account             *"
343       echo "*               ------------              *"
344       echo "*                                         *"
345       echo "* user: admin             password: admin *"
346       echo "*                                         *"
347       echo "* Please change this as soon as possible! *"
348       echo "*                                         *"
349       echo "*******************************************"
350     else
351       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."
352     fi
353 fi
354
355 # We should restart apaches after all configuration stuff ...
356 for service in $SERVICES; do
357     test -x /etc/init.d/$service && invoke-rc.d $service stop || true
358 done
359 for service in $SERVICES; do
360     test -x /etc/init.d/$service && invoke-rc.d $service start || true
361 done
Note: See TracBrowser for help on using the browser.