alternc.install 22.1 KB
Newer Older
Alan Garcia's avatar
Hop-là    
Alan Garcia committed
1
#!/bin/bash
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# ----------------------------------------------------------------------
# AlternC - Web Hosting System
# Copyright (C) 2000-2012 by the AlternC Development Team.
# https://alternc.org/
# ----------------------------------------------------------------------
# LICENSE
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
19
#
20
21
22
23
# To read the license please visit http://www.gnu.org/copyleft/gpl.html
# ----------------------------------------------------------------------
# Purpose of file: Main install script, launch it anytime ;) 
# ----------------------------------------------------------------------
24

25
26
27
28
29
30
# Somes check before start operations
if [ `id -u` -ne 0 ]; then
    echo "must be launched as root"
    exit 1
fi

31
32
set -e 

33
for i in $*; do
34
35
    case "$i" in
        -f|--force)
36
            export force=1; shift;;
37
        -s|--slave)
38
            export slave=1; shift;;
39
40
41
42
43
44
45
        --)
            break;;
        *)
            echo "unknown option $i"; shift;;
    esac
done

46
47
. /usr/lib/alternc/functions.sh

Alan Garcia's avatar
Alan Garcia committed
48
49
50
# Lock the jobs !
lock_jobs

51
52
53
# hook 
run-parts --arg=startup /usr/lib/alternc/install.d 

54
55
56
57
58
59
60
61
#######################################################################
# Script configuration
#

# Configuration template location
TEMPLATE_DIR="/etc/alternc/templates"

# Find needed configuration files (without the initial '/')
62
# replace this one unconditionnally
Alan Garcia's avatar
Alan Garcia committed
63
CONFIG_FILES="etc/alternc/bureau.conf etc/apache2/envvars etc/alternc/apache2.conf etc/alternc/apache_logformat.conf etc/alternc/phpmyadmin.inc.php"
64
65

if [ -e /etc/bind/named.conf ]; then
66
    CONFIG_FILES="$CONFIG_FILES etc/bind/named.conf.options"
67
fi
68
if [ -d /etc/postfix ]; then
69
    CONFIG_FILES="$CONFIG_FILES etc/postfix/master.cf etc/postfix/myalias.cf etc/postfix/myrelay.cf
70
                  etc/postfix/mydomain.cf etc/postfix/myrelay-domain.cf etc/postfix/mymail2mail.cf etc/postfix/mygid.cf etc/postfix/myquota.cf
Alan Garcia's avatar
Alan Garcia committed
71
                  etc/postfix/myvirtual.cf etc/postfix/mytransport.cf etc/postfix/sasl/smtpd.conf
72
73
                  etc/alternc/postfix/postfix.cf etc/alternc/postfix/postfix-slave.cf
                  etc/opendkim.conf etc/default/opendkim"
74
fi
75
76
if [ -e /etc/proftpd/proftpd.conf ]; then
    CONFIG_FILES="$CONFIG_FILES etc/proftpd/proftpd.conf etc/proftpd/welcome.msg etc/proftpd/modules.conf"
77
78
79
80
81
82
fi

if [ -e /etc/default/saslauthd ]; then
    CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
fi

83
if [ -e /etc/dovecot/dovecot.conf ]; then
84
    CONFIG_FILES="$CONFIG_FILES etc/dovecot/dovecot.conf etc/dovecot/dovecot-sql.conf etc/dovecot/dovecot-dict-quota.conf"
85
86
fi

87
INSTALLED_CONFIG_TAR="/var/lib/alternc/backups/etc-installed.tar.gz"
88
89
90
91
92

#######################################################################
# Look for modified configuration files
#
if [ -f "$INSTALLED_CONFIG_TAR" ]; then
93
94
    CHANGED="`env LANG=C tar -zdf "$INSTALLED_CONFIG_TAR" -C / 2> /dev/null | 
              grep -v 'postfix/main.cf' | grep -v 'Uid differs'|grep -v 'Gid differs'  |grep -v 'Mode differs' | 
95
96
97
98
99
100
              sed -e 's/^\([^:]*\).*/    \1/' | sort -u`"
    if [ ! -z "$CHANGED" ]; then
        echo "The following configuration files has changed since last AlternC"
        echo "installation :"
        echo "$CHANGED"
        echo ""
101
        if [ "$force" = "1" ]; then
102
103
104
105
106
107
            echo "Replacing them as you requested."
        else
            echo "These configuration files should normally be modified by"
            echo "changing the template in $TEMPLATE_DIR and then calling"
            echo "$0 to perform the update."
            echo ""
108
            echo "Please examine the situation closely and call '$0 -f'"
109
110
111
112
113
114
115
116
117
118
            echo "if you still want to actually overwrite these files."
            exit 1
        fi
    fi
fi

#######################################################################
# Prepare template expansions
#

119
chown :alterncpanel /etc/alternc/local.sh
120
121
. /etc/alternc/local.sh

122
123
124
# May be missing 
test -d /var/run/alternc || ( mkdir -p /var/run/alternc && chown alterncpanel:alterncpanel /var/run/alternc )

Alan Garcia's avatar
Alan Garcia committed
125
126
127
128
129
# Create the target directory
for i in "$ALTERNC_HTML" "$ALTERNC_MAIL" "$ALTERNC_LOGS" ; do
  test -d "$i" || mkdir -p "$i"
done

130
for i in a b c d e f g h i j k l m n o p q r s t u v w x y z _ 0 1 2 3 4 5 6 7 8 9; do
131
  test -d "$ALTERNC_HTML/$i" || ( mkdir -p "$ALTERNC_HTML/$i" && chown alterncpanel:alterncpanel "$ALTERNC_HTML/$i" && chmod 775 "$ALTERNC_HTML/$i" )
132
  test -d "$ALTERNC_MAIL/$i" || ( mkdir -p "$ALTERNC_MAIL/$i" && chown vmail:vmail "$ALTERNC_MAIL/$i" && chmod 775 "$ALTERNC_MAIL/$i" )
133
134
done

135
136
137
find $ALTERNC_LOGS -maxdepth 1 -type d -exec chown alterncpanel:adm {} \; 
find $ALTERNC_HTML -maxdepth 1 -type d -exec chown alterncpanel:alterncpanel {} \; 
find $ALTERNC_MAIL -maxdepth 1 -type d -exec chown vmail:vmail {} \;
138

139
# Check ACL
Alan Garcia's avatar
Alan Garcia committed
140
aclcheckfile="$ALTERNC_HTML/test-acl"
141
touch "$aclcheckfile"
142
143
setfacl -m u:root:rwx "$aclcheckfile" 2>/dev/null || ( echo "Error : ACL aren't activated on $ALTERNC_HTML . AlternC can't work without it." ; test -e "$aclcheckfile" && rm -f "$aclcheckfile" ; exit 2)
test -e "$aclcheckfile" && rm -f "$aclcheckfile"
144

145
146
147
148
149
150
151
152
153
# XXX: copy-paste from debian/config
if [ -r /etc/alternc/my.cnf ]; then
    # make mysql configuration available as shell variables
    # to convert from .cnf to shell syntax, we:
    # * match only lines with "equal" in them (/=/)
    # * remove whitespace around the = and add a left quote operator ' (;s)
    # * add a right quote operator at the end of line (;s)
    # * convert mysql variables into our MYSQL_ naming convention (;s)
    # * print the result (;p)
154
    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`
Alan Garcia's avatar
Alan Garcia committed
155
    chown root:alterncpanel /etc/alternc/my.cnf
156
    chmod 640 /etc/alternc/my.cnf
157
158
fi

Steven Mondji-Lerider's avatar
Steven Mondji-Lerider committed
159
160
161
162
163
164
165
166
if [ -r /etc/alternc/my_mail.cnf ]; then
    # make mysql configuration available as shell variables
    # to convert from .cnf to shell syntax, we:
    # * match only lines with "equal" in them (/=/)
    # * remove whitespace around the = and add a left quote operator ' (;s)
    # * add a right quote operator at the end of line (;s)
    # * convert mysql variables into our MYSQL_ naming convention (;s)
    # * print the result (;p)
167
    eval `sed -n -e "/=/{s/ *= *\"\?/='/;s/\"\?\$/'/;s/host/MYSQL_HOST/;s/user/MYSQL_MAIL_USER/;s/password/MYSQL_MAIL_PASS/;s/database/MYSQL_DATABASE/;p}" /etc/alternc/my_mail.cnf`
Steven Mondji-Lerider's avatar
Steven Mondji-Lerider committed
168
169
170
171
    chown root:alterncpanel /etc/alternc/my_mail.cnf
    chmod 640 /etc/alternc/my_mail.cnf
fi

172
173
WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."

174
175
176
177
178
if [ "$slave" = "1" ]; then
    VERSION="`dpkg -s alternc-slave | sed -n -e 's/^Version: \(.*\)/\1/p'`"
else
    VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
fi
179

180
# /var/ alternc/dns/d/www.example.com
181
182
183
184
185
186
187
188
189
190
191
192
193
194
FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
if [ "$FQDN_LETTER" = "$FQDN" ] 
then
       FQDN_LETTER="_" 
fi

NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
                 @ip = unpack('C4', \\$h);
                 print join (\".\", @ip);"`

if [ -z "$MONITOR_IP" ]; then
    MONITOR_IP="127.0.0.1"
fi

195
PUBLIC_IP_BEGIN=$(echo $PUBLIC_IP|cut -c 1)
Alan Garcia's avatar
Alan Garcia committed
196

197
198
199
# Secret for PhpMyAdmin sessions
PHPMYADMIN_BLOWFISH="$(generate_string 24)"

200
201
# XXX: I assume this is secure if /tmp is sticky (+t)
# we should have a better way to deal with templating, of course.
202
SED_SCRIPT="/tmp/alternc.install.sedscript"
203
cat > $SED_SCRIPT <<EOF
204
205
206
s\\%%hosting%%\\$HOSTING\\;
s\\%%fqdn%%\\$FQDN\\;
s\\%%public_ip%%\\$PUBLIC_IP\\;
Alan Garcia's avatar
Alan Garcia committed
207
s\\%%public_ip_begin%%\\$PUBLIC_IP_BEGIN\\;
208
209
210
211
212
213
214
215
216
s\\%%internal_ip%%\\$INTERNAL_IP\\;
s\\%%monitor_ip%%\\$MONITOR_IP\\;
s\\%%ns1%%\\$NS1_HOSTNAME\\;
s\\%%ns2%%\\$NS2_HOSTNAME\\;
s\\%%mx%%\\$DEFAULT_MX\\;
s\\%%dbhost%%\\$MYSQL_HOST\\;
s\\%%dbname%%\\$MYSQL_DATABASE\\;
s\\%%dbuser%%\\$MYSQL_USER\\;
s\\%%dbpwd%%\\$MYSQL_PASS\\;
Steven Mondji-Lerider's avatar
Steven Mondji-Lerider committed
217
218
s\\%%db_mail_user%%\\$MYSQL_MAIL_USER\\;
s\\%%db_mail_pwd%%\\$MYSQL_MAIL_PASS\\;
219
220
221
222
s\\%%warning_message%%\\$WARNING\\;
s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
s\\%%version%%\\$VERSION\\;
s\\%%ns2_ip%%\\$NS2_IP\\;
Alan Garcia's avatar
Alan Garcia committed
223
224
225
s\\%%ALTERNC_HTML%%\\$ALTERNC_HTML\\;
s\\%%ALTERNC_MAIL%%\\$ALTERNC_MAIL\\;
s\\%%ALTERNC_LOGS%%\\$ALTERNC_LOGS\\;
226
s\\%%PHPMYADMIN_BLOWFISH%%\\$PHPMYADMIN_BLOWFISH\\;
227
EOF
228

229
# hook 
Alan Garcia's avatar
Alan Garcia committed
230
test -d /usr/lib/alternc/install.d || mkdir -p /usr/lib/alternc/install.d
231
232
run-parts --arg=templates /usr/lib/alternc/install.d 

233
234
235

######################################################################
# Backup the Main database
236
DB_BACKUP="/var/lib/alternc/backups/${MYSQL_DATABASE}-db-`date +%Y%m%d-%H:%M:%S`.gz"
237
238
239
db_dump="mysqldump --defaults-file=/etc/alternc/my.cnf --add-drop-table --allow-keywords --quote-names --force --quick --add-locks --lock-tables --extended-insert ${MYSQL_DATABASE}"
$db_dump | /bin/gzip -c > $DB_BACKUP || echo "backup of the main database failed"

240
241
242
#######################################################################
# Backup configuration files
#
243
BACKUP_FILE="/var/lib/alternc/backups/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
244
245
246
247
248
249
250
251
252
253

# Only backup what we are really going to replace
BACKUPS=""
for file in $CONFIG_FILES; do
    TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
    if [ -f "$TEMPLATE" ]; then
        BACKUPS="$BACKUPS $file"
    fi
done

254
255
# also backup main.cf since we're doing major changes to it
BACKUPS="$BACKUPS etc/postfix/main.cf"
256

257
258
259
260
261
tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true

#######################################################################
# Expand templates in the right place
#
262
echo -n "Expanding variables in configuration files:"
263
264
for file in $CONFIG_FILES; do
    TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
265
    echo -n " $file"
266
    if [ -f "$TEMPLATE" ]; then
267
        sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
268
269
    fi
done
270
echo "."
271
rm -f $SED_SCRIPT
272
273
274
275
276

######################################################################## 
# Ad-hoc fixes
#

277
php="`ls /usr/lib/apache*/*/*php*.so | sed -e 's/^.*libphp\(.\)\.so$/php\1/' | tail -1`"
278
ln -fs /etc/alternc/alternc.ini /etc/$php/conf.d/alternc.ini || true
279
if [ -x /usr/sbin/apache2 ]; then
280
281
282
    # hook 
    run-parts --arg=apache2 /usr/lib/alternc/install.d 
    
283
    s=""
Benjamin Sonntag's avatar
Benjamin Sonntag committed
284
    # unused from AlternC 1.0, FIXME: remove it later
285
    if [ -L /etc/apache2/mods-enabled/vhost_alias.load ]
286
    then
287
        a2dismod vhost_alias
288
289
        s="apache2"
    fi 
290
291
    if ! [ -L /etc/apache2/mods-enabled/$php.load ]
    then
Alan Garcia's avatar
Alan Garcia committed
292
	    a2enmod $php
293
294
295
    fi
    if ! [ -L /etc/apache2/mods-enabled/rewrite.load ]
    then
Alan Garcia's avatar
Alan Garcia committed
296
	    a2enmod rewrite
297
    fi
298
    if [ -e /etc/alternc/apache.pem ]; then
299
300
301
302
303
        # We enable proftpd tls module
        cat /etc/proftpd/modules.conf | sed -e 's/^#LoadModule mod_tls.c/LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
        mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf 
        cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
        # We enable apache2 SSL : 
304
        if [ ! -L /etc/apache2/mods-enabled/ssl.load ] ; then
305
306
307
308
            a2enmod ssl
            s="apache2"
        fi
        if [ ! -h /etc/apache2/conf.d/alternc-ssl.conf ] && [ -e /etc/apache2/conf.d/ ]; then
309
            ln -sf /etc/alternc/apache2-ssl.conf /etc/apache2/conf.d/alternc-ssl.conf
310
311
            s="apache2"
        fi
312
313

	# We enable dovecot SSL certificate instructions: (on wheezy we should use a new file in /etc/dovecot/conf.d/ )
314
	sed -i -e 's#^ssl_cert_file.*$#ssl_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem#' -e 's#^ssl_key_file.*$#ssl_key_file = /etc/ssl/private/ssl-cert-snakeoil.key#' /etc/dovecot/dovecot.conf
315

316
    else
317
318
319
320
        # We disable proftpd tls module
        cat /etc/proftpd/modules.conf | sed -e 's/^LoadModule mod_tls.c/#LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
        mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf 
        cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
321
322

	# We disable dovecot SSL certificate instructions: (on wheezy we should remove a file in /etc/dovecot/conf.d/ )
323
        sed -i -e 's#^ssl_cert_file.*$#ssl_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem#' -e 's#^ssl_key_file.*$#ssl_key_file = /etc/ssl/private/ssl-cert-snakeoil.key#' /etc/dovecot/dovecot.conf
324

325
326
        echo "SSL not configured"
        echo "create a certificate in /etc/alternc/apache.pem and rerun alternc.install"
Antoine Beaupré's avatar
Antoine Beaupré committed
327
    fi
328
329
330
331
    if [ ! -h /etc/apache2/conf.d/alternc.conf ] && [ -e /etc/apache2/conf.d/ ]; then
        ln -sf /etc/alternc/apache2.conf /etc/apache2/conf.d/alternc.conf
        s="apache2"
    fi
332
333
334
335
    if [ -e /etc/apache2/sites-enabled/000-default ]; then
        a2dissite default
        s="apache2"
    fi
336
    SERVICES="$SERVICES $s"
337
fi
338
339
340
341
342
343
344
345
346

# Copy postfix *_checks if they do not exist
for file in body_checks header_checks; do
    if [ ! -e "/etc/postfix/$file" ]; then
        cp /usr/share/alternc/install/$file /etc/postfix
    fi
done

# Attribute the correct rights to critical postfix files
347
if [ -e /etc/postfix/myalias.cf -o -e /etc/postfix/mydomain.cf -o -e /etc/postfix/mygid.cf -o -e /etc/postfix/myrelay-domain.sh -o -e /etc/postfix/myvirtual.cf -o -e /etc/postfix/myrelay.cf -o -e /etc/postfix/myquota.cf ]; then
348
349
350
351
    chown root:postfix /etc/postfix/my*
    chmod 640 /etc/postfix/my*
fi

352
353
354
355
356
357
if [ ! -f /etc/postfix/main.cf ]
then
    echo "****************************************"
    echo "POSTFIX is NOT configured properly"
    echo "please launch dpkg-reconfigure -plow postfix" 
    echo "and choose 'Internet Site'"
358
    echo "then launch alternc.install again"
359
360
361
362
    echo "****************************************"
    exit 1
fi

363
# configure Postfix appropriatly for our needs
364
if [ "$slave" = "1" ]; then
365
    postfix_conf=/etc/alternc/postfix/postfix-slave.cf
366
else
367
    postfix_conf=/etc/alternc/postfix/postfix.cf
368
fi
369
grep -v '^\ *#' $postfix_conf |while read line ; do
Steven Mondji-Lerider's avatar
Steven Mondji-Lerider committed
370
   if echo "$line" | grep -qi '^smtpd_tls_dcert_file' ;then
371
372
373
     line_strip=`echo "$line"|tr -d '[:blank:]'`
     pattern="*="
     cert_file=${line_strip#$pattern}
Steven Mondji-Lerider's avatar
Steven Mondji-Lerider committed
374
375
376
     echo $cert_file
     echo $line
     echo $line_strip
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
     if [ -e $cert_file ];then
        postconf -e "$line"
     else
        echo "****************************************"
        echo "The certificate file : $cert_file does not exists"
        echo "please go to https://alternc.org/wiki/SSL to get information on how to create a certificate"
        echo "Then edit the file /etc/alternc/postfix/postfix.cf to add"
        echo "the cert file path name to the key :smtpd_tls_cert_file"
        echo "Finally relaunch alternc.install"
        echo "****************************************"
     fi
  else
        postconf -e "$line"
  fi
done
392

393
# Conviguring delivery used by Postfix
Steven Mondji-Lerider's avatar
Steven Mondji-Lerider committed
394
/usr/lib/alternc/alternc_add_policy_dovecot
395

396
397
398
# Bug #1215: configure mydestination when $FQDN is not in
OLDDESTINATION=`postconf mydestination | awk -F '=' '{print $2}'`
echo "$OLDDESTINATION" | grep -q -v "$FQDN" && postconf -e "mydestination = $FQDN, $OLDDESTINATION"
399

400
401
402
403
404
405
406
407
408
# Configure PHPMyAdmin
include_str='include("/etc/alternc/phpmyadmin.inc.php")'
pma_config='/etc/phpmyadmin/config.inc.php'

# Sur une configuration vierge, inclure la configuration alternc
if ! grep -e "${include_str/\"/\\\"}" $pma_config > /dev/null 2>&1; then
    echo "$include_str;" >> $pma_config
fi

409
# Le template de /etc/alternc/phpmyadmin.inc.php viens d'être réappliqué, on 
410
# regénére la liste des serveurs MySQL disponible dedans.
411
412
413
414
415
416
417
418
419
420
421
mysql_query "select id,host,name from db_servers;" | while read id host name ; do
echo "
// Server #$id in db_servers
\$i++;
\$cfg['Servers'][\$i]['connect_type']  = 'tcp';    // How to connect to MySQL server ('tcp' or 'socket')
\$cfg['Servers'][\$i]['auth_type']     = 'cookie';    // Authentication method (config, http or cookie based)?
\$cfg['Servers'][\$i]['hide_db']       = 'information_schema';
\$cfg['Servers'][\$i]['verbose']       = '$name'; // human name
\$cfg['Servers'][\$i]['host']          = '$host'; // MySQL hostname or IP address
" >> '/etc/alternc/phpmyadmin.inc.php'
done
422

423
# Reload incron. Useless, but who know?
424
SERVICES="$SERVICES incron"
425
 
Benjamin Sonntag's avatar
Benjamin Sonntag committed
426
if [ -e /etc/proftpd.conf ] ; then
427
    chmod 640 /etc/proftpd/proftpd.conf
Benjamin Sonntag's avatar
Benjamin Sonntag committed
428
429
fi

430
431
if [ -x /usr/sbin/locale-gen ] ; then
    touch /etc/locale.gen
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
    LOCALECHANGED=""
    # Add de_DE ISO-8859-1, en_US ISO-8859-1, es_ES ISO-8859-1, fr_FR ISO-8859-1 to the locales : 
    if ! grep -q "^de_DE ISO-8859-1$" /etc/locale.gen ; then
	echo "de_DE ISO-8859-1" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
    if ! grep -q "^en_US ISO-8859-1$" /etc/locale.gen ; then
	echo "en_US ISO-8859-1" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
    if ! grep -q "^es_ES ISO-8859-1$" /etc/locale.gen ; then
	echo "es_ES ISO-8859-1" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
    if ! grep -q "^fr_FR ISO-8859-1$" /etc/locale.gen ; then 
	echo "fr_FR ISO-8859-1" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
    if ! grep -q "^de_DE.UTF-8 UTF-8$" /etc/locale.gen ; then
	echo "de_DE.UTF-8 UTF-8" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
    if ! grep -q "^fr_FR.UTF-8 UTF-8$" /etc/locale.gen ; then
	echo "fr_FR.UTF-8 UTF-8" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
    if ! grep -q "^es_ES.UTF-8 UTF-8$" /etc/locale.gen ; then
	echo "es_ES.UTF-8 UTF-8" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
    if ! grep -q "^en_US.UTF-8 UTF-8$" /etc/locale.gen ; then
	echo "en_US.UTF-8 UTF-8" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
466
467
468
469
    if ! grep -q "^it_IT.UTF-8 UTF-8$" /etc/locale.gen ; then
	echo "it_IT.UTF-8 UTF-8" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
Alan Garcia's avatar
Alan Garcia committed
470
471
472
473
    if ! grep -q "^nl_NL.UTF-8 UTF-8$" /etc/locale.gen ; then
	echo "nl_NL.UTF-8 UTF-8" >>/etc/locale.gen
	LOCALECHANGED=1
    fi
474
475
476
477
478
    if [ "$LOCALECHANGED" ] ; then
	locale-gen
    fi
fi

479
480
481
482
483
# remaining steps are only for the master
if [ "$slave" = "1" ]; then
    exit 0
fi

484
#######################################################################
485
# populate alternc database with the mailname used by postfix to send mail for each vhost
486
#
Alan Garcia's avatar
Alan Garcia committed
487
488
# If mailname does not exist, create it. Fix #1495
test -e "/etc/mailname" || hostname -f > "/etc/mailname" 
489
490
# Allow for all the users to view /etc/mailname
chmod +r "/etc/mailname"
491

492
493
494
495
496
#######################################################################
# Save installed files to check them during next install
#
tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES

497
498
499
500
#######################################################################
# Last touches
#

501
find $ALTERNC_HTML -maxdepth 1 -type d -exec setfacl -b -k -m d:g:alterncpanel:rw- -m d:u:alterncpanel:rw- -m u:alterncpanel:rw- -m g:alterncpanel:rw- {} \;
502

503
504
#creating log file
if [ ! -e "/var/log/alternc/bureau.log" ]; then
505
  test -d "/var/log/alternc/" || mkdir -p "/var/log/alternc/"
506
507
508
  touch "/var/log/alternc/bureau.log"
fi

509
510
511
512
513
if [ ! -e "/var/log/alternc/update_domains.log" ]; then
  test -d "/var/log/alternc/" || mkdir -p "/var/log/alternc/"
  touch "/var/log/alternc/update_domains.log"
fi

Alan Garcia's avatar
Alan Garcia committed
514
515
516
517
# Be sure of the owner of the logs files
chmod 640 /var/log/alternc/bureau.log /var/log/alternc/update_domains.log
chown alterncpanel:adm /var/log/alternc/bureau.log /var/log/alternc/update_domains.log

Antoine Beaupré's avatar
Antoine Beaupré committed
518
519
520
# Creating admin user if needed
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`

521
522
523
524
if [ "$HAS_ROOT" != "1" ]; then
    echo "Creating admin user..."
    echo ""

525
    if su - alterncpanel -s /bin/bash -c /usr/share/alternc/install/newone.php
526
527
528
529
530
531
532
533
534
535
536
537
      then
      echo "*******************************************"
      echo "*                                         *"
      echo "*               Admin account             *"
      echo "*               ------------              *"
      echo "*                                         *"
      echo "* user: admin             password: admin *"
      echo "*                                         *"
      echo "* Please change this as soon as possible! *"
      echo "*                                         *"
      echo "*******************************************"
    else
Benjamin Sonntag's avatar
Benjamin Sonntag committed
538
	echo "Unable to create the first AlternC account (named 'admin'). newone.php returned $?. Check your MySQL database, PHP, and the /etc/alternc/local.sh file. Also check for any error above during install."
539
540
541
    fi
fi

542
543
544
545
#giving vmail user read access on dovecot sql file
chgrp vmail /etc/dovecot/dovecot.conf
chmod g+r /etc/dovecot/dovecot.conf

Alan Garcia's avatar
Alan Garcia committed
546
# Changing owner of web panel's files
Alan Garcia's avatar
Hop-là    
Alan Garcia committed
547
chown -R alterncpanel:alterncpanel "/usr/share/alternc/panel/"
Alan Garcia's avatar
Alan Garcia committed
548

549
# We force the re-computing of the DNS zones, since we may have changed the IP address (see #460)
Alan Garcia's avatar
Alan Garcia committed
550
/usr/bin/mysql --defaults-file="/etc/alternc/my.cnf" -B -e "update domaines set dns_action='update';"
551

552
553
554
555
556
# We ensure localhost is trusted to opendkim
mkdir -p "/etc/opendkim/keys"
grep -q "^127.0.0.1\$" /etc/opendkim/TrustedHosts || echo "127.0.0.1" >>/etc/opendkim/TrustedHosts
grep -q "^localhost\$" /etc/opendkim/TrustedHosts || echo "localhost" >>/etc/opendkim/TrustedHosts

557
558
559
560
561
562
# hook 
run-parts --arg=before-reload /usr/lib/alternc/install.d 

#######################################################################
# Reload services
#
563
for service in postfix bind9 apache2 dovecot cron proftpd opendkim; do
564
565
566
    invoke-rc.d $service force-reload || true
done

567
# We should restart apaches after all configuration stuff ...
568
for service in $SERVICES; do
569
570
    test -x /etc/init.d/$service && invoke-rc.d $service stop || true
done
571
for service in $SERVICES; do
572
    test -x /etc/init.d/$service && invoke-rc.d $service start || true
573
done
574

Alan Garcia's avatar
Alan Garcia committed
575
echo "Fix all the permission. May be quite long..."
576
/usr/lib/alternc/fixperms.sh
577
echo "Compile PO files"
Benjamin Sonntag's avatar
Benjamin Sonntag committed
578
579
580
581
582
583
584
585
586
587

# TODO : includes the .MO in debian package ;) 
find /usr/share/alternc/panel/locales -maxdepth 1 -mindepth 1 -type d -name "*_*" | while read A
do 
    B="$A/LC_MESSAGES"
    cd $B
    rm -f alternc.mo
    msgfmt alternc -o alternc.mo
done

Alan Garcia's avatar
Alan Garcia committed
588
589
590
# Fix some perms
# Fix phpmyadmin import trac#1557
test -d "/var/lib/phpmyadmin/tmp" && dpkg-statoverride --update --add www-data alterncpanel 0775 "/var/lib/phpmyadmin/tmp"
591

592
593
# hook 
run-parts --arg=end /usr/lib/alternc/install.d 
Alan Garcia's avatar
Alan Garcia committed
594

alban's avatar
Oops    
alban committed
595
596
597
# Unlock jobs !
unlock_jobs

598
599
600
# Rebuild all web configuration
/usr/lib/alternc/rebuild_all_webconf.sh --force