#!/bin/sh
# Start the network interfaces

source /etc/sysconfig/config;

IS_ON=/bin/chkconfig
CONFIG=/var/config

# misc services/devices
#   this is a catchall script for misc. services or devices which can be 
# controlled via the chkconfig utility
# to add a service do two things
# 1) add the name to the list below
# 2) create a function called service_<service_name>, that contains a
#    start and stop definition
# note, stop will kill the services in the reverse order that they are started
#
services="vm"

service_vm()
{
	# this is chkconfig device
	SERVICE=vm

	case "$1" in 
		"start")
			if $IS_ON $SERVICE
			then
				if [ -e /var/config/${SERVICE}.options ]
				then
#					rm -f /var/config/.${SERVICE}.options.restore
#					cat /var/config/${SERVICE}.options | \
#					while read line 
#					do
#						echo ${line} | grep -sq '^#'
#						if [ $? -ne 0 -a ! -z "${line}" ]
#						then
#							ctl=`echo "$line" |awk '{print $3}' |cut -d'=' -f1`
#							sysctl ${ctl} | awk '{ print "sysctl -w " $1$2$3 }' >> /var/config/.${SERVICE}.options.restore
#						fi
#					done
					cat /var/config/${SERVICE}.options | \
					while read line
					do
						if [ "X${line}" != "X" ]
						then
							sysctl -w $line
						fi
					done
				fi 
			fi
			;;
		"stop")
			# nothing to do in this case
			;;
	esac
}

case "$1" in
    "start")
		if [ $# -eq 2 ]
		then
			service_${2} start
		else
			for service in $services
			do
				service_${service} start
			done
		fi
		;;
	"stop")
		if [ $# -eq 2 ]
		then
			service_${2} stop
		else
			echo ${services} | awk '{ for (i=NF;i>0;i--) print $i }' | \
			while read service
			do
				service_${service} stop
			done
		fi
		;;
	*)
		echo "Syntax is $0 start | stop"
		exit 255
esac
