2011-02-28 16:43:03 +00:00
#!/bin/sh
2006-04-26 12:28:53 +00:00
#
# AlternC Main install script.
# This script should be launched only once, when installing AlternC
# on a new server. THIS SCRIPT ERASE ALL DATA ON THE AlternC SYSTEM !!
# YOU HAVE BEEN WARNED !
2008-04-13 04:35:19 +00:00
# This script now assumes it has MySQL connectivity through
# /etc/alternc/my.cnf
2006-04-26 12:28:53 +00:00
set -e
2010-03-04 14:23:38 +00:00
for i in $*; do
2008-10-23 18:37:40 +00:00
case "$i" in
-f|--force)
force=1; shift;;
-s|--slave)
slave=1; shift;;
--)
break;;
*)
echo "unknown option $i"; shift;;
esac
done
2007-09-09 18:56:31 +00:00
. /usr/lib/alternc/functions.sh
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
CONFIG_FILES="etc/alternc/bureau.conf"
2006-04-26 12:28:53 +00:00
if [ -e /etc/bind/named.conf ]; then
CONFIG_FILES="$CONFIG_FILES etc/bind/templates/zone.template
2010-03-04 14:32:02 +00:00
etc/bind/templates/named.template etc/bind/named.conf.options"
2006-04-26 12:28:53 +00:00
fi
if [ -e /etc/courier/authdaemonrc ]; then
CONFIG_FILES="$CONFIG_FILES etc/courier/authdaemonrc
etc/courier/authmysqlrc"
fi
2007-08-23 08:01:01 +00:00
if [ -d /etc/postfix ]; then
2008-10-23 18:37:40 +00:00
CONFIG_FILES="$CONFIG_FILES etc/postfix/myalias.cf etc/postfix/myrelay.cf
2006-04-26 12:28:53 +00:00
etc/postfix/mydomain.cf etc/postfix/mygid.cf
etc/postfix/myvirtual.cf etc/postfix/sasl/smtpd.conf"
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/squirrelmail/apache.conf ]; then
CONFIG_FILES="$CONFIG_FILES etc/squirrelmail/apache.conf"
fi
if [ -e /etc/default/saslauthd ]; then
CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
fi
INSTALLED_CONFIG_TAR="/var/backups/alternc/etc-installed.tar.gz"
#######################################################################
# 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' |
2006-04-26 12:28:53 +00:00
sed -e 's/^\([^:]*\).*/ \1/' | sort -u`"
2008-10-23 18:37:40 +00:00
# " shutup emacs
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 ""
2009-01-29 01:09:40 +00:00
echo "Please examine the situation closely and call '$0 --force'"
2006-04-26 12:28:53 +00:00
echo "if you still want to actually overwrite these files."
exit 1
fi
fi
fi
#######################################################################
# Prepare template expansions
#
. /etc/alternc/local.sh
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`
2008-07-10 21:37:29 +00:00
chown root:www-data /etc/alternc/my.cnf
chmod 640 /etc/alternc/my.cnf
2008-04-13 04:35:19 +00:00
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."
VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
# /var/alternc/dns/d/www.example.com
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
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.
SED_SCRIPT=`mktemp`
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\\;
s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
s\\%%warning_message%%\\$WARNING\\;
s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
s\\%%version%%\\$VERSION\\;
s\\%%ns2_ip%%\\$NS2_IP\\;
2008-04-13 04:35:19 +00:00
EOF
2006-04-26 12:28:53 +00:00
#######################################################################
# Backup configuration files
#
BACKUP_FILE="/var/backups/alternc/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
# 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"
2006-04-26 12:28:53 +00:00
tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
#######################################################################
# 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
########################################################################
# Ad-hoc fixes
#
2007-10-05 14:46:40 +00:00
php="`ls /usr/lib/apache*/*/*php*.so | sed -e 's/^.*libphp\(.\)\.so$/php\1/' | tail -1`"
2008-10-31 17:55:06 +00:00
ln -fs /etc/alternc/alternc.ini /etc/$php/conf.d/alternc.ini || true
2008-10-07 17:21:18 +00:00
if [ -x /usr/sbin/apache2 ]; then
s=""
2011-03-28 06:38:24 +00:00
if ! [ -L /etc/apache2/mods-enabled/vhost_alias.load ]
2008-10-07 17:21:18 +00:00
then
a2enmod vhost_alias
s="apache2"
fi
2011-03-28 06:38:24 +00:00
if ! [ -L /etc/apache2/mods-enabled/$php.load ]
then
a2enmod $php
fi
if ! [ -L /etc/apache2/mods-enabled/rewrite.load ]
then
a2enmod rewrite
fi
2008-10-07 18:28:39 +00:00
if [ -e /etc/alternc/apache.pem ]; then
2010-03-04 14:23:38 +00:00
# We enable proftpd tls module
cat /etc/proftpd/modules.conf | sed -e 's/^#LoadModule mod_tls.c/LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
# We enable apache2 SSL :
2011-03-28 06:38:24 +00:00
if [ ! -L /etc/apache2/mods-enabled/ssl.load ] ; then
2008-10-07 18:28:39 +00:00
a2enmod ssl
s="apache2"
fi
if [ ! -h /etc/apache2/conf.d/alternc-ssl.conf ] && [ -e /etc/apache2/conf.d/ ]; then
2008-10-07 18:34:02 +00:00
ln -sf /etc/alternc/apache2-ssl.conf /etc/apache2/conf.d/alternc-ssl.conf
2008-10-07 18:28:39 +00:00
s="apache2"
fi
else
2010-03-04 14:23:38 +00:00
# We disable proftpd tls module
cat /etc/proftpd/modules.conf | sed -e 's/^LoadModule mod_tls.c/#LoadModule mod_tls.c/' > /etc/proftpd/modules.conf.alternc-new
mv /etc/proftpd/modules.conf.alternc-new /etc/proftpd/modules.conf
cp /etc/proftpd/modules.conf /etc/alternc/templates/proftpd/
2008-10-07 18:28:39 +00:00
echo "SSL not configured"
echo "create a certificate in /etc/alternc/apache.pem and rerun alternc.install"
2008-10-07 18:00:06 +00:00
fi
2008-10-07 17:21:18 +00:00
if [ ! -h /etc/apache2/conf.d/alternc.conf ] && [ -e /etc/apache2/conf.d/ ]; then
ln -sf /etc/alternc/apache2.conf /etc/apache2/conf.d/alternc.conf
s="apache2"
fi
2008-10-07 17:23:09 +00:00
if [ -e /etc/apache2/sites-enabled/000-default ]; then
a2dissite default
s="apache2"
fi
2008-10-07 17:21:18 +00:00
SERVICES="$SERVICES $s"
2007-09-09 19:17:45 +00:00
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
2008-10-23 18:37:40 +00:00
if [ -e /etc/postfix/myalias.cf -o -e /etc/postfix/mydomain.cf -o -e /etc/postfix/mygid.cf -o -e /etc/postfix/myvirtual.cf -o -e /etc/postfix/myrelay.cf ]; then
2006-04-26 12:28:53 +00:00
chown root:postfix /etc/postfix/my*
chmod 640 /etc/postfix/my*
fi
2008-10-23 18:37:40 +00:00
# configure postfix appropriatly for our needs
if [ "$slave" = "1" ]; then
postfix_conf=/etc/alternc/postfix-slave.cf
else
postfix_conf=/etc/alternc/postfix.cf
fi
2008-10-06 22:12:41 +00:00
while read line
do
2008-10-06 22:48:58 +00:00
postconf -e "$line"
2008-10-23 18:37:40 +00:00
done < $postfix_conf
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"
2006-04-26 12:28:53 +00:00
if [ -e /etc/courier/authmysqlrc ] ; then
chown root:root /etc/courier/authmysqlrc
chmod 640 /etc/courier/authmysqlrc
fi
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
if [ "$LOCALECHANGED" ] ; then
locale-gen
fi
fi
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
#######################################################################
2007-08-26 20:44:53 +00:00
# Reload services
2006-04-26 12:28:53 +00:00
#
2008-10-07 20:14:15 +00:00
for service in postfix bind9 courier-authdaemon \
2006-04-26 12:28:53 +00:00
courier-imap courier-imap-ssl courier-pop courier-pop-ssl \
cron proftpd; do
2009-02-17 21:20:23 +00:00
invoke-rc.d $service force-reload || true
2006-04-26 12:28:53 +00:00
done
#######################################################################
# Last touches
#
2011-03-04 13:05:55 +00:00
2006-04-26 12:28:53 +00:00
# Creating admin user if needed
2008-04-13 04:35:19 +00:00
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 ""
if su - www-data -c /usr/share/alternc/install/newone.php
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
echo "Il a <20> t<EFBFBD> impossible de cr<63> er un nouveau membre alternc. newone.php a retourn<72> un code d'erreur $?. V<> rifiez si la base MySQL, PHP, ainsi que le fichier local.sh sont bien configur<75> s. V<> rifiez aussi si des erreurs ne sont pas apparues plus haut dans l'installation."
fi
fi
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)
MYSQL_CONFIG="/etc/alternc/my.cnf"
mysql="/usr/bin/mysql --defaults-file=$MYSQL_CONFIG"
$mysql -B -e "update domaines set dns_action='update';"
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
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