Alternc  latest
Alternc logiel libre pour l'hébergement
alternc.install
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # ----------------------------------------------------------------------
4 # AlternC - Web Hosting System
5 # Copyright (C) 2000-2012 by the AlternC Development Team.
6 # https://alternc.org/
7 # ----------------------------------------------------------------------
8 # LICENSE
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License (GPL)
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # To read the license please visit http://www.gnu.org/copyleft/gpl.html
21 # ----------------------------------------------------------------------
22 # Purpose of file: Main install script, launch it anytime ;)
23 # ----------------------------------------------------------------------
24 
25 # Somes check before start operations
26 if [ `id -u` -ne 0 ]; then
27  echo "must be launched as root"
28  exit 1
29 fi
30 
31 for i in $*; do
32  case "$i" in
33  -f|--force)
34  export force=1; shift;;
35  -s|--slave)
36  export slave=1; shift;;
37  --)
38  break;;
39  *)
40  echo "unknown option $i"; shift;;
41  esac
42 done
43 
44 . /usr/lib/alternc/functions.sh
45 
46 # Lock the jobs !
47 lock_jobs
48 
49 # hook
50 run-parts --arg=startup /usr/lib/alternc/install.d
51 
52 #######################################################################
53 # Script configuration
54 #
55 
56 # Configuration template location
57 TEMPLATE_DIR="/etc/alternc/templates"
58 
59 # Find needed configuration files (without the initial '/')
60 # replace this one unconditionnally
61 CONFIG_FILES="etc/alternc/bureau.conf etc/apache2/envvars etc/alternc/apache2.conf etc/alternc/apache_logformat.conf etc/alternc/phpmyadmin.inc.php"
62 
63 if [ -e /etc/bind/named.conf ]; then
64  CONFIG_FILES="$CONFIG_FILES etc/bind/named.conf.options"
65 fi
66 if [ -d /etc/postfix ]; then
67  CONFIG_FILES="$CONFIG_FILES etc/postfix/master.cf etc/postfix/myalias.cf etc/postfix/myrelay.cf
68  etc/postfix/mydomain.cf etc/postfix/myrelay-domain.cf etc/postfix/mymail2mail.cf etc/postfix/mygid.cf etc/postfix/myquota.cf
69  etc/postfix/myvirtual.cf etc/postfix/mytransport.cf etc/postfix/sasl/smtpd.conf
70  etc/alternc/postfix/postfix.cf etc/alternc/postfix/postfix-slave.cf
71  etc/opendkim.conf etc/default/opendkim"
72 fi
73 if [ -e /etc/proftpd/proftpd.conf ]; then
74  CONFIG_FILES="$CONFIG_FILES etc/proftpd/proftpd.conf etc/proftpd/welcome.msg etc/proftpd/modules.conf"
75 fi
76 
77 if [ -e /etc/default/saslauthd ]; then
78  CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
79 fi
80 
81 if [ -e /etc/dovecot/dovecot.conf ]; then
82  CONFIG_FILES="$CONFIG_FILES etc/dovecot/alternc-sql.conf etc/dovecot/alternc-dict-quota.conf etc/dovecot/conf.d/95_alternc.conf"
83 fi
84 
85 INSTALLED_CONFIG_TAR="/var/lib/alternc/backups/etc-installed.tar.gz"
86 
87 #######################################################################
88 # Look for modified configuration files
89 #
90 if [ -f "$INSTALLED_CONFIG_TAR" ]; then
91  CHANGED="`env LANG=C tar -zdf "$INSTALLED_CONFIG_TAR" -C / 2> /dev/null |
92  grep -v 'postfix/main.cf' | grep -v 'Uid differs'|grep -v 'Gid differs' |grep -v 'Mode differs' |
93  sed -e 's#^\([^:]*\).*# /\1#' | sort -u`"
94  if [ ! -z "$CHANGED" ]; then
95  echo "The following configuration files has changed since last AlternC"
96  echo "installation :"
97  echo "$CHANGED"
98  echo ""
99  if [ "$force" = "1" ]; then
100  echo "Replacing them as you requested."
101  else
102  echo "These configuration files should normally be modified by"
103  echo "changing the template in $TEMPLATE_DIR and then calling"
104  echo "$0 to perform the update."
105  echo ""
106  echo "Please examine the situation closely and call '$0 -f'"
107  echo "if you still want to actually overwrite these files."
108  exit 1
109  fi
110  fi
111 fi
112 
113 # Upgrade the DATA and DB SCHEMA
114 /usr/share/alternc/install/upgrade_check.sh
115 # Launch upgrade of alternc modules
116 run-parts --arg=upgrade /usr/lib/alternc/install.d
117 
118 
119 #######################################################################
120 # Prepare template expansions
121 #
122 
123 chown :alterncpanel /etc/alternc/local.sh
124 . /etc/alternc/local.sh
125 
126 # May be missing
127 test -d /var/run/alternc || ( mkdir -p /var/run/alternc && chown alterncpanel:alterncpanel /var/run/alternc )
128 
129 # Create the target directory
130 for i in "$ALTERNC_HTML" "$ALTERNC_MAIL" "$ALTERNC_LOGS" ; do
131  test -d "$i" || mkdir -p "$i"
132 done
133 
134 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
135  test -d "$ALTERNC_HTML/$i" || ( mkdir -p "$ALTERNC_HTML/$i" && chown alterncpanel:alterncpanel "$ALTERNC_HTML/$i" && chmod 775 "$ALTERNC_HTML/$i" )
136  test -d "$ALTERNC_MAIL/$i" || ( mkdir -p "$ALTERNC_MAIL/$i" && chown vmail:vmail "$ALTERNC_MAIL/$i" && chmod 775 "$ALTERNC_MAIL/$i" )
137 done
138 
139 find $ALTERNC_LOGS -maxdepth 1 -type d -exec chown alterncpanel:adm {} \;
140 find $ALTERNC_HTML -maxdepth 1 -type d -exec chown alterncpanel:alterncpanel {} \;
141 find $ALTERNC_MAIL -maxdepth 1 -type d -exec chown vmail:vmail {} \;
142 
143 # Check ACL
144 aclcheckfile="$ALTERNC_HTML/test-acl"
145 touch "$aclcheckfile"
146 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)
147 test -e "$aclcheckfile" && rm -f "$aclcheckfile"
148 
149 # XXX: copy-paste from debian/config
150 if [ -r /etc/alternc/my.cnf ]; then
151  # make mysql configuration available as shell variables
152  # to convert from .cnf to shell syntax, we:
153  # * match only lines with "equal" in them (/=/)
154  # * remove whitespace around the = and add a left quote operator ' (;s)
155  # * add a right quote operator at the end of line (;s)
156  # * convert mysql variables into our MYSQL_ naming convention (;s)
157  # * print the result (;p)
158  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`
159  chown root:alterncpanel /etc/alternc/my.cnf
160  chmod 640 /etc/alternc/my.cnf
161 fi
162 
163 if [ -r /etc/alternc/my_mail.cnf ]; then
164  # make mysql configuration available as shell variables
165  # to convert from .cnf to shell syntax, we:
166  # * match only lines with "equal" in them (/=/)
167  # * remove whitespace around the = and add a left quote operator ' (;s)
168  # * add a right quote operator at the end of line (;s)
169  # * convert mysql variables into our MYSQL_ naming convention (;s)
170  # * print the result (;p)
171  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`
172  chown root:alterncpanel /etc/alternc/my_mail.cnf
173  chmod 640 /etc/alternc/my_mail.cnf
174 fi
175 
176 WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
177 
178 if [ "$slave" = "1" ]; then
179  VERSION="`dpkg -s alternc-slave | sed -n -e 's/^Version: \(.*\)/\1/p'`"
180 else
181  VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
182 fi
183 
184 # /var/ alternc/dns/d/www.example.com
185 FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
186 if [ "$FQDN_LETTER" = "$FQDN" ]
187 then
188  FQDN_LETTER="_"
189 fi
190 
191 NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
192  @ip = unpack('C4', \\$h);
193  print join (\".\", @ip);"`
194 
195 if [ -z "$MONITOR_IP" ]; then
196  MONITOR_IP="127.0.0.1"
197 fi
198 
199 PUBLIC_IP_BEGIN=$(echo $PUBLIC_IP|cut -c 1)
200 
201 # Secret for PhpMyAdmin sessions
202 PHPMYADMIN_BLOWFISH="$(generate_string 24)"
203 
204 # XXX: I assume this is secure if /tmp is sticky (+t)
205 # we should have a better way to deal with templating, of course.
206 SED_SCRIPT="/tmp/alternc.install.sedscript"
207 cat > $SED_SCRIPT <<EOF
208 s\\%%hosting%%\\$HOSTING\\;
209 s\\%%fqdn%%\\$FQDN\\;
210 s\\%%public_ip%%\\$PUBLIC_IP\\;
211 s\\%%public_ip_begin%%\\$PUBLIC_IP_BEGIN\\;
212 s\\%%internal_ip%%\\$INTERNAL_IP\\;
213 s\\%%monitor_ip%%\\$MONITOR_IP\\;
214 s\\%%ns1%%\\$NS1_HOSTNAME\\;
215 s\\%%ns2%%\\$NS2_HOSTNAME\\;
216 s\\%%mx%%\\$DEFAULT_MX\\;
217 s\\%%dbhost%%\\$MYSQL_HOST\\;
218 s\\%%dbname%%\\$MYSQL_DATABASE\\;
219 s\\%%dbuser%%\\$MYSQL_USER\\;
220 s\\%%dbpwd%%\\$MYSQL_PASS\\;
221 s\\%%db_mail_user%%\\$MYSQL_MAIL_USER\\;
222 s\\%%db_mail_pwd%%\\$MYSQL_MAIL_PASS\\;
223 s\\%%warning_message%%\\$WARNING\\;
224 s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
225 s\\%%version%%\\$VERSION\\;
226 s\\%%ns2_ip%%\\$NS2_IP\\;
227 s\\%%ALTERNC_HTML%%\\$ALTERNC_HTML\\;
228 s\\%%ALTERNC_MAIL%%\\$ALTERNC_MAIL\\;
229 s\\%%ALTERNC_LOGS%%\\$ALTERNC_LOGS\\;
230 s\\%%PHPMYADMIN_BLOWFISH%%\\$PHPMYADMIN_BLOWFISH\\;
231 EOF
232 
233 # hook
234 test -d /usr/lib/alternc/install.d || mkdir -p /usr/lib/alternc/install.d
235 run-parts --arg=templates /usr/lib/alternc/install.d
236 
237 
238 ######################################################################
239 # Backup the Main database
240 DB_BACKUP="/var/lib/alternc/backups/${MYSQL_DATABASE}-db-`date +%Y%m%d-%H:%M:%S`.gz"
241 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}"
242 $db_dump | /bin/gzip -c > $DB_BACKUP || echo "backup of the main database failed"
243 
244 #######################################################################
245 # Backup configuration files
246 #
247 BACKUP_FILE="/var/lib/alternc/backups/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
248 
249 # Only backup what we are really going to replace
250 BACKUPS=""
251 for file in $CONFIG_FILES; do
252  TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
253  if [ -f "$TEMPLATE" ]; then
254  BACKUPS="$BACKUPS $file"
255  fi
256 done
257 
258 # also backup main.cf since we're doing major changes to it
259 BACKUPS="$BACKUPS etc/postfix/main.cf"
260 
261 tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
262 chmod 600 "$BACKUP_FILE"
263 
264 #######################################################################
265 # Expand templates in the right place
266 #
267 echo -n "Expanding variables in configuration files:"
268 for file in $CONFIG_FILES; do
269  TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
270  echo -n " $file"
271  if [ -f "$TEMPLATE" ]; then
272  sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
273  fi
274 done
275 echo "."
276 rm -f $SED_SCRIPT
277 
278 ########################################################################
279 # Ad-hoc fixes
280 #
281 
282 php="`ls /usr/lib/apache*/*/*php*.so | sed -e 's/^.*libphp\(.*\)\.so$/\1/' | tail -1`"
283 if [ "$php" = "7.0" ]
284 then
285  ln -fs /etc/alternc/alternc.ini /etc/php/$php/apache2/conf.d/alternc.ini || true
286  ln -fs /etc/alternc/alternc.ini /etc/php/$php/cli/conf.d/alternc.ini || true
287 else
288  ln -fs /etc/alternc/alternc.ini /etc/php$php/apache2/conf.d/alternc.ini || true
289  ln -fs /etc/alternc/alternc.ini /etc/php$php/cli/conf.d/alternc.ini || true
290 fi
291 
292 if [ -x /usr/sbin/apache2 ]; then
293  # hook
294  run-parts --arg=apache2 /usr/lib/alternc/install.d
295  a2enmod mpm_itk
296 
297  s=""
298  # unused from AlternC 1.0, FIXME: remove it later
299  if [ -L /etc/apache2/mods-enabled/vhost_alias.load ]
300  then
301  a2dismod vhost_alias
302  s="apache2"
303  fi
304  if ! [ -L /etc/apache2/mods-enabled/php$php.load ]
305  then
306  a2enmod php$php
307  fi
308  if ! [ -L /etc/apache2/mods-enabled/rewrite.load ]
309  then
310  a2enmod rewrite
311  fi
312  if [ -e /etc/alternc/apache.pem ]; then
313  # We enable proftpd tls module
314  cat /etc/proftpd/modules.conf | sed -e 's/^#LoadModule mod_tls.c/LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
315  mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
316  cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
317  # We enable apache2 SSL :
318  if [ ! -L /etc/apache2/mods-enabled/ssl.load ] ; then
319  a2enmod ssl
320  s="apache2"
321  fi
322  if [ ! -h /etc/apache2/conf-available/alternc-ssl.conf ] && [ -e /etc/apache2/conf-available/ ]; then
323  ln -sf /etc/alternc/apache2-ssl.conf /etc/apache2/conf-available/alternc-ssl.conf
324  a2enconf alternc-ssl
325  s="apache2"
326  fi
327 
328  # We enable dovecot SSL certificate instructions: (on wheezy we should use a new file in /etc/dovecot/conf.d/ )
329  ( echo "# Don't change this file, it will be overwriten by alternc.install. Change ssl parameters in a file named 99_ssl.conf instead" ; echo "ssl_cert = </etc/alternc/apache.pem" ; echo "ssl_key = </etc/alternc/apache.pem" ) >/etc/dovecot/conf.d/96_ssl.conf
330 
331  else
332  # We disable proftpd tls module
333  cat /etc/proftpd/modules.conf | sed -e 's/^LoadModule mod_tls.c/#LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
334  mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
335  cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
336 
337  # We disable dovecot SSL certificate instructions: (on wheezy we should remove a file in /etc/dovecot/conf.d/ )
338  ( echo "# Don't change this file, it will be overwriten by alternc.install. Change ssl parameters in a file named 99_ssl.conf instead" ; echo "ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem" ; echo "ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key" ) >/etc/dovecot/conf.d/96_ssl.conf
339 
340  echo "SSL not configured"
341  echo "create a certificate in /etc/alternc/apache.pem and rerun alternc.install"
342  fi
343  if [ ! -h /etc/apache2/conf-available/alternc.conf ] && [ -e /etc/apache2/conf-available/ ]; then
344  ln -sf /etc/alternc/apache2.conf /etc/apache2/conf-available/alternc.conf
345  a2enconf alternc.conf
346  s="apache2"
347  fi
348  if [ -e /etc/apache2/sites-enabled/000-default.conf ]; then
349  a2dissite 000-default
350  s="apache2"
351  fi
352  SERVICES="$SERVICES $s"
353 fi
354 
355 # Manage sudoers.d include appearing in Squeeze:
356 # if the "includedir" is not here, we add it ONLY IF visudo -c is happy.
357 if ! grep -q "#includedir */etc/sudoers.d" /etc/sudoers ; then
358  if ! cat /etc/sudoers.d/* | visudo -c -f - >/dev/null ; then
359  echo -e "\033[31m**********************************************"
360  echo "* *"
361  echo "* ALTERNC ACTION REQUESTED *"
362  echo "* *"
363  echo "* SUDO is NOT configured properly *"
364  echo "* check your files in /etc/sudoers.d ! *"
365  echo "* then launch alternc.install again *"
366  echo "* *"
367  echo "**********************************************"
368  echo -e "\033[0m"
369  exit 1
370  else
371  echo "#includedir */etc/sudoers.d" >>/etc/sudoers
372  fi
373 fi
374 
375 # Copy postfix *_checks if they do not exist
376 for file in body_checks header_checks; do
377  if [ ! -e "/etc/postfix/$file" ]; then
378  cp /usr/share/alternc/install/$file /etc/postfix
379  fi
380 done
381 
382 # Attribute the correct rights to critical postfix files
383 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
384  chown root:postfix /etc/postfix/my*
385  chmod 640 /etc/postfix/my*
386 fi
387 
388 if [ ! -f /etc/postfix/main.cf ]
389 then
390  echo -e "\033[31m**********************************************"
391  echo "* *"
392  echo "* ALTERNC ACTION REQUESTED *"
393  echo "* *"
394  echo "* POSTFIX is NOT configured properly *"
395  echo "* launch dpkg-reconfigure -plow postfix *"
396  echo "* and choose 'Internet Site' *"
397  echo "* then launch alternc.install again *"
398  echo "* *"
399  echo "**********************************************"
400  echo -e "\033[0m"
401  exit 1
402 fi
403 
404 # configure Postfix appropriatly for our needs
405 if [ "$slave" = "1" ]; then
406  postfix_conf=/etc/alternc/postfix/postfix-slave.cf
407 else
408  postfix_conf=/etc/alternc/postfix/postfix.cf
409 fi
410 grep -v '^\ *#' $postfix_conf |while read line ; do
411  if echo "$line" | grep -qi '^smtpd_tls_dcert_file' ;then
412  line_strip=`echo "$line"|tr -d '[:blank:]'`
413  pattern="*="
414  cert_file=${line_strip#$pattern}
415  echo $cert_file
416  echo $line
417  echo $line_strip
418  if [ -e $cert_file ];then
419  postconf -e "$line"
420  else
421  echo -e "\033[31m*****************************************************"
422  echo "* The certificate file : $cert_file does not exists *"
423  echo "* If you want to be able to use SSL/TLS *"
424  echo "* please go to https://alternc.com/SSL *"
425  echo "* to get information on how to create a certificate *"
426  echo "* Finally relaunch alternc.install *"
427  echo "*****************************************************"
428  echo -e "\033[0m"
429  fi
430  else
431  postconf -e "$line"
432  fi
433 done
434 
435 # Conviguring delivery used by Postfix
436 /usr/lib/alternc/alternc_add_policy_dovecot
437 
438 # Bug #1215: configure mydestination when $FQDN is not in
439 OLDDESTINATION=`postconf mydestination | awk -F '=' '{print $2}'`
440 echo "$OLDDESTINATION" | grep -q -v "$FQDN" && postconf -e "mydestination = $FQDN, $OLDDESTINATION"
441 
442 # Remove phpmyadmin apache2 configuration
443 a2disconf phpmyadmin
444 
445 # Configure PHPMyAdmin
446 include_str='include("/etc/alternc/phpmyadmin.inc.php")'
447 pma_config='/etc/phpmyadmin/config.inc.php'
448 
449 # Sur une configuration vierge, inclure la configuration alternc
450 if ! grep -e "${include_str/\"/\\\"}" $pma_config > /dev/null 2>&1; then
451  echo "$include_str;" >> $pma_config
452 fi
453 
454 # Le template de /etc/alternc/phpmyadmin.inc.php viens d'être réappliqué, on
455 # regénére la liste des serveurs MySQL disponible dedans.
456 mysql_query "select id,host,name from db_servers;" | while read id host name ; do
457 echo "
458 // Server #$id in db_servers
459 \$i++;
460 \$cfg['Servers'][\$i]['connect_type'] = 'tcp'; // How to connect to MySQL server ('tcp' or 'socket')
461 \$cfg['Servers'][\$i]['auth_type'] = 'cookie'; // Authentication method (config, http or cookie based)?
462 \$cfg['Servers'][\$i]['hide_db'] = 'information_schema';
463 \$cfg['Servers'][\$i]['verbose'] = '$name'; // human name
464 \$cfg['Servers'][\$i]['host'] = '$host'; // MySQL hostname or IP address
465 " >> '/etc/alternc/phpmyadmin.inc.php'
466 done
467 
468 # Reload incron. Useless, but who know?
469 SERVICES="$SERVICES incron"
470 
471 if [ -e /etc/proftpd.conf ] ; then
472  chmod 640 /etc/proftpd/proftpd.conf
473 fi
474 
475 if [ -x /usr/sbin/locale-gen ] ; then
476  touch /etc/locale.gen
477  LOCALECHANGED=""
478  # Add de_DE ISO-8859-1, en_US ISO-8859-1, es_ES ISO-8859-1, fr_FR ISO-8859-1 to the locales :
479  if ! grep -q "^de_DE ISO-8859-1$" /etc/locale.gen ; then
480  echo "de_DE ISO-8859-1" >>/etc/locale.gen
481  LOCALECHANGED=1
482  fi
483  if ! grep -q "^en_US ISO-8859-1$" /etc/locale.gen ; then
484  echo "en_US ISO-8859-1" >>/etc/locale.gen
485  LOCALECHANGED=1
486  fi
487  if ! grep -q "^es_ES ISO-8859-1$" /etc/locale.gen ; then
488  echo "es_ES ISO-8859-1" >>/etc/locale.gen
489  LOCALECHANGED=1
490  fi
491  if ! grep -q "^fr_FR ISO-8859-1$" /etc/locale.gen ; then
492  echo "fr_FR ISO-8859-1" >>/etc/locale.gen
493  LOCALECHANGED=1
494  fi
495  if ! grep -q "^de_DE.UTF-8 UTF-8$" /etc/locale.gen ; then
496  echo "de_DE.UTF-8 UTF-8" >>/etc/locale.gen
497  LOCALECHANGED=1
498  fi
499  if ! grep -q "^fr_FR.UTF-8 UTF-8$" /etc/locale.gen ; then
500  echo "fr_FR.UTF-8 UTF-8" >>/etc/locale.gen
501  LOCALECHANGED=1
502  fi
503  if ! grep -q "^es_ES.UTF-8 UTF-8$" /etc/locale.gen ; then
504  echo "es_ES.UTF-8 UTF-8" >>/etc/locale.gen
505  LOCALECHANGED=1
506  fi
507  if ! grep -q "^en_US.UTF-8 UTF-8$" /etc/locale.gen ; then
508  echo "en_US.UTF-8 UTF-8" >>/etc/locale.gen
509  LOCALECHANGED=1
510  fi
511  if ! grep -q "^it_IT.UTF-8 UTF-8$" /etc/locale.gen ; then
512  echo "it_IT.UTF-8 UTF-8" >>/etc/locale.gen
513  LOCALECHANGED=1
514  fi
515  if ! grep -q "^nl_NL.UTF-8 UTF-8$" /etc/locale.gen ; then
516  echo "nl_NL.UTF-8 UTF-8" >>/etc/locale.gen
517  LOCALECHANGED=1
518  fi
519  if [ "$LOCALECHANGED" ] ; then
520  locale-gen
521  fi
522 fi
523 
524 # remaining steps are only for the master
525 if [ "$slave" = "1" ]; then
526  exit 0
527 fi
528 
529 #######################################################################
530 # populate alternc database with the mailname used by postfix to send mail for each vhost
531 #
532 # If mailname does not exist, create it. Fix #1495
533 test -e "/etc/mailname" || hostname -f > "/etc/mailname"
534 # Allow for all the users to view /etc/mailname
535 chmod +r "/etc/mailname"
536 
537 #######################################################################
538 # Save installed files to check them during next install
539 #
540 tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
541 
542 #######################################################################
543 # Last touches
544 #
545 
546 find $ALTERNC_HTML -maxdepth 1 -type d -exec setfacl -b -k -m d:g:alterncpanel:-wx -m d:u:alterncpanel:-wx -m u:alterncpanel:-wx -m g:alterncpanel:-wx {} \;
547 
548 #creating log file
549 if [ ! -e "/var/log/alternc/bureau.log" ]; then
550  test -d "/var/log/alternc/" || mkdir -p "/var/log/alternc/"
551  touch "/var/log/alternc/bureau.log"
552 fi
553 
554 if [ ! -e "/var/log/alternc/update_domains.log" ]; then
555  test -d "/var/log/alternc/" || mkdir -p "/var/log/alternc/"
556  touch "/var/log/alternc/update_domains.log"
557 fi
558 
559 # Be sure of the owner of the logs files
560 chmod 640 /var/log/alternc/bureau.log /var/log/alternc/update_domains.log
561 chown alterncpanel:adm /var/log/alternc/bureau.log /var/log/alternc/update_domains.log
562 
563 # Creating admin user if needed
564 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`
565 
566 if [ "$HAS_ROOT" != "1" ]; then
567  echo "Creating admin user..."
568  echo ""
569 
570  if su - alterncpanel -s /bin/bash -c /usr/share/alternc/install/newone.php
571  then
572  echo "*******************************************"
573  echo "* *"
574  echo "* Admin account *"
575  echo "* ------------ *"
576  echo "* *"
577  echo "* user: admin password: admin *"
578  echo "* *"
579  echo "* Please change this as soon as possible! *"
580  echo "* *"
581  echo "*******************************************"
582  else
583  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."
584  fi
585 else
586  ##UPDATE default db_server following /etc/alternc/my.cnf values
587  if [ "$MYSQL_HOST" == "localhost" ]; then
588  MYSQL_HOST_CLIENT="localhost"
589  else
590  MYSQL_HOST_CLIENT="%"
591  fi
592  mysql --defaults-file=/etc/alternc/my.cnf -e "UPDATE db_servers SET host='$MYSQL_HOST', login='$MYSQL_USER', password='$MYSQL_PASS', client='$MYSQL_HOST_CLIENT' WHERE name='Default';"
593 fi
594 
595 # giving vmail user read access on dovecot sql file
596 chgrp vmail /etc/dovecot/alternc-sql.conf
597 chmod g+r /etc/dovecot/alternc-sql.conf
598 # Override some dovecot 2.0 configuration that may have happened during dovecot postinst:
599 sed -i -e 's/^ *!include/#!include/' /etc/dovecot/conf.d/10-auth.conf
600 
601 # Changing owner of web panel's files
602 chown -R alterncpanel:alterncpanel "/usr/share/alternc/panel/"
603 
604 # We force the re-computing of the DNS zones, since we may have changed the IP address (see #460)
605 /usr/bin/mysql --defaults-file="/etc/alternc/my.cnf" -B -e "update domaines set dns_action='UPDATE' WHERE gesdns=1;"
606 
607 # We ensure localhost is trusted to opendkim
608 mkdir -p "/etc/opendkim/keys"
609 touch /etc/opendkim/TrustedHosts /etc/opendkim/SigningTable /etc/opendkim/KeyTable
610 grep -q "^127.0.0.1\$" /etc/opendkim/TrustedHosts || echo "127.0.0.1" >>/etc/opendkim/TrustedHosts
611 grep -q "^localhost\$" /etc/opendkim/TrustedHosts || echo "localhost" >>/etc/opendkim/TrustedHosts
612 grep -q "^$PUBLIC_IP\$" /etc/opendkim/TrustedHosts || echo "$PUBLIC_IP" >>/etc/opendkim/TrustedHosts
613 
614 # Add opendkim to service to restart
615 SERVICES="$SERVICES opendkim bind9"
616 
617 # hook
618 run-parts --arg=before-reload /usr/lib/alternc/install.d
619 
620 #######################################################################
621 # Reload services
622 #
623 for service in postfix dovecot cron proftpd ; do
624  invoke-rc.d $service force-reload || true
625 done
626 
627 # We should restart apaches after all configuration stuff ...
628 for service in $SERVICES; do
629  test -x /etc/init.d/$service && invoke-rc.d $service stop || true
630 done
631 
632 # on Jessie, apache2 does not stop/start properly due to "service" and "apache2ctl" having different behavior pid-file-wise
633 killall apache2
634 
635 for service in $SERVICES; do
636  test -x /etc/init.d/$service && invoke-rc.d $service start || true
637 done
638 
639 echo "Fix all the permission. May be quite long..."
640 echo "YOU CAN INTERUPT THIS BY USING Ctrl-c THEN y TO BYPASS THE ERROR."
641 /usr/lib/alternc/fixperms.sh
642 echo "Compile PO files"
643 
644 # TODO : includes the .MO in debian package ;)
645 find /usr/share/alternc/panel/locales -maxdepth 1 -mindepth 1 -type d -name "*_*" | while read A
646 do
647  B="$A/LC_MESSAGES"
648  cd $B
649  rm -f alternc.mo alternc.po
650  msgcat --use-first *.po alternc >alternc.po
651  msgfmt alternc.po -o alternc.mo
652 done
653 
654 # Fix some perms
655 # Fix phpmyadmin import trac#1557
656 test -d "/var/lib/phpmyadmin/tmp" && dpkg-statoverride --update --add www-data alterncpanel 0775 "/var/lib/phpmyadmin/tmp" 2>/dev/null || true
657 test -f "/etc/phpmyadmin/config-db.php" && dpkg-statoverride --update --add www-data alterncpanel 0644 "/etc/phpmyadmin/config-db.php" 2>/dev/null || true
658 
659 # hook
660 run-parts --arg=end /usr/lib/alternc/install.d
661 
662 # Unlock jobs !
663 unlock_jobs
664 
665 # Rebuild all web configuration
666 /usr/lib/alternc/rebuild_all_webconf.sh --force