2014-07-04 14:04:17 +00:00
#!/bin/bash
2012-08-26 17:20:10 +00:00
# ----------------------------------------------------------------------
# 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.
2006-04-26 12:28:53 +00:00
#
2012-08-26 17:20:10 +00:00
# To read the license please visit http://www.gnu.org/copyleft/gpl.html
# ----------------------------------------------------------------------
# Purpose of file: Main install script, launch it anytime ;)
# ----------------------------------------------------------------------
2006-04-26 12:28:53 +00:00
2012-08-26 17:20:10 +00:00
2018-06-22 13:04:21 +00:00
usage(){
declare -a out
[[ $# -ne 0 ]] && out+=("\e[31mWarning: $@ \e[0m")
out+=("
2018-06-24 17:40:22 +00:00
Usage: alternc.install [-n] [-f] [-s]
or alternc.install [-h] [-v]
Launch the template installation and service configuration process of AlternC.
This script should be launched by root after an AlternC package or plugin
installation or upgrade.
It should be harmless to launch it anytime, (it will restart services though).
Options:
-n, --no-fixperms Skip the -often long- fixperms action
-f, --force Force the execution even if some files changed
-s, --slave Mandatory on instances runnning the alternc-slave module
-h, --help This help
-v, --version Show AlternC version
AlternC is a free software distributed under GPL-v2+ license.
For more information see https://alternc.com/
2018-06-22 13:04:21 +00:00
")
echo -e "${out[@]}"
exit 2
}
2010-03-04 14:23:38 +00:00
for i in $*; do
2008-10-23 18:37:40 +00:00
case "$i" in
2018-06-22 13:04:21 +00:00
-h|--help)
usage; shift;;
2018-06-24 17:40:22 +00:00
-v|--version)
echo "AlternC - hosting software control panel, version @@REPLACED_DURING_BUILD@@"
exit 2;;
2018-06-22 13:04:21 +00:00
-n|--no-fixperms)
export nofixperms=1; shift;;
2008-10-23 18:37:40 +00:00
-f|--force)
2012-08-26 17:20:10 +00:00
export force=1; shift;;
2008-10-23 18:37:40 +00:00
-s|--slave)
2012-08-26 17:20:10 +00:00
export slave=1; shift;;
2008-10-23 18:37:40 +00:00
--)
break;;
*)
2018-06-22 13:04:21 +00:00
usage "unknown option '$i'!";
2008-10-23 18:37:40 +00:00
esac
done
2018-06-24 17:40:22 +00:00
# Somes check before start operations
if [ `id -u` -ne 0 ]; then
echo "must be launched as root"
exit 1
fi
2007-09-09 18:56:31 +00:00
. /usr/lib/alternc/functions.sh
2018-10-25 13:49:21 +00:00
# get the information on running Sysv or Systemd init & boot system
if [ -e /run/systemd/system ]
then
SYSTEMD=1
else
SYSTEMD=0
fi
2013-09-12 09:28:31 +00:00
# Lock the jobs !
lock_jobs
2012-08-26 17:20:10 +00:00
# hook
run-parts --arg=startup /usr/lib/alternc/install.d
2006-04-26 12:28:53 +00:00
#######################################################################
# Script configuration
#
# Configuration template location
TEMPLATE_DIR="/etc/alternc/templates"
# Find needed configuration files (without the initial '/')
2006-04-26 21:38:32 +00:00
# replace this one unconditionnally
2018-10-25 14:14:45 +00:00
CONFIG_FILES="etc/alternc/bureau.conf etc/apache2/envvars etc/alternc/apache2.conf etc/alternc/phpmyadmin.inc.php"
2006-04-26 12:28:53 +00:00
if [ -e /etc/bind/named.conf ]; then
2013-03-05 13:49:20 +00:00
CONFIG_FILES="$CONFIG_FILES etc/bind/named.conf.options"
2006-04-26 12:28:53 +00:00
fi
2007-08-23 08:01:01 +00:00
if [ -d /etc/postfix ]; then
2013-01-22 09:06:13 +00:00
CONFIG_FILES="$CONFIG_FILES etc/postfix/master.cf etc/postfix/myalias.cf etc/postfix/myrelay.cf
2014-03-07 14:24:45 +00:00
etc/postfix/mydomain.cf etc/postfix/myrelay-domain.cf etc/postfix/mymail2mail.cf etc/postfix/mygid.cf etc/postfix/myquota.cf
2013-02-18 18:20:12 +00:00
etc/postfix/myvirtual.cf etc/postfix/mytransport.cf etc/postfix/sasl/smtpd.conf
2013-08-22 07:29:25 +00:00
etc/alternc/postfix/postfix.cf etc/alternc/postfix/postfix-slave.cf
etc/opendkim.conf etc/default/opendkim"
2006-04-26 12:28:53 +00:00
fi
2007-08-22 22:32:12 +00:00
if [ -e /etc/proftpd/proftpd.conf ]; then
CONFIG_FILES="$CONFIG_FILES etc/proftpd/proftpd.conf etc/proftpd/welcome.msg etc/proftpd/modules.conf"
2006-04-26 12:28:53 +00:00
fi
if [ -e /etc/default/saslauthd ]; then
CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
fi
2012-05-02 13:03:48 +00:00
if [ -e /etc/dovecot/dovecot.conf ]; then
2018-07-12 13:59:45 +00:00
CONFIG_FILES="$CONFIG_FILES etc/dovecot/alternc-sql.conf etc/dovecot/alternc-dict-quota.conf etc/dovecot/conf.d/95_alternc.conf etc/dovecot/conf.d/96_ssl.conf"
2012-05-02 13:03:48 +00:00
fi
2013-04-23 15:11:00 +00:00
INSTALLED_CONFIG_TAR="/var/lib/alternc/backups/etc-installed.tar.gz"
2006-04-26 12:28:53 +00:00
#######################################################################
# Look for modified configuration files
#
if [ -f "$INSTALLED_CONFIG_TAR" ]; then
2008-10-06 22:21:37 +00:00
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' |
2015-09-25 15:53:55 +00:00
sed -e 's#^\([^:]*\).*# /\1#' | sort -u`"
2006-04-26 12:28:53 +00:00
if [ ! -z "$CHANGED" ]; then
echo "The following configuration files has changed since last AlternC"
echo "installation :"
echo "$CHANGED"
echo ""
2008-10-23 18:37:40 +00:00
if [ "$force" = "1" ]; then
2006-04-26 12:28:53 +00:00
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 ""
2012-08-26 17:20:10 +00:00
echo "Please examine the situation closely and call '$0 -f'"
2006-04-26 12:28:53 +00:00
echo "if you still want to actually overwrite these files."
exit 1
fi
fi
fi
2014-03-27 15:43:36 +00:00
# Upgrade the DATA and DB SCHEMA
/usr/share/alternc/install/upgrade_check.sh
2014-03-28 10:39:22 +00:00
# Launch upgrade of alternc modules
run-parts --arg=upgrade /usr/lib/alternc/install.d
2014-03-27 15:43:36 +00:00
2006-04-26 12:28:53 +00:00
#######################################################################
# Prepare template expansions
#
2012-09-26 09:41:41 +00:00
chown :alterncpanel /etc/alternc/local.sh
2006-04-26 12:28:53 +00:00
. /etc/alternc/local.sh
2013-10-17 08:42:11 +00:00
# May be missing
2018-07-04 15:42:42 +00:00
test -d /run/alternc || ( mkdir -p /run/alternc && chown alterncpanel:alterncpanel /run/alternc )
2013-10-17 08:42:11 +00:00
2013-02-18 13:11:25 +00:00
# Create the target directory
for i in "$ALTERNC_HTML" "$ALTERNC_MAIL" "$ALTERNC_LOGS" ; do
test -d "$i" || mkdir -p "$i"
done
2013-02-18 14:00:25 +00:00
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
2013-08-22 14:18:17 +00:00
test -d "$ALTERNC_HTML/$i" || ( mkdir -p "$ALTERNC_HTML/$i" && chown alterncpanel:alterncpanel "$ALTERNC_HTML/$i" && chmod 775 "$ALTERNC_HTML/$i" )
2013-04-24 14:34:54 +00:00
test -d "$ALTERNC_MAIL/$i" || ( mkdir -p "$ALTERNC_MAIL/$i" && chown vmail:vmail "$ALTERNC_MAIL/$i" && chmod 775 "$ALTERNC_MAIL/$i" )
2013-02-18 14:00:25 +00:00
done
2013-08-12 12:47:31 +00:00
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 {} \;
2013-04-24 14:34:54 +00:00
2011-05-23 16:17:52 +00:00
# Check ACL
2013-02-18 13:11:25 +00:00
aclcheckfile="$ALTERNC_HTML/test-acl"
2011-05-23 16:17:52 +00:00
touch "$aclcheckfile"
2013-03-03 11:57:57 +00:00
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"
2011-05-23 16:17:52 +00:00
2008-04-13 04:35:19 +00:00
# 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)
2008-04-17 23:04:26 +00:00
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`
2011-05-22 09:22:45 +00:00
chown root:alterncpanel /etc/alternc/my.cnf
2008-07-10 21:37:29 +00:00
chmod 640 /etc/alternc/my.cnf
2008-04-13 04:35:19 +00:00
fi
2012-04-16 14:21:10 +00:00
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)
2012-04-24 15:51:47 +00:00
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`
2012-04-16 14:21:10 +00:00
chown root:alterncpanel /etc/alternc/my_mail.cnf
chmod 640 /etc/alternc/my_mail.cnf
fi
2006-04-26 12:28:53 +00:00
WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
2013-04-02 20:34:02 +00:00
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
2006-04-26 12:28:53 +00:00
2013-02-18 18:09:43 +00:00
# /var/ alternc/dns/d/www.example.com
2006-04-26 12:28:53 +00:00
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
2011-02-28 16:43:03 +00:00
PUBLIC_IP_BEGIN=$(echo $PUBLIC_IP|cut -c 1)
2010-12-20 16:56:37 +00:00
2013-02-20 14:41:55 +00:00
# Secret for PhpMyAdmin sessions
PHPMYADMIN_BLOWFISH="$(generate_string 24)"
2008-04-13 04:35:19 +00:00
# XXX: I assume this is secure if /tmp is sticky (+t)
# we should have a better way to deal with templating, of course.
2012-10-16 13:50:44 +00:00
SED_SCRIPT="/tmp/alternc.install.sedscript"
2008-04-13 04:35:19 +00:00
cat > $SED_SCRIPT <<EOF
2006-04-26 12:28:53 +00:00
s\\%%hosting%%\\$HOSTING\\;
s\\%%fqdn%%\\$FQDN\\;
s\\%%public_ip%%\\$PUBLIC_IP\\;
2010-12-20 16:56:37 +00:00
s\\%%public_ip_begin%%\\$PUBLIC_IP_BEGIN\\;
2006-04-26 12:28:53 +00:00
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\\;
2012-04-16 14:21:10 +00:00
s\\%%db_mail_user%%\\$MYSQL_MAIL_USER\\;
s\\%%db_mail_pwd%%\\$MYSQL_MAIL_PASS\\;
2006-04-26 12:28:53 +00:00
s\\%%warning_message%%\\$WARNING\\;
s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
s\\%%version%%\\$VERSION\\;
s\\%%ns2_ip%%\\$NS2_IP\\;
2013-02-18 13:11:25 +00:00
s\\%%ALTERNC_HTML%%\\$ALTERNC_HTML\\;
s\\%%ALTERNC_MAIL%%\\$ALTERNC_MAIL\\;
s\\%%ALTERNC_LOGS%%\\$ALTERNC_LOGS\\;
2013-02-20 14:41:55 +00:00
s\\%%PHPMYADMIN_BLOWFISH%%\\$PHPMYADMIN_BLOWFISH\\;
2008-04-13 04:35:19 +00:00
EOF
2006-04-26 12:28:53 +00:00
2012-08-26 17:20:10 +00:00
# hook
2013-02-08 10:53:13 +00:00
test -d /usr/lib/alternc/install.d || mkdir -p /usr/lib/alternc/install.d
2012-08-26 17:20:10 +00:00
run-parts --arg=templates /usr/lib/alternc/install.d
2012-10-01 13:37:59 +00:00
######################################################################
# Backup the Main database
2013-04-23 15:11:00 +00:00
DB_BACKUP="/var/lib/alternc/backups/${MYSQL_DATABASE}-db-`date +%Y%m%d-%H:%M:%S`.gz"
2012-10-01 13:37:59 +00:00
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"
2006-04-26 12:28:53 +00:00
#######################################################################
# Backup configuration files
#
2013-04-23 15:11:00 +00:00
BACKUP_FILE="/var/lib/alternc/backups/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
2006-04-26 12:28:53 +00:00
# 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
2008-10-06 22:20:48 +00:00
# also backup main.cf since we're doing major changes to it
BACKUPS="$BACKUPS etc/postfix/main.cf"
2013-01-28 17:05:53 +00:00
2006-04-26 12:28:53 +00:00
tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
2016-05-17 13:51:33 +00:00
chmod 600 "$BACKUP_FILE"
2006-04-26 12:28:53 +00:00
#######################################################################
# Expand templates in the right place
#
2008-04-14 03:10:58 +00:00
echo -n "Expanding variables in configuration files:"
2006-04-26 12:28:53 +00:00
for file in $CONFIG_FILES; do
TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
2008-04-14 03:10:58 +00:00
echo -n " $file"
2006-04-26 12:28:53 +00:00
if [ -f "$TEMPLATE" ]; then
2008-04-13 04:35:19 +00:00
sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
2006-04-26 12:28:53 +00:00
fi
done
2008-04-14 03:10:58 +00:00
echo "."
2008-04-13 04:35:19 +00:00
rm -f $SED_SCRIPT
2006-04-26 12:28:53 +00:00
########################################################################
2018-06-24 13:43:23 +00:00
# Ad-hoc fixes
2006-04-26 12:28:53 +00:00
2018-06-24 13:43:23 +00:00
# add php.ini directives for AlternC in any installed php version:
2018-06-21 15:29:42 +00:00
php="`ls /usr/lib/apache*/*/*php*.so | sed -e 's/^.*libphp\(.*\)\.so$/\1/' | tail -1`"
if [ "$php" = "7.0" ]
then
ln -fs /etc/alternc/alternc.ini /etc/php/$php/apache2/conf.d/alternc.ini || true
ln -fs /etc/alternc/alternc.ini /etc/php/$php/cli/conf.d/alternc.ini || true
else
ln -fs /etc/alternc/alternc.ini /etc/php$php/apache2/conf.d/alternc.ini || true
ln -fs /etc/alternc/alternc.ini /etc/php$php/cli/conf.d/alternc.ini || true
fi
2018-06-24 13:43:23 +00:00
# Create the default certificate if needed (requires openssl)
2018-06-23 09:00:45 +00:00
make-ssl-cert generate-default-snakeoil
2018-06-24 14:09:28 +00:00
/usr/bin/mysql --defaults-file=/etc/alternc/my.cnf -Bs <<EOF
2018-06-24 13:43:23 +00:00
SET SESSION sql_mode="NO_AUTO_VALUE_ON_ZERO" ;
INSERT IGNORE INTO certificates
(id,uid,status,fqdn,validstart,validend,sslkey,sslcrt,provider)
VALUES
(0, 2000, 1, "AlternC Default Certificate", NOW(), DATE_ADD(NOW(),INTERVAL 20 YEAR),
"$(cat /etc/ssl/private/ssl-cert-snakeoil.key)",
"$(cat /etc/ssl/certs/ssl-cert-snakeoil.pem)",
"snakeoil");
EOF
2018-06-23 09:00:45 +00:00
2018-06-24 13:43:23 +00:00
# backward compatibility: in case you still use apache.pem
# we are now storing certificates in /etc/ssl/certs/alternc-<servicename>.pem
# and private keys in /etc/ssl/private/alternc-<servicename>.key
2018-06-23 09:00:45 +00:00
if [ ! -e /etc/alternc/apache.pem ]; then
2018-06-24 13:43:23 +00:00
cat /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/certs/ssl-cert-snakeoil.pem > /etc/alternc/apache.pem
2018-06-23 09:00:45 +00:00
fi
2018-06-24 13:43:23 +00:00
# set services certificates in case we don't already have them:
# we set them to snakeoil: a provider MUST be installed to obtain a proper certificate automagically
for service in postfix dovecot proftpd panel
do
if [ ! -e "/etc/ssl/certs/alternc-${service}.pem" -o ! -e "/etc/ssl/private/alternc-${service}.key" ]
then
cat /etc/ssl/private/ssl-cert-snakeoil.key >"/etc/ssl/private/alternc-${service}.key"
cat /etc/ssl/certs/ssl-cert-snakeoil.pem >"/etc/ssl/certs/alternc-${service}.pem"
fi
done
2018-07-17 13:11:31 +00:00
# ensure dovecot, postfix, can access ssl certificates:
2018-06-24 13:43:23 +00:00
adduser dovecot ssl-cert
adduser postfix ssl-cert
2018-06-23 09:00:45 +00:00
run-parts --arg=certificates /usr/lib/alternc/install.d
2008-10-07 17:21:18 +00:00
if [ -x /usr/sbin/apache2 ]; then
2012-08-26 19:59:12 +00:00
# hook
run-parts --arg=apache2 /usr/lib/alternc/install.d
2018-06-21 15:29:42 +00:00
a2enmod mpm_itk
2012-08-26 19:59:12 +00:00
2013-02-08 13:05:54 +00:00
# unused from AlternC 1.0, FIXME: remove it later
2012-08-26 17:20:10 +00:00
if [ -L /etc/apache2/mods-enabled/vhost_alias.load ]
2008-10-07 17:21:18 +00:00
then
2012-08-26 17:20:10 +00:00
a2dismod vhost_alias
2008-10-07 17:21:18 +00:00
fi
2018-06-21 15:29:42 +00:00
if ! [ -L /etc/apache2/mods-enabled/php$php.load ]
2011-03-28 06:38:24 +00:00
then
2018-06-24 14:09:28 +00:00
a2enmod php$php
2011-03-28 06:38:24 +00:00
fi
if ! [ -L /etc/apache2/mods-enabled/rewrite.load ]
then
2018-06-24 14:09:28 +00:00
a2enmod rewrite
2008-10-07 18:00:06 +00:00
fi
2018-06-24 14:09:11 +00:00
if ! [ -L /etc/apache2/mods-enabled/expires.load ]
then
2018-06-24 14:09:28 +00:00
a2enmod expires
2008-10-07 17:21:18 +00:00
fi
2018-06-24 16:17:10 +00:00
if ! [ -L /etc/apache2/mods-enabled/ssl.load ]
then
a2enmod ssl
fi
2013-05-28 04:58:01 +00:00
2018-06-23 09:39:34 +00:00
if [ ! -h /etc/apache2/conf-available/alternc-ssl.conf ] && [ -e /etc/apache2/conf-available/ ]; then
ln -sf /etc/alternc/apache2-ssl.conf /etc/apache2/conf-available/alternc-ssl.conf
a2enconf alternc-ssl
2008-10-07 17:23:09 +00:00
fi
2018-06-23 09:39:34 +00:00
2018-07-12 14:25:57 +00:00
if [ ! -h /etc/apache2/conf-available/alternc.conf ] && [ -e /etc/apache2/conf-available/ ]; then
ln -sf /etc/alternc/apache2.conf /etc/apache2/conf-available/alternc.conf
a2enconf alternc
fi
2018-10-25 14:47:52 +00:00
SERVICES="$SERVICES apache2"
2007-09-09 19:17:45 +00:00
fi
2006-04-26 12:28:53 +00:00
2014-03-28 10:39:22 +00:00
# Manage sudoers.d include appearing in Squeeze:
# if the "includedir" is not here, we add it ONLY IF visudo -c is happy.
if ! grep -q "#includedir */etc/sudoers.d" /etc/sudoers ; then
if ! cat /etc/sudoers.d/* | visudo -c -f - >/dev/null ; then
echo -e "\033[31m**********************************************"
echo "* *"
echo "* ALTERNC ACTION REQUESTED *"
echo "* *"
echo "* SUDO is NOT configured properly *"
echo "* check your files in /etc/sudoers.d ! *"
echo "* then launch alternc.install again *"
echo "* *"
echo "**********************************************"
echo -e "\033[0m"
exit 1
else
echo "#includedir */etc/sudoers.d" >>/etc/sudoers
fi
fi
2006-04-26 12:28:53 +00:00
# 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
2012-10-15 09:08:55 +00:00
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
2006-04-26 12:28:53 +00:00
chown root:postfix /etc/postfix/my*
chmod 640 /etc/postfix/my*
fi
2011-06-04 09:39:15 +00:00
if [ ! -f /etc/postfix/main.cf ]
then
2014-03-28 10:39:22 +00:00
echo -e "\033[31m**********************************************"
echo "* *"
echo "* ALTERNC ACTION REQUESTED *"
echo "* *"
echo "* POSTFIX is NOT configured properly *"
echo "* launch dpkg-reconfigure -plow postfix *"
echo "* and choose 'Internet Site' *"
echo "* then launch alternc.install again *"
echo "* *"
echo "**********************************************"
echo -e "\033[0m"
2011-06-04 09:39:15 +00:00
exit 1
fi
2012-04-24 15:51:47 +00:00
# configure Postfix appropriatly for our needs
2008-10-23 18:37:40 +00:00
if [ "$slave" = "1" ]; then
2013-02-18 16:31:51 +00:00
postfix_conf=/etc/alternc/postfix/postfix-slave.cf
2008-10-23 18:37:40 +00:00
else
2013-02-18 16:31:51 +00:00
postfix_conf=/etc/alternc/postfix/postfix.cf
2008-10-23 18:37:40 +00:00
fi
2012-05-04 08:57:23 +00:00
grep -v '^\ *#' $postfix_conf |while read line ; do
2018-06-23 09:39:34 +00:00
postconf -e "$line"
2013-03-08 11:26:04 +00:00
done
2012-04-24 15:51:47 +00:00
2012-08-26 17:20:10 +00:00
# Conviguring delivery used by Postfix
2012-09-04 08:35:05 +00:00
/usr/lib/alternc/alternc_add_policy_dovecot
2008-10-06 22:12:41 +00:00
2011-03-13 14:37:37 +00:00
# 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"
2013-01-28 17:05:53 +00:00
2015-04-20 18:38:58 +00:00
# Remove phpmyadmin apache2 configuration
2018-06-24 14:09:28 +00:00
if [ -L /etc/apache2/conf-enabled/phpmyadmin.conf ]
then
a2disconf phpmyadmin
fi
2018-06-24 14:50:08 +00:00
# Remove global /javascript alias (side effect warning)
if [ -L /etc/apache2/conf-enabled/javascript-common.conf ]
then
a2disconf javascript-common
fi
2015-04-20 18:38:58 +00:00
2013-02-21 08:05:38 +00:00
# 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
2013-03-01 10:31:23 +00:00
# Le template de /etc/alternc/phpmyadmin.inc.php viens d'être réappliqué, on
2013-09-25 09:50:53 +00:00
# regénére la liste des serveurs MySQL disponible dedans.
2013-03-01 10:31:23 +00:00
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
2013-02-21 08:05:38 +00:00
2013-01-29 07:08:32 +00:00
# Reload incron. Useless, but who know?
2013-01-28 17:05:53 +00:00
SERVICES="$SERVICES incron"
2011-03-13 14:37:37 +00:00
2006-04-26 14:00:52 +00:00
if [ -e /etc/proftpd.conf ] ; then
2007-08-22 22:32:12 +00:00
chmod 640 /etc/proftpd/proftpd.conf
2006-04-26 14:00:52 +00:00
fi
2007-08-26 19:34:17 +00:00
if [ -x /usr/sbin/locale-gen ] ; then
touch /etc/locale.gen
2007-08-26 19:14:51 +00:00
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
2012-08-26 17:20:10 +00:00
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
2012-10-31 11:42:32 +00:00
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
2013-02-08 10:53:13 +00:00
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
2007-08-26 19:14:51 +00:00
if [ "$LOCALECHANGED" ] ; then
locale-gen
fi
fi
2013-04-02 20:43:38 +00:00
# remaining steps are only for the master
if [ "$slave" = "1" ]; then
exit 0
fi
2012-08-06 09:22:13 +00:00
#######################################################################
2012-08-26 17:20:10 +00:00
# populate alternc database with the mailname used by postfix to send mail for each vhost
2012-08-06 09:22:13 +00:00
#
2014-03-03 08:51:12 +00:00
# If mailname does not exist, create it. Fix #1495
test -e "/etc/mailname" || hostname -f > "/etc/mailname"
2012-08-22 15:17:11 +00:00
# Allow for all the users to view /etc/mailname
chmod +r "/etc/mailname"
2012-08-06 09:22:13 +00:00
2010-06-03 10:32:12 +00:00
#######################################################################
# Save installed files to check them during next install
#
tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
2006-04-26 12:28:53 +00:00
#######################################################################
# Last touches
#
2016-02-22 14:49:50 +00:00
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 {} \;
2011-05-22 19:18:43 +00:00
2012-11-08 16:13:18 +00:00
#creating log file
if [ ! -e "/var/log/alternc/bureau.log" ]; then
2012-11-08 19:33:31 +00:00
test -d "/var/log/alternc/" || mkdir -p "/var/log/alternc/"
2012-11-08 16:13:18 +00:00
touch "/var/log/alternc/bureau.log"
fi
2013-02-19 08:56:47 +00:00
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
2013-02-27 08:18:32 +00:00
# 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
2018-10-25 12:58:18 +00:00
# Launch a script that will populate AlternC variables as needed
su - alterncpanel -s /bin/bash -c /usr/share/alternc/install/variables.php
2013-01-08 20:44:17 +00:00
# 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`
2006-04-26 12:28:53 +00:00
if [ "$HAS_ROOT" != "1" ]; then
echo "Creating admin user..."
echo ""
2011-05-22 19:18:43 +00:00
if su - alterncpanel -s /bin/bash -c /usr/share/alternc/install/newone.php
2006-04-26 12:28:53 +00:00
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
2013-02-08 13:05:54 +00:00
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."
2006-04-26 12:28:53 +00:00
fi
2017-10-08 12:45:54 +00:00
else
##UPDATE default db_server following /etc/alternc/my.cnf values
if [ "$MYSQL_HOST" == "localhost" ]; then
MYSQL_HOST_CLIENT="localhost"
else
MYSQL_HOST_CLIENT="%"
fi
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';"
2006-04-26 12:28:53 +00:00
fi
2018-06-21 15:29:42 +00:00
# giving vmail user read access on dovecot sql file
chgrp vmail /etc/dovecot/alternc-sql.conf
chmod g+r /etc/dovecot/alternc-sql.conf
# Override some dovecot 2.0 configuration that may have happened during dovecot postinst:
sed -i -e 's/^ *!include/#!include/' /etc/dovecot/conf.d/10-auth.conf
# Changing owner of web panel's files
chown -R alterncpanel:alterncpanel "/usr/share/alternc/panel/"
2012-04-24 15:51:47 +00:00
2011-03-27 11:23:28 +00:00
# We force the re-computing of the DNS zones, since we may have changed the IP address (see #460)
2014-10-02 10:08:06 +00:00
/usr/bin/mysql --defaults-file="/etc/alternc/my.cnf" -B -e "update domaines set dns_action='UPDATE' WHERE gesdns=1;"
2011-03-27 11:23:28 +00:00
2013-08-22 07:29:25 +00:00
# We ensure localhost is trusted to opendkim
mkdir -p "/etc/opendkim/keys"
2015-11-05 17:08:30 +00:00
touch /etc/opendkim/TrustedHosts /etc/opendkim/SigningTable /etc/opendkim/KeyTable
2013-08-22 07:29:25 +00:00
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
2017-08-12 15:03:03 +00:00
grep -q "^$PUBLIC_IP\$" /etc/opendkim/TrustedHosts || echo "$PUBLIC_IP" >>/etc/opendkim/TrustedHosts
2018-10-25 13:49:21 +00:00
if [ "$SYSTEMD" = "1" -a "$(lsb_release -s -c)" = "stretch" ] ; then
2018-06-14 18:12:14 +00:00
/lib/opendkim/opendkim.service.generate
# Without adding '-u opendkim' after the service file is generated, opendkim
# will run as root, which we do not want.
if [ "$(grep -c 'u opendkim' /etc/systemd/system/opendkim.service.d/override.conf)" == 0 ] ; then
2018-06-14 19:00:09 +00:00
sed -i -e 's/inet:8891@127.0.0.1/& -u opendkim/' /etc/systemd/system/opendkim.service.d/override.conf
2018-06-14 18:12:14 +00:00
fi
systemctl daemon-reload
fi
2013-08-22 07:29:25 +00:00
2014-03-26 18:13:45 +00:00
# Add opendkim to service to restart
2018-06-21 15:29:42 +00:00
SERVICES="$SERVICES opendkim bind9"
2014-03-26 18:13:45 +00:00
2012-08-26 17:20:10 +00:00
# hook
run-parts --arg=before-reload /usr/lib/alternc/install.d
#######################################################################
# Reload services
#
2018-06-21 15:29:42 +00:00
for service in postfix dovecot cron proftpd ; do
2012-08-26 17:20:10 +00:00
invoke-rc.d $service force-reload || true
done
2007-08-26 20:44:53 +00:00
# We should restart apaches after all configuration stuff ...
2008-10-07 20:14:15 +00:00
for service in $SERVICES; do
2007-09-27 08:29:11 +00:00
test -x /etc/init.d/$service && invoke-rc.d $service stop || true
done
2018-06-21 15:29:42 +00:00
# on Jessie, apache2 does not stop/start properly due to "service" and "apache2ctl" having different behavior pid-file-wise
killall apache2
2008-10-07 20:14:15 +00:00
for service in $SERVICES; do
2007-09-27 08:29:11 +00:00
test -x /etc/init.d/$service && invoke-rc.d $service start || true
2007-08-26 20:44:53 +00:00
done
2012-08-26 17:20:10 +00:00
2018-06-22 13:04:21 +00:00
if [[ $nofixperms -ne 1 ]] ; then
echo "Fix all the permission. May be quite long..."
echo "YOU CAN INTERUPT THIS BY USING Ctrl-c THEN y TO BYPASS THE ERROR."
/usr/lib/alternc/fixperms.sh
echo "Compile PO files"
else
echo -e "\nSkipping fixperms as requested\n"
fi
2013-10-18 09:12:08 +00:00
# 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
2014-03-27 16:47:45 +00:00
rm -f alternc.mo alternc.po
msgcat --use-first *.po alternc >alternc.po
msgfmt alternc.po -o alternc.mo
2013-10-18 09:12:08 +00:00
done
2014-02-28 14:35:40 +00:00
# Fix some perms
# Fix phpmyadmin import trac#1557
2014-03-27 16:47:45 +00:00
test -d "/var/lib/phpmyadmin/tmp" && dpkg-statoverride --update --add www-data alterncpanel 0775 "/var/lib/phpmyadmin/tmp" 2>/dev/null || true
2017-10-08 08:47:44 +00:00
test -f "/etc/phpmyadmin/config-db.php" && dpkg-statoverride --update --add www-data alterncpanel 0644 "/etc/phpmyadmin/config-db.php" 2>/dev/null || true
2012-09-27 10:05:25 +00:00
2012-08-26 17:20:10 +00:00
# hook
run-parts --arg=end /usr/lib/alternc/install.d
2013-09-12 09:28:31 +00:00
2013-10-18 14:17:53 +00:00
# Unlock jobs !
unlock_jobs
2013-10-18 13:54:07 +00:00
# Rebuild all web configuration
/usr/lib/alternc/rebuild_all_webconf.sh --force