#!/bin/sh
#
# Copyright (c) 1993, by Sun Microsystems, Inc.
#
#ident	"$Header: /net/projects/S2.6/cvs/os_net/src_ws/usr/src/tadcmd/locations/init.d/ksrv,v 1.1 1997/12/01 08:58:17 ang Exp $"
#
#LocINFO Keyserv daemon
#

killproc() {		# kill the named process(es)
	pid=`/usr/bin/ps -e |
	     /usr/bin/grep " ${1}$" |
	     /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
	[ "$pid" != "" ] && kill -TERM $pid
}

procexist() {
    pid=`/usr/bin/ps -e | /usr/bin/grep " ${1}$" |
	     /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
    if [ -z "$pid" ]
    then
	return 1
    fi
    return 0
}

#
# Start/stop keyserv
#

case "$1" in

'start')
    if [ -f $LOCDB/etc/.rootkey ]
    then
	cp -p $LOCDB/etc/.rootkey /etc
    fi
    #
    # Start the key service.
    #
    if [ -x /usr/sbin/keyserv ] ; then
	/usr/sbin/keyserv > /dev/console 2>&1
    fi
    ;;

'stop')
    killproc keyserv
    rm -f /etc/.rootkey
    ;;

'create')
    if [ -f /etc/.rootkey ]
    then
	cp -p /etc/.rootkey $LOCDB/etc
    fi
    exit `procexist keyserv`
    ;;

*)
    echo "Usage: $0 { start | stop | create }" 1>&2
    ;;
esac

exit 0
