#! /sbin/sh
#
# NOTE:    This script is not configurable!  Any changes made to this
#          scipt will be overwritten when you upgrade to the next
#          release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
#          is unbootable.  Do not modify this script.
#

#
# Not supported on all systems
# vtdaemon responds to vt requests from other systems
# See vtdaemon(1m) for more information about the vtdaemon.
#

PATH=/sbin:/usr/sbin:/usr/bin
export PATH

rval=0
set_return() {
	x=$?
	if [ $x -ne 0 ]; then
		echo "EXIT CODE: $x"
		rval=1
	fi
}


case $1 in
start_msg)
	echo "Start vt daemon"
	;;

stop_msg)
	echo "Stop vt daemon"
	;;

'start')
	if [ -f /etc/rc.config.d/vt ] ; then
		. /etc/rc.config.d/vt
	else
		echo "ERROR: /etc/rc.config.d/vt file MISSING"
	fi
	if [ $VTDAEMON_START -eq 1 ] && [ -x /usr/sbin/vtdaemon ] \
				&& [ -c /dev/lan0 ]; then
		case `hostname` in
		$VTGATEWAY)
			echo "starting the gateway vtdaemon"
			/usr/sbin/vtdaemon $VTGOPTS $VTGINTERFACES
			set_return
			;;
		*)
			echo "starting the vtdaemon"
			/usr/sbin/vtdaemon
			set_return
			;;
		esac
	else
		rval=2
	fi

	;;

'stop')
	#
	# Determine PID of process(es) to stop
	#
	pid=`ps -e | awk '$NF~/vtdaemon/ {print $1}'`
	if [ "X$pid" != "X" ]; then
		if kill $pid; then
			echo "vtdaemon stopped"
		else
			set_return
			echo "Unable to stop vtdaemon"
		fi
	fi

	;;

*)
	echo "usage: $0 {start|stop}"
	rval=1
	;;
esac

exit $rval
