Alternc  latest
Alternc logiel libre pour l'hébergement
 All Classes Namespaces Files Functions Variables Pages
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 set -e
32 
33 for i in $*; do
34  case "$i" in
35  -f|--force)
36  export force=1; shift;;
37  -s|--slave)
38  export slave=1; shift;;
39  --)
40  break;;
41  *)
42  echo "unknown option $i"; shift;;
43  esac
44 done
45 
46 . /usr/lib/alternc/functions.sh
47 
48 # hook
49 run-parts --arg=startup /usr/lib/alternc/install.d
50 
51 #######################################################################
52 # Script configuration
53 #
54 
55 # Configuration template location
56 TEMPLATE_DIR="/etc/alternc/templates"
57 
58 # Find needed configuration files (without the initial '/')
59 # replace this one unconditionnally
60 CONFIG_FILES="etc/alternc/bureau.conf etc/incron.d/alternc etc/apache2/envvars etc/alternc/apache2.conf etc/alternc/apache_logformat.conf etc/alternc/phpmyadmin.inc.php"
61 
62 if [ -e /etc/bind/named.conf ]; then
63  CONFIG_FILES="$CONFIG_FILES etc/bind/named.conf.options"
64 fi
65 if [ -d /etc/postfix ]; then
66  CONFIG_FILES="$CONFIG_FILES etc/postfix/master.cf etc/postfix/myalias.cf etc/postfix/myrelay.cf
67  etc/postfix/mydomain.cf etc/postfix/myrelay-domain.cf etc/postfix/mygid.cf etc/postfix/myquota.cf
68  etc/postfix/myvirtual.cf etc/postfix/mytransport.cf etc/postfix/sasl/smtpd.conf
69  etc/alternc/postfix/postfix.cf etc/alternc/postfix/postfix-slave.cf"
70 fi
71 if [ -e /etc/proftpd/proftpd.conf ]; then
72  CONFIG_FILES="$CONFIG_FILES etc/proftpd/proftpd.conf etc/proftpd/welcome.msg etc/proftpd/modules.conf"
73 fi
74 
75 if [ -e /etc/default/saslauthd ]; then
76  CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
77 fi
78 
79 if [ -e /etc/dovecot/dovecot.conf ]; then
80  CONFIG_FILES="$CONFIG_FILES etc/dovecot/alternc-sql.conf etc/dovecot/alternc-dict-quota.conf etc/dovecot/conf.d/95_alternc.conf"
81 fi
82 
83 INSTALLED_CONFIG_TAR="/var/lib/alternc/backups/etc-installed.tar.gz"
84 
85 #######################################################################
86 # Look for modified configuration files
87 #
88 if [ -f "$INSTALLED_CONFIG_TAR" ]; then
89  CHANGED="`env LANG=C tar -zdf "$INSTALLED_CONFIG_TAR" -C / 2> /dev/null |
90  grep -v 'postfix/main.cf' | grep -v 'Uid differs'|grep -v 'Gid differs' |grep -v 'Mode differs' |
91  sed -e 's/^\([^:]*\).*/ \1/' | sort -u`"
92  # " shutup emacs
93  if [ ! -z "$CHANGED" ]; then
94  echo "The following configuration files has changed since last AlternC"
95  echo "installation :"
96  echo "$CHANGED"
97  echo ""
98  if [ "$force" = "1" ]; then
99  echo "Replacing them as you requested."
100  else
101  echo "These configuration files should normally be modified by"
102  echo "changing the template in $TEMPLATE_DIR and then calling"
103  echo "$0 to perform the update."
104  echo ""
105  echo "Please examine the situation closely and call '$0 -f'"
106  echo "if you still want to actually overwrite these files."
107  exit 1
108  fi
109  fi
110 fi
111 
112 #######################################################################
113 # Prepare template expansions
114 #
115 
116 chown :alterncpanel /etc/alternc/local.sh
117 . /etc/alternc/local.sh
118 
119 # Create the target directory
120 for i in "$ALTERNC_HTML" "$ALTERNC_MAIL" "$ALTERNC_LOGS" ; do
121  test -d "$i" || mkdir -p "$i"
122 done
123 
124 find $ALTERNC_LOGS -maxdepth 1 -type d -exec chown alterncpanel:adm {} \;
125 find $ALTERNC_HTML -maxdepth 1 -type d -exec chown alterncpanel:alterncpanel {} \;
126 find $ALTERNC_MAIL -maxdepth 1 -type d -exec chown vmail:vmail {} \;
127 
128 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
129  test -d "$ALTERNC_HTML/$i" || ( mkdir -p "$ALTERNC_HTML/$i" && chown www-data:www-data "$ALTERNC_HTML/$i" )
130  test -d "$ALTERNC_MAIL/$i" || ( mkdir -p "$ALTERNC_MAIL/$i" && chown vmail:vmail "$ALTERNC_MAIL/$i" && chmod 775 "$ALTERNC_MAIL/$i" )
131 done
132 
133 
134 # Check ACL
135 aclcheckfile="$ALTERNC_HTML/test-acl"
136 touch "$aclcheckfile"
137 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)
138 test -e "$aclcheckfile" && rm -f "$aclcheckfile"
139 
140 # XXX: copy-paste from debian/config
141 if [ -r /etc/alternc/my.cnf ]; then
142  # make mysql configuration available as shell variables
143  # to convert from .cnf to shell syntax, we:
144  # * match only lines with "equal" in them (/=/)
145  # * remove whitespace around the = and add a left quote operator ' (;s)
146  # * add a right quote operator at the end of line (;s)
147  # * convert mysql variables into our MYSQL_ naming convention (;s)
148  # * print the result (;p)
149  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`
150  chown root:alterncpanel /etc/alternc/my.cnf
151  chmod 640 /etc/alternc/my.cnf
152 fi
153 
154 if [ -r /etc/alternc/my_mail.cnf ]; then
155  # make mysql configuration available as shell variables
156  # to convert from .cnf to shell syntax, we:
157  # * match only lines with "equal" in them (/=/)
158  # * remove whitespace around the = and add a left quote operator ' (;s)
159  # * add a right quote operator at the end of line (;s)
160  # * convert mysql variables into our MYSQL_ naming convention (;s)
161  # * print the result (;p)
162  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`
163  chown root:alterncpanel /etc/alternc/my_mail.cnf
164  chmod 640 /etc/alternc/my_mail.cnf
165 fi
166 
167 WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
168 
169 if [ "$slave" = "1" ]; then
170  VERSION="`dpkg -s alternc-slave | sed -n -e 's/^Version: \(.*\)/\1/p'`"
171 else
172  VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
173 fi
174 
175 # /var/ alternc/dns/d/www.example.com
176 FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
177 if [ "$FQDN_LETTER" = "$FQDN" ]
178 then
179  FQDN_LETTER="_"
180 fi
181 
182 NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
183  @ip = unpack('C4', \\$h);
184  print join (\".\", @ip);"`
185 
186 if [ -z "$MONITOR_IP" ]; then
187  MONITOR_IP="127.0.0.1"
188 fi
189 
190 PUBLIC_IP_BEGIN=$(echo $PUBLIC_IP|cut -c 1)
191 
192 # Secret for PhpMyAdmin sessions
193 PHPMYADMIN_BLOWFISH="$(generate_string 24)"
194 
195 # XXX: I assume this is secure if /tmp is sticky (+t)
196 # we should have a better way to deal with templating, of course.
197 SED_SCRIPT="/tmp/alternc.install.sedscript"
198 cat > $SED_SCRIPT <<EOF
199 s\\%%hosting%%\\$HOSTING\\;
200 s\\%%fqdn%%\\$FQDN\\;
201 s\\%%public_ip%%\\$PUBLIC_IP\\;
202 s\\%%public_ip_begin%%\\$PUBLIC_IP_BEGIN\\;
203 s\\%%internal_ip%%\\$INTERNAL_IP\\;
204 s\\%%monitor_ip%%\\$MONITOR_IP\\;
205 s\\%%ns1%%\\$NS1_HOSTNAME\\;
206 s\\%%ns2%%\\$NS2_HOSTNAME\\;
207 s\\%%mx%%\\$DEFAULT_MX\\;
208 s\\%%dbhost%%\\$MYSQL_HOST\\;
209 s\\%%dbname%%\\$MYSQL_DATABASE\\;
210 s\\%%dbuser%%\\$MYSQL_USER\\;
211 s\\%%dbpwd%%\\$MYSQL_PASS\\;
212 s\\%%db_mail_user%%\\$MYSQL_MAIL_USER\\;
213 s\\%%db_mail_pwd%%\\$MYSQL_MAIL_PASS\\;
214 s\\%%warning_message%%\\$WARNING\\;
215 s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
216 s\\%%version%%\\$VERSION\\;
217 s\\%%ns2_ip%%\\$NS2_IP\\;
218 s\\%%ALTERNC_HTML%%\\$ALTERNC_HTML\\;
219 s\\%%ALTERNC_MAIL%%\\$ALTERNC_MAIL\\;
220 s\\%%ALTERNC_LOGS%%\\$ALTERNC_LOGS\\;
221 s\\%%PHPMYADMIN_BLOWFISH%%\\$PHPMYADMIN_BLOWFISH\\;
222 EOF
223 
224 # hook
225 test -d /usr/lib/alternc/install.d || mkdir -p /usr/lib/alternc/install.d
226 run-parts --arg=templates /usr/lib/alternc/install.d
227 
228 
229 ######################################################################
230 # Backup the Main database
231 DB_BACKUP="/var/lib/alternc/backups/${MYSQL_DATABASE}-db-`date +%Y%m%d-%H:%M:%S`.gz"
232 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}"
233 $db_dump | /bin/gzip -c > $DB_BACKUP || echo "backup of the main database failed"
234 
235 #######################################################################
236 # Backup configuration files
237 #
238 BACKUP_FILE="/var/lib/alternc/backups/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
239 
240 # Only backup what we are really going to replace
241 BACKUPS=""
242 for file in $CONFIG_FILES; do
243  TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
244  if [ -f "$TEMPLATE" ]; then
245  BACKUPS="$BACKUPS $file"
246  fi
247 done
248 
249 # also backup main.cf since we're doing major changes to it
250 BACKUPS="$BACKUPS etc/postfix/main.cf"
251 
252 tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
253 
254 #######################################################################
255 # Expand templates in the right place
256 #
257 echo -n "Expanding variables in configuration files:"
258 for file in $CONFIG_FILES; do
259  TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
260  echo -n " $file"
261  if [ -f "$TEMPLATE" ]; then
262  sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
263  fi
264 done
265 echo "."
266 rm -f $SED_SCRIPT
267 
268 ########################################################################
269 # Ad-hoc fixes
270 #
271 
272 php="`ls /usr/lib/apache*/*/*php*.so | sed -e 's/^.*libphp\(.\)\.so$/php\1/' | tail -1`"
273 ln -fs /etc/alternc/alternc.ini /etc/$php/conf.d/alternc.ini || true
274 if [ -x /usr/sbin/apache2 ]; then
275  # hook
276  run-parts --arg=apache2 /usr/lib/alternc/install.d
277 
278  s=""
279  # unused from AlternC 1.0, FIXME: remove it later
280  if [ -L /etc/apache2/mods-enabled/vhost_alias.load ]
281  then
282  a2dismod vhost_alias
283  s="apache2"
284  fi
285  if ! [ -L /etc/apache2/mods-enabled/$php.load ]
286  then
287  a2enmod $php
288  fi
289  if ! [ -L /etc/apache2/mods-enabled/rewrite.load ]
290  then
291  a2enmod rewrite
292  fi
293  if [ -e /etc/alternc/apache.pem ]; then
294  # We enable proftpd tls module
295  cat /etc/proftpd/modules.conf | sed -e 's/^#LoadModule mod_tls.c/LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
296  mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
297  cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
298  # We enable apache2 SSL :
299  if [ ! -L /etc/apache2/mods-enabled/ssl.load ] ; then
300  a2enmod ssl
301  s="apache2"
302  fi
303  if [ ! -h /etc/apache2/conf.d/alternc-ssl.conf ] && [ -e /etc/apache2/conf.d/ ]; then
304  ln -sf /etc/alternc/apache2-ssl.conf /etc/apache2/conf.d/alternc-ssl.conf
305  s="apache2"
306  fi
307 
308  # We enable dovecot SSL certificate instructions: (on wheezy we should use a new file in /etc/dovecot/conf.d/ )
309  ( echo "ssl_cert = </etc/alternc/apache.pem" ; echo "ssl_key = </etc/alternc/apache.pem" ) >/etc/dovecot/conf.d/96_ssl.conf
310 
311  else
312  # We disable proftpd tls module
313  cat /etc/proftpd/modules.conf | sed -e 's/^LoadModule mod_tls.c/#LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
314  mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
315  cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
316 
317  # We disable dovecot SSL certificate instructions: (on wheezy we should remove a file in /etc/dovecot/conf.d/ )
318  ( 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
319 
320  echo "SSL not configured"
321  echo "create a certificate in /etc/alternc/apache.pem and rerun alternc.install"
322  fi
323  if [ ! -h /etc/apache2/conf.d/alternc.conf ] && [ -e /etc/apache2/conf.d/ ]; then
324  ln -sf /etc/alternc/apache2.conf /etc/apache2/conf.d/alternc.conf
325  s="apache2"
326  fi
327  if [ -e /etc/apache2/sites-enabled/000-default ]; then
328  a2dissite default
329  s="apache2"
330  fi
331  SERVICES="$SERVICES $s"
332 fi
333 
334 # Copy postfix *_checks if they do not exist
335 for file in body_checks header_checks; do
336  if [ ! -e "/etc/postfix/$file" ]; then
337  cp /usr/share/alternc/install/$file /etc/postfix
338  fi
339 done
340 
341 # Attribute the correct rights to critical postfix files
342 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
343  chown root:postfix /etc/postfix/my*
344  chmod 640 /etc/postfix/my*
345 fi
346 
347 if [ ! -f /etc/postfix/main.cf ]
348 then
349  echo "****************************************"
350  echo "POSTFIX is NOT configured properly"
351  echo "please launch dpkg-reconfigure -plow postfix"
352  echo "and choose 'Internet Site'"
353  echo "then launch alternc.install again"
354  echo "****************************************"
355  exit 1
356 fi
357 
358 # configure Postfix appropriatly for our needs
359 if [ "$slave" = "1" ]; then
360  postfix_conf=/etc/alternc/postfix/postfix-slave.cf
361 else
362  postfix_conf=/etc/alternc/postfix/postfix.cf
363 fi
364 grep -v '^\ *#' $postfix_conf |while read line ; do
365  if echo "$line" | grep -qi '^smtpd_tls_cert_file' ;then
366  line_strip=`echo "$line"|tr -d '[:blank:]'`
367  pattern="*="
368  cert_file=${line_strip#$pattern}
369  if [ -e $cert_file ];then
370  postconf -e "$line"
371  else
372  echo "****************************************"
373  echo "The certificate file : $cert_file does not exists"
374  echo "please go to https://alternc.org/wiki/SSL to get information on how to create a certificate"
375  echo "Then edit the file /etc/alternc/postfix/postfix.cf to add"
376  echo "the cert file path name to the key :smtpd_tls_cert_file"
377  echo "Finally relaunch alternc.install"
378  echo "****************************************"
379  fi
380  else
381  postconf -e "$line"
382  fi
383 done
384 
385 # Conviguring delivery used by Postfix
386 /usr/lib/alternc/alternc_add_policy_dovecot
387 
388 # Bug #1215: configure mydestination when $FQDN is not in
389 OLDDESTINATION=`postconf mydestination | awk -F '=' '{print $2}'`
390 echo "$OLDDESTINATION" | grep -q -v "$FQDN" && postconf -e "mydestination = $FQDN, $OLDDESTINATION"
391 
392 # Configure PHPMyAdmin
393 include_str='include("/etc/alternc/phpmyadmin.inc.php")'
394 pma_config='/etc/phpmyadmin/config.inc.php'
395 
396 # Sur une configuration vierge, inclure la configuration alternc
397 if ! grep -e "${include_str/\"/\\\"}" $pma_config > /dev/null 2>&1; then
398  echo "$include_str;" >> $pma_config
399 fi
400 
401 # Le template de /etc/alternc/phpmyadmin.inc.php viens d'être réappliqué, on
402 # regénére la liste des serveurs MySQL disponible dedans.
403 mysql_query "select id,host,name from db_servers;" | while read id host name ; do
404 echo "
405 // Server #$id in db_servers
406 \$i++;
407 \$cfg['Servers'][\$i]['connect_type'] = 'tcp'; // How to connect to MySQL server ('tcp' or 'socket')
408 \$cfg['Servers'][\$i]['auth_type'] = 'cookie'; // Authentication method (config, http or cookie based)?
409 \$cfg['Servers'][\$i]['hide_db'] = 'information_schema';
410 \$cfg['Servers'][\$i]['verbose'] = '$name'; // human name
411 \$cfg['Servers'][\$i]['host'] = '$host'; // MySQL hostname or IP address
412 " >> '/etc/alternc/phpmyadmin.inc.php'
413 done
414 
415 # Reload incron. Useless, but who know?
416 SERVICES="$SERVICES incron"
417 
418 if [ -e /etc/proftpd.conf ] ; then
419  chmod 640 /etc/proftpd/proftpd.conf
420 fi
421 
422 if [ -x /usr/sbin/locale-gen ] ; then
423  touch /etc/locale.gen
424  LOCALECHANGED=""
425  # Add de_DE ISO-8859-1, en_US ISO-8859-1, es_ES ISO-8859-1, fr_FR ISO-8859-1 to the locales :
426  if ! grep -q "^de_DE ISO-8859-1$" /etc/locale.gen ; then
427  echo "de_DE ISO-8859-1" >>/etc/locale.gen
428  LOCALECHANGED=1
429  fi
430  if ! grep -q "^en_US ISO-8859-1$" /etc/locale.gen ; then
431  echo "en_US ISO-8859-1" >>/etc/locale.gen
432  LOCALECHANGED=1
433  fi
434  if ! grep -q "^es_ES ISO-8859-1$" /etc/locale.gen ; then
435  echo "es_ES ISO-8859-1" >>/etc/locale.gen
436  LOCALECHANGED=1
437  fi
438  if ! grep -q "^fr_FR ISO-8859-1$" /etc/locale.gen ; then
439  echo "fr_FR ISO-8859-1" >>/etc/locale.gen
440  LOCALECHANGED=1
441  fi
442  if ! grep -q "^de_DE.UTF-8 UTF-8$" /etc/locale.gen ; then
443  echo "de_DE.UTF-8 UTF-8" >>/etc/locale.gen
444  LOCALECHANGED=1
445  fi
446  if ! grep -q "^fr_FR.UTF-8 UTF-8$" /etc/locale.gen ; then
447  echo "fr_FR.UTF-8 UTF-8" >>/etc/locale.gen
448  LOCALECHANGED=1
449  fi
450  if ! grep -q "^es_ES.UTF-8 UTF-8$" /etc/locale.gen ; then
451  echo "es_ES.UTF-8 UTF-8" >>/etc/locale.gen
452  LOCALECHANGED=1
453  fi
454  if ! grep -q "^en_US.UTF-8 UTF-8$" /etc/locale.gen ; then
455  echo "en_US.UTF-8 UTF-8" >>/etc/locale.gen
456  LOCALECHANGED=1
457  fi
458  if ! grep -q "^it_IT.UTF-8 UTF-8$" /etc/locale.gen ; then
459  echo "it_IT.UTF-8 UTF-8" >>/etc/locale.gen
460  LOCALECHANGED=1
461  fi
462  if ! grep -q "^nl_NL.UTF-8 UTF-8$" /etc/locale.gen ; then
463  echo "nl_NL.UTF-8 UTF-8" >>/etc/locale.gen
464  LOCALECHANGED=1
465  fi
466  if [ "$LOCALECHANGED" ] ; then
467  locale-gen
468  fi
469 fi
470 
471 # remaining steps are only for the master
472 if [ "$slave" = "1" ]; then
473  exit 0
474 fi
475 
476 #######################################################################
477 # populate alternc database with the mailname used by postfix to send mail for each vhost
478 #
479 mailname=`cat /etc/mailname`
480 mysql_query "update variable SET value='"$mailname"' where name='mailname_bounce';"
481 # Allow for all the users to view /etc/mailname
482 chmod +r "/etc/mailname"
483 
484 #######################################################################
485 # Save installed files to check them during next install
486 #
487 tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
488 
489 #######################################################################
490 # Last touches
491 #
492 
493 find $ALTERNC_HTML -maxdepth 1 -type d -exec setfacl -b -k -m d:g:alterncpanel:-wx -m g:alterncpanel:-wx {} \;
494 
495 #creating log file
496 if [ ! -e "/var/log/alternc/bureau.log" ]; then
497  test -d "/var/log/alternc/" || mkdir -p "/var/log/alternc/"
498  touch "/var/log/alternc/bureau.log"
499 fi
500 
501 if [ ! -e "/var/log/alternc/update_domains.log" ]; then
502  test -d "/var/log/alternc/" || mkdir -p "/var/log/alternc/"
503  touch "/var/log/alternc/update_domains.log"
504 fi
505 
506 # Be sure of the owner of the logs files
507 chmod 640 /var/log/alternc/bureau.log /var/log/alternc/update_domains.log
508 chown alterncpanel:adm /var/log/alternc/bureau.log /var/log/alternc/update_domains.log
509 
510 # Creating admin user if needed
511 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`
512 
513 if [ "$HAS_ROOT" != "1" ]; then
514  echo "Creating admin user..."
515  echo ""
516 
517  if su - alterncpanel -s /bin/bash -c /usr/share/alternc/install/newone.php
518  then
519  echo "*******************************************"
520  echo "* *"
521  echo "* Admin account *"
522  echo "* ------------ *"
523  echo "* *"
524  echo "* user: admin password: admin *"
525  echo "* *"
526  echo "* Please change this as soon as possible! *"
527  echo "* *"
528  echo "*******************************************"
529  else
530  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."
531  fi
532 fi
533 
534 #giving vmail user read access on dovecot sql file
535 chgrp vmail /etc/dovecot/dovecot.conf
536 chmod g+r /etc/dovecot/dovecot.conf
537 
538 # Changing owner of web panel's files
539 chown -R alterncpanel:alterncpanel "/usr/share/alternc/panel/"
540 
541 # We force the re-computing of the DNS zones, since we may have changed the IP address (see #460)
542 /usr/bin/mysql --defaults-file="/etc/alternc/my.cnf" -B -e "update domaines set dns_action='update';"
543 
544 # hook
545 run-parts --arg=before-reload /usr/lib/alternc/install.d
546 
547 #######################################################################
548 # Reload services
549 #
550 for service in postfix bind9 apache2 dovecot cron proftpd; do
551  invoke-rc.d $service force-reload || true
552 done
553 
554 # We should restart apaches after all configuration stuff ...
555 for service in $SERVICES; do
556  test -x /etc/init.d/$service && invoke-rc.d $service stop || true
557 done
558 for service in $SERVICES; do
559  test -x /etc/init.d/$service && invoke-rc.d $service start || true
560 done
561 
562 #launch fixperms
563 echo "Fix all the permission. May be quite long..."
564 /usr/lib/alternc/fixperms.sh
565 
566 # hook
567 run-parts --arg=end /usr/lib/alternc/install.d