2006-04-26 12:28:53 +00:00
#!/bin/sh
#
# 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 !
set -e
#######################################################################
# 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
etc/bind/templates/named.template etc/bind/named.conf"
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
2006-04-26 12:28:53 +00:00
CONFIG_FILES="$CONFIG_FILES etc/postfix/main.cf etc/postfix/myalias.cf
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
CHANGED="`tar -zdf "$INSTALLED_CONFIG_TAR" -C / 2> /dev/null |
2006-05-04 09:03:31 +00:00
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`"
if [ ! -z "$CHANGED" ]; then
echo "The following configuration files has changed since last AlternC"
echo "installation :"
echo "$CHANGED"
echo ""
if [ "$1" = "force" ]; then
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 ""
echo "Please examine the situation closely and call '$0 force'"
echo "if you still want to actually overwrite these files."
exit 1
fi
fi
fi
#######################################################################
# Prepare template expansions
#
. /etc/alternc/local.sh
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 "$BIND_INTERNAL" ]; then
BIND_INTERNAL="$BIND_INTERNAL;"
fi
if [ -z "$MONITOR_IP" ]; then
MONITOR_IP="127.0.0.1"
fi
SED_SCRIPT="
s\\%%hosting%%\\$HOSTING\\;
s\\%%fqdn%%\\$FQDN\\;
s\\%%public_ip%%\\$PUBLIC_IP\\;
s\\%%internal_ip%%\\$INTERNAL_IP\\;
s\\%%monitor_ip%%\\$MONITOR_IP\\;
s\\%%ns1%%\\$NS1_HOSTNAME\\;
s\\%%ns2%%\\$NS2_HOSTNAME\\;
s\\%%bind_internal%%\\$BIND_INTERNAL\\;
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\\%%mynetwork%%\\$SMTP_RELAY_NETWORKS\\;
s\\%%warning_message%%\\$WARNING\\;
s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
s\\%%version%%\\$VERSION\\;
s\\%%ns2_ip%%\\$NS2_IP\\;
"
#######################################################################
# 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
tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
#######################################################################
# Expand templates in the right place
#
for file in $CONFIG_FILES; do
TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
if [ -f "$TEMPLATE" ]; then
sed -e "$SED_SCRIPT" < $TEMPLATE > /$file
fi
done
#######################################################################
# Save installed files to check them during next install
#
tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
######################################################################
# Initialize database
#
2007-08-23 08:25:45 +00:00
if [ "$MYSQL_HOST" != "localhost" -o -e /usr/sbin/mysqld ]; then
2006-04-26 12:28:53 +00:00
echo "Setup MySQL and database..."
2007-08-23 08:24:15 +00:00
/usr/share/alternc/install/mysql.sh "$MYSQL_HOST" "$MYSQL_USER" "$MYSQL_PASS" "$MYSQL_DATABASE"
2007-08-23 08:25:45 +00:00
fi
2006-04-26 12:28:53 +00:00
########################################################################
# Ad-hoc fixes
#
# Add access to the management panel
ln -nsf /var/alternc/bureau /var/alternc/dns/$FQDN_LETTER/$FQDN
# Update l18n files
/usr/share/alternc/install/dopo.sh
# Bind stuff
touch /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
chown root:bind /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
2006-04-26 14:00:52 +00:00
chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
2006-04-26 12:28:53 +00:00
touch /var/run/alternc/refresh_slave
/usr/lib/alternc/slave_dns
# Apache will not start without this file
touch /var/alternc/apacheconf/override_php.conf
2007-05-11 08:12:43 +00:00
# Enable vhost_alias apache module at the right place (ie: BEFORE mod_alias, but apache knows this ... )
2007-08-23 17:14:17 +00:00
# well, apache-modconf works like crap in a shell script ...
# apache-modconf apache enable mod_vhost_alias quiet </dev/null || true
# apache-modconf apache enable `dpkg -l libapache-mod-php*|grep ii | cut -f 3 -d ' '|cut -b 11-18|sed -e 's/-/_/'` quiet </dev/null|| true
if ! grep -q "vhost_alias_module" /etc/apache/modules.conf
then
mv /etc/apache/modules.conf /etc/apache/modules.conf.alternc-dist
cat /etc/apache/modules.conf.alternc-dist | sed -e 's/LoadModule config_log_module/LoadModule vhost_alias_module \/usr\/lib\/apache\/1.3\/mod_vhost_alias.so\nLoadModule config_log_module/' > /etc/apache/modules.conf
rm /etc/apache/modules.conf.alternc-dist
fi
if ! grep -q "php5_module" /etc/apache/modules.conf
then
2007-08-26 18:07:28 +00:00
echo "LoadModule php5_module /usr/lib/apache/1.3/libphp5.so" >>/etc/apache/modules.conf
2007-08-23 17:14:17 +00:00
fi
if ! grep -q "php5_module" /etc/apache-ssl/modules.conf
then
2007-08-26 18:07:28 +00:00
echo "LoadModule php5_module /usr/lib/apache/1.3/libphp5.so" >>/etc/apache-ssl/modules.conf
2007-08-23 17:14:17 +00:00
fi
2007-08-26 18:33:40 +00:00
# We update ucf, that's bad isn't it ? ;)
2007-08-26 19:01:52 +00:00
ucf /etc/apache/modules.conf /etc/apache/modules.conf
ucf /etc/apache-ssl/modules.conf /etc/apache-ssl/modules.conf
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
if [ -e /etc/postfix/myalias.cf -o -e /etc/postfix/mydomain.cf -o -e /etc/postfix/mygid.cf -o -e /etc/postfix/myvirtual.cf ]; then
chown root:postfix /etc/postfix/my*
chmod 640 /etc/postfix/my*
fi
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
2006-04-26 12:28:53 +00:00
#######################################################################
2007-08-26 19:05:22 +00:00
# Restart services
2006-04-26 12:28:53 +00:00
#
for service in apache apache-ssl postfix bind9 courier-authdaemon \
courier-imap courier-imap-ssl courier-pop courier-pop-ssl \
cron proftpd; do
2007-08-26 19:05:22 +00:00
test -x /etc/init.d/$service && invoke-rc.d $service restart || true
2006-04-26 12:28:53 +00:00
done
#######################################################################
# Last touches
#
# Add basedir protection
/usr/lib/alternc/basedir_prot.sh
# Creating admin user if needed
HAS_ROOT="`mysql -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" -e "SELECT COUNT(*) FROM membres WHERE login = 'admin' OR login = 'root' and su = 1" | tail -1`"
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