#!/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 '/') # replace this one unconditionnally CONFIG_FILES="etc/alternc/bureau.conf" 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 if [ -d /etc/postfix ]; then 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 if [ -e /etc/proftpd/proftpd.conf ]; then CONFIG_FILES="$CONFIG_FILES etc/proftpd/proftpd.conf etc/proftpd/welcome.msg etc/proftpd/modules.conf" 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 | grep -v 'Uid differs'|grep -v 'Gid differs' |grep -v 'Mode differs' | 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 # if [ "$MYSQL_HOST" != "localhost" -o -e /usr/sbin/mysqld ]; then echo "Setup MySQL and database..." /usr/share/alternc/install/mysql.sh "$MYSQL_HOST" "$MYSQL_USER" "$MYSQL_PASS" "$MYSQL_DATABASE" fi ######################################################################## # 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 chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf 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 # Enable vhost_alias apache module at the right place (ie: BEFORE mod_alias, but apache knows this ... ) apache-modconf apache enable mod_vhost_alias quiet