#!/bin/sh
#
# chkconfig: 345 35 65
# description: virtualhosting Bring up/down the (virtual) interfaces \
#               used for virtal hosting
#
# Copyright (c) Ensim Corporation 2000, 2001   All Rights Reserved.
#
# This software is furnished under a license and may be used and copied
# only  in  accordance  with  the  terms  of such  license and with the
# inclusion of the above copyright notice. This software or any other
# copies thereof may not be provided or otherwise made available to any
# other person. No title to and ownership of the software is hereby
# transferred.
#
# The information in this software is subject to change without notice
# and  should  not be  construed  as  a commitment by Ensim Corporation.
# Ensim assumes no responsibility for the use or  reliability  of its
# software on equipment which is not supplied by Ensim.
#
#

# Source function library.
. /etc/rc.d/init.d/functions
. /etc/appliance/scriptsLib-3.0/common.lib

# See how we were called.
case "$1" in
  start)
	# preinstall check is done in webppliance-prolog now

	echo -n "Starting virtual hosting"
	for addr in `/sbin/listaliases`
	do
	    /sbin/applifconfig alias $addr
	    if [ $? != 0 ]; then
		/sbin/initlog -f local3 -s "virtualhosting: [warning] applifconfig for alias $addr failed"
	    fi
	done
        # need this touch, as init will require it to run the shutdown below
        touch /var/lock/subsys/virtualhosting                                    
	#XXX:???:this has to be replaced with siteinfo_detectchanges_boot (already in the tree)
        cat /etc/localtime > /home/virtual/FILESYSTEMTEMPLATE/siteinfo/etc/localtime
	if [ $? != 0 ]; then
	    /sbin/initlog -f local3 -s "virtualhosting: Couldn't copy /etc/localtime into FILESYSTEMTEMPLATE/siteinfo"
	    exit 1
	fi

        cat /etc/resolv.conf > /home/virtual/FILESYSTEMTEMPLATE/siteinfo/etc/resolv.conf
	if [ $? != 0 ]; then
	    /sbin/initlog -f local3 -s "virtualhosting: Couldn't copy /etc/resolv.conf into FILESYSTEMTEMPLATE/siteinfo"
	    exit 1
	fi

	#A little workaround
	if [ -x /sbin/quotaon ]; then
	    /sbin/quotaon -au 1> /dev/null 2>&1
	    if [ $? != 0 ]; then
		/sbin/initlog -f local3 -s "virtualhosting: [warning] /sbin/quotaon -au failed"
	    fi
	    /sbin/quotaon -ag 1> /dev/null 2>&1
	    if [ $? != 0 ]; then
		/sbin/initlog -f local3 -s "virtualhosting: [warning] /sbin/quotaon -ag failed"
	    fi
	fi
	echo
	;;
  stop)
	echo -n "Shutting down virtual hosting"
	for addr in `/sbin/listaliases`
	do
	    /sbin/applifconfig delete $addr 1> /dev/null 2>&1
	    if [ $? != 0 ]; then
		/sbin/initlog -f local3 -s "virtualhosting: [warning] applifconfig delete $addr failed."
	    fi
	done

	rm -f /var/lock/subsys/virtualhosting
	if [ $? != 0 ]; then
	    /sbin/initlog -f local3 -s "virtualhosting: rm -f /var/lock/subsys/virtualhosting failed."
	fi

	echo
	;;
  *)
	echo "Usage: $0 {start|stop}"
	exit 1
esac

exit 0

