#!/sbin/sh
#
# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)vca.sh	1.4	03/06/11 SMI"

PATH=/sbin:/usr/bin:/usr/sbin; export PATH
DRIVER=vca

#
# This script emulates ddi-force-attach and ddi-no-autodetach, by loading
# the driver in memory at start of day if any instances are found, and
# then holding it in memory with a specific modload.  Note that
# modunload -i 0 will not cause a driver to unload that has been loaded
# with a specific modload.
#
# On Solaris 9 (and later?), this script is still needed due to a possible 
# hang condition when using ddi-force-attach. Note: the modload command
# is not needed since we specify ddi-no-autodetach in vca.conf. 
#
case "$1" in
'start')
	case `uname -r` in
	5.[01234567]*)
		# this package is not supported on these older releases
		echo "The $DRIVER driver is not supported on this release."
		;;
	5.8)
		devfsadm -i $DRIVER >/dev/null 2>&1
		if [ $? -eq 0 ]; then
		    # holds it in memory to keep it from vanishing
		    modload -p drv/$DRIVER
		fi
		;;
	*)
		# everything else should be 5.9 and newer...
		# On these releases, we can rely on 
		# ddi-no-autodetach to get the right behavior.
		devfsadm -i $DRIVER >/dev/null 2>&1
		;;
	esac

	#
	# Now we need to start the keystore daemon
	#
	[ ! -x /opt/SUNWconn/cryptov2/sbin/vcad ] && exit 0
	#
	# If the daemon is already running, then leave it alone
	#
	if /usr/bin/pgrep -x -u 0 -P 1 vcad >/dev/null 2>&1
	then
		exit 0
	fi
	/opt/SUNWconn/cryptov2/sbin/vcad
	
	;;
           
'stop')
	#
	# Stop the daemon.
	#
	/usr/bin/pkill -x -u 0 -P 1 vcad
       	;; 

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