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/dovecot.conf etc/dovecot/dovecot-sql.conf etc/dovecot/dovecot-dict-quota.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$/php\1/' | tail -1`"
283 ln -fs /etc/alternc/alternc.ini /etc/$php/apache2/conf.d/alternc.ini || true
284 ln -fs /etc/alternc/alternc.ini /etc/$php/cli/conf.d/alternc.ini || true
285 if [ -x /usr/sbin/apache2 ]; then
286  # hook
287  run-parts --arg=apache2 /usr/lib/alternc/install.d
288 
289  s=""
290  # unused from AlternC 1.0, FIXME: remove it later
291  if [ -L /etc/apache2/mods-enabled/vhost_alias.load ]
292  then
293  a2dismod vhost_alias
294  s="apache2"
295  fi
296  if ! [ -L /etc/apache2/mods-enabled/$php.load ]
297  then
298  a2enmod $php
299  fi
300  if ! [ -L /etc/apache2/mods-enabled/rewrite.load ]
301  then
302  a2enmod rewrite
303  fi
304  if [ -e /etc/alternc/apache.pem ]; then
305  # We enable proftpd tls module
306  cat /etc/proftpd/modules.conf | sed -e 's/^#LoadModule mod_tls.c/LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
307  mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
308  cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
309  # We enable apache2 SSL :
310  if [ ! -L /etc/apache2/mods-enabled/ssl.load ] ; then
311  a2enmod ssl
312  s="apache2"
313  fi
314  if [ ! -h /etc/apache2/conf.d/alternc-ssl.conf ] && [ -e /etc/apache2/conf.d/ ]; then
315  ln -sf /etc/alternc/apache2-ssl.conf /etc/apache2/conf.d/alternc-ssl.conf
316  s="apache2"
317  fi
318 
319  # We enable dovecot SSL certificate instructions: (on wheezy we should use a new file in /etc/dovecot/conf.d/ )
320  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
321 
322  else
323  # We disable proftpd tls module
324  cat /etc/proftpd/modules.conf | sed -e 's/^LoadModule mod_tls.c/#LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
325  mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
326  cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
327 
328  # We disable dovecot SSL certificate instructions: (on wheezy we should remove a file in /etc/dovecot/conf.d/ )
329  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
330 
331  echo "SSL not configured"
332  echo "create a certificate in /etc/alternc/apache.pem and rerun alternc.install"
333  fi
334  if [ ! -h /etc/apache2/conf.d/alternc.conf ] && [ -e /etc/apache2/conf.d/ ]; then
335  ln -sf /etc/alternc/apache2.conf /etc/apache2/conf.d/alternc.conf
336  s="apache2"
337  fi
338  if [ -e /etc/apache2/sites-enabled/000-default ]; then
339  a2dissite default
340  s="apache2"
341  fi
342  SERVICES="$SERVICES $s"
343 fi
344 
345 # Manage sudoers.d include appearing in Squeeze:
346 # if the "includedir" is not here, we add it ONLY IF visudo -c is happy.
347 if ! grep -q "#includedir */etc/sudoers.d" /etc/sudoers ; then
348  if ! cat /etc/sudoers.d/* | visudo -c -f - >/dev/null ; then
349  echo -e "\033[31m**********************************************"
350  echo "* *"
351  echo "* ALTERNC ACTION REQUESTED *"
352  echo "* *"
353  echo "* SUDO is NOT configured properly *"
354  echo "* check your files in /etc/sudoers.d ! *"
355  echo "* then launch alternc.install again *"
356  echo "* *"
357  echo "**********************************************"
358  echo -e "\033[0m"
359  exit 1
360  else
361  echo "#includedir */etc/sudoers.d" >>/etc/sudoers
362  fi
363 fi
364 
365 # Copy postfix *_checks if they do not exist
366 for file in body_checks header_checks; do
367  if [ ! -e "/etc/postfix/$file" ]; then
368  cp /usr/share/alternc/install/$file /etc/postfix
369  fi
370 done
371 
372 # Attribute the correct rights to critical postfix files
373 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
374  chown root:postfix /etc/postfix/my*
375  chmod 640 /etc/postfix/my*
376 fi
377 
378 if [ ! -f /etc/postfix/main.cf ]
379 then
380  echo -e "\033[31m**********************************************"
381  echo "* *"
382  echo "* ALTERNC ACTION REQUESTED *"
383  echo "* *"
384  echo "* POSTFIX is NOT configured properly *"
385  echo "* launch dpkg-reconfigure -plow postfix *"
386  echo "* and choose 'Internet Site' *"
387  echo "* then launch alternc.install again *"
388  echo "* *"
389  echo "**********************************************"
390  echo -e "\033[0m"
391  exit 1
392 fi
393 
394 # configure Postfix appropriatly for our needs
395 if [ "$slave" = "1" ]; then
396  postfix_conf=/etc/alternc/postfix/postfix-slave.cf
397 else
398  postfix_conf=/etc/alternc/postfix/postfix.cf
399 fi
400 grep -v '^\ *#' $postfix_conf |while read line ; do
401  if echo "$line" | grep -qi '^smtpd_tls_dcert_file' ;then
402  line_strip=`echo "$line"|tr -d '[:blank:]'`
403  pattern="*="
404  cert_file=${line_strip#$pattern}
405  echo $cert_file
406  echo $line
407  echo $line_strip
408  if [ -e $cert_file ];then
409  postconf -e "$line"
410  else
411  echo -e "\033[31m*****************************************************"
412  echo "* The certificate file : $cert_file does not exists *"
413  echo "* If you want to be able to use SSL/TLS *"
414  echo "* please go to https://alternc.com/SSL *"
415  echo "* to get information on how to create a certificate *"
416  echo "* Finally relaunch alternc.install *"
417  echo "*****************************************************"
418  echo -e "\033[0m"
419  fi
420  else
421  postconf -e "$line"
422  fi
423 done
424 
425 # Conviguring delivery used by Postfix
426 /usr/lib/alternc/alternc_add_policy_dovecot
427 
428 # Bug #1215: configure mydestination when $FQDN is not in
429 OLDDESTINATION=`postconf mydestination | awk -F '=' '{print $2}'`
430 echo "$OLDDESTINATION" | grep -q -v "$FQDN" && postconf -e "mydestination = $FQDN, $OLDDESTINATION"
431 
432 # Remove phpmyadmin apache2 configuration
433 rm -f /etc/apache2/conf.d/phpmyadmin.conf || true
434 
435 # Configure PHPMyAdmin
436 include_str='include("/etc/alternc/phpmyadmin.inc.php")'
437 pma_config='/etc/phpmyadmin/config.inc.php'
438 
439 # Sur une configuration vierge, inclure la configuration alternc
440 if ! grep -e "${include_str/\"/\\\"}" $pma_config > /dev/null 2>&1; then
441  echo "$include_str;" >> $pma_config
442 fi
443 
444 # Le template de /etc/alternc/phpmyadmin.inc.php viens d'être réappliqué, on
445 # regénére la liste des serveurs MySQL disponible dedans.
446 mysql_query "select id,host,name from db_servers;" | while read id host name ; do
447 echo "
448 // Server #$id in db_servers
449 \$i++;
450 \$cfg['Servers'][\$i]['connect_type'] = 'tcp'; // How to connect to MySQL server ('tcp' or 'socket')
451 \$cfg['Servers'][\$i]['auth_type'] = 'cookie'; // Authentication method (config, http or cookie based)?
452 \$cfg['Servers'][\$i]['hide_db'] = 'information_schema';
453 \$cfg['Servers'][\$i]['verbose'] = '$name'; // human name
454 \$cfg['Servers'][\$i]['host'] = '$host'; // MySQL hostname or IP address
455 " >> '/etc/alternc/phpmyadmin.inc.php'
456 done
457 
458 # Reload incron. Useless, but who know?
459 SERVICES="$SERVICES incron"
460 
461 if [ -e /etc/proftpd.conf ] ; then
462  chmod 640 /etc/proftpd/proftpd.conf
463 fi
464 
465 if [ -x /usr/sbin/locale-gen ] ; then
466  touch /etc/locale.gen
467  LOCALECHANGED=""
468  # Add de_DE ISO-8859-1, en_US ISO-8859-1, es_ES ISO-8859-1, fr_FR ISO-8859-1 to the locales :
469  if ! grep -q "^de_DE ISO-8859-1$" /etc/locale.gen ; then
470  echo "de_DE ISO-8859-1" >>/etc/locale.gen
471  LOCALECHANGED=1
472  fi
473  if ! grep -q "^en_US ISO-8859-1$" /etc/locale.gen ; then
474  echo "en_US ISO-8859-1" >>/etc/locale.gen
475  LOCALECHANGED=1
476  fi
477  if ! grep -q "^es_ES ISO-8859-1$" /etc/locale.gen ; then
478  echo "es_ES ISO-8859-1" >>/etc/locale.gen
479  LOCALECHANGED=1
480  fi
481  if ! grep -q "^fr_FR ISO-8859-1$" /etc/locale.gen ; then
482  echo "fr_FR ISO-8859-1" >>/etc/locale.gen
483  LOCALECHANGED=1
484  fi
485  if ! grep -q "^de_DE.UTF-8 UTF-8$" /etc/locale.gen ; then
486  echo "de_DE.UTF-8 UTF-8" >>/etc/locale.gen
487  LOCALECHANGED=1
488  fi
489  if ! grep -q "^fr_FR.UTF-8 UTF-8$" /etc/locale.gen ; then
490  echo "fr_FR.UTF-8 UTF-8" >>/etc/locale.gen
491  LOCALECHANGED=1
492  fi
493  if ! grep -q "^es_ES.UTF-8 UTF-8$" /etc/locale.gen ; then
494  echo "es_ES.UTF-8 UTF-8" >>/etc/locale.gen
495  LOCALECHANGED=1
496  fi
497  if ! grep -q "^en_US.UTF-8 UTF-8$" /etc/locale.gen ; then
498  echo "en_US.UTF-8 UTF-8" >>/etc/locale.gen
499  LOCALECHANGED=1
500  fi
501  if ! grep -q "^it_IT.UTF-8 UTF-8$" /etc/locale.gen ; then
502  echo "it_IT.UTF-8 UTF-8" >>/etc/locale.gen
503  LOCALECHANGED=1
504  fi
505  if ! grep -q "^nl_NL.UTF-8 UTF-8$" /etc/locale.gen ; then
506  echo "nl_NL.UTF-8 UTF-8" >>/etc/locale.gen
507  LOCALECHANGED=1
508  fi
509  if [ "$LOCALECHANGED" ] ; then
510  locale-gen
511  fi
512 fi
513 
514 # remaining steps are only for the master
515 if [ "$slave" = "1" ]; then
516  exit 0
517 fi
518 
519 #######################################################################
520 # populate alternc database with the mailname used by postfix to send mail for each vhost
521 #
522 # If mailname does not exist, create it. Fix #1495
523 test -e "/etc/mailname" || hostname -f > "/etc/mailname"
524 # Allow for all the users to view /etc/mailname
525 chmod +r "/etc/mailname"
526 
527 #######################################################################
528 # Save installed files to check them during next install
529 #
530 tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
531 
532 #######################################################################
533 # Last touches
534 #
535 
536 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 {} \;
537 
538 #creating log file
539 if [ ! -e "/var/log/alternc/bureau.log" ]; then
540  test -d "/var/log/alternc/" || mkdir -p "/var/log/alternc/"
541  touch "/var/log/alternc/bureau.log"
542 fi
543 
544 if [ ! -e "/var/log/alternc/update_domains.log" ]; then
545  test -d "/var/log/alternc/" || mkdir -p "/var/log/alternc/"
546  touch "/var/log/alternc/update_domains.log"
547 fi
548 
549 # Be sure of the owner of the logs files
550 chmod 640 /var/log/alternc/bureau.log /var/log/alternc/update_domains.log
551 chown alterncpanel:adm /var/log/alternc/bureau.log /var/log/alternc/update_domains.log
552 
553 # Creating admin user if needed
554 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`
555 
556 if [ "$HAS_ROOT" != "1" ]; then
557  echo "Creating admin user..."
558  echo ""
559 
560  if su - alterncpanel -s /bin/bash -c /usr/share/alternc/install/newone.php
561  then
562  echo "*******************************************"
563  echo "* *"
564  echo "* Admin account *"
565  echo "* ------------ *"
566  echo "* *"
567  echo "* user: admin password: admin *"
568  echo "* *"
569  echo "* Please change this as soon as possible! *"
570  echo "* *"
571  echo "*******************************************"
572  else
573  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."
574  fi
575 else
576  ##UPDATE default db_server following /etc/alternc/my.cnf values
577  if [ "$MYSQL_HOST" == "localhost" ]; then
578  MYSQL_HOST_CLIENT="localhost"
579  else
580  MYSQL_HOST_CLIENT="%"
581  fi
582  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';"
583 fi
584 
585 #giving vmail user read access on dovecot sql file
586 chgrp vmail /etc/dovecot/dovecot.conf
587 chmod g+r /etc/dovecot/dovecot.conf
588 
589 # We force the re-computing of the DNS zones, since we may have changed the IP address (see #460)
590 /usr/bin/mysql --defaults-file="/etc/alternc/my.cnf" -B -e "update domaines set dns_action='UPDATE' WHERE gesdns=1;"
591 
592 # We ensure localhost is trusted to opendkim
593 mkdir -p "/etc/opendkim/keys"
594 touch /etc/opendkim/TrustedHosts /etc/opendkim/SigningTable /etc/opendkim/KeyTable
595 grep -q "^127.0.0.1\$" /etc/opendkim/TrustedHosts || echo "127.0.0.1" >>/etc/opendkim/TrustedHosts
596 grep -q "^localhost\$" /etc/opendkim/TrustedHosts || echo "localhost" >>/etc/opendkim/TrustedHosts
597 grep -q "^$PUBLIC_IP\$" /etc/opendkim/TrustedHosts || echo "$PUBLIC_IP" >>/etc/opendkim/TrustedHosts
598 if [ "$(lsb_release -s -c)" == 'stretch' ] ; then
599  /lib/opendkim/opendkim.service.generate
600  # Without adding '-u opendkim' after the service file is generated, opendkim
601  # will run as root, which we do not want.
602  if [ "$(grep -c 'u opendkim' /etc/systemd/system/opendkim.service.d/override.conf)" == 0 ] ; then
603  sed -i -e 's/inet:8891@127.0.0.1/& -u opendkim/' /etc/systemd/system/opendkim.service.d/override.conf
604  fi
605  systemctl daemon-reload
606 fi
607 
608 # Add opendkim to service to restart
609 SERVICES="$SERVICES opendkim"
610 
611 # hook
612 run-parts --arg=before-reload /usr/lib/alternc/install.d
613 
614 #######################################################################
615 # Reload services
616 #
617 for service in postfix bind9 apache2 dovecot cron proftpd ; do
618  invoke-rc.d $service force-reload || true
619 done
620 
621 # We should restart apaches after all configuration stuff ...
622 for service in $SERVICES; do
623  test -x /etc/init.d/$service && invoke-rc.d $service stop || true
624 done
625 for service in $SERVICES; do
626  test -x /etc/init.d/$service && invoke-rc.d $service start || true
627 done
628 
629 echo "Fix all the permission. May be quite long..."
630 echo "YOU CAN INTERUPT THIS BY USING Ctrl-c THEN y TO BYPASS THE ERROR."
631 /usr/lib/alternc/fixperms.sh
632 echo "Compile PO files"
633 
634 # TODO : includes the .MO in debian package ;)
635 find /usr/share/alternc/panel/locales -maxdepth 1 -mindepth 1 -type d -name "*_*" | while read A
636 do
637  B="$A/LC_MESSAGES"
638  cd $B
639  rm -f alternc.mo alternc.po
640  msgcat --use-first *.po alternc >alternc.po
641  msgfmt alternc.po -o alternc.mo
642 done
643 
644 # Fix some perms
645 # Fix phpmyadmin import trac#1557
646 test -d "/var/lib/phpmyadmin/tmp" && dpkg-statoverride --update --add www-data alterncpanel 0775 "/var/lib/phpmyadmin/tmp" 2>/dev/null || true
647 test -f "/etc/phpmyadmin/config-db.php" && dpkg-statoverride --update --add www-data alterncpanel 0644 "/etc/phpmyadmin/config-db.php" 2>/dev/null || true
648 
649 # hook
650 run-parts --arg=end /usr/lib/alternc/install.d
651 
652 # Unlock jobs !
653 unlock_jobs
654 
655 # Rebuild all web configuration
656 /usr/lib/alternc/rebuild_all_webconf.sh --force