#!/bin/sh -f
#
# Start/Stop NetLS daemon
#
# Copyright 1988-1991 Silicon Graphics, Inc.
# All rights reserved.
#
# This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
# the contents of this file may not be disclosed to third parties, copied or
# duplicated in any form, in whole or in part, without the prior written
# permission of Silicon Graphics, Inc.
#
# RESTRICTED RIGHTS LEGEND:
# Use, duplication or disclosure by the Government is subject to restrictions
# as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
# and Computer Software clause at DFARS 252.227-7013, and/or in similar or
# successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
# rights reserved under the Copyright Laws of the United States.

NETLS=/usr/etc
CONFIG=/etc/config
IS_ON=/etc/chkconfig
SU="/bin/su daemon -c"
OPTIONS=

case "$1" in
'start')
	if $IS_ON netls && test -x $NETLS/netlsd; then

		cd /var/netls
		if $IS_ON network ; then
			if $IS_ON verbose; then
                        	echo "Network flag on"
				echo "Starting netlsd"
			fi
                else
                        echo "Cannot start netlsd as network is off"
                        exit 1
                fi
		if test -f $CONFIG/netlsd.options; then
			OPTIONS="`cat $CONFIG/netlsd.options`"
		fi
		#
		# Run as as the user "daemon" if possible
		#
		if $SU echo >/dev/null 2>&1; then
			#
			# Make sure netlsd can write to all the places that
			# it needs to
			#
			chown daemon /var/netls
			set +f
			if test -f /var/netls/lic_db; then
				chown daemon /var/netls/*db*
			fi
			if test -f /var/netls/log_file; then
				chown daemon /var/netls/log_file
			fi
			$SU "$NETLS/netlsd $OPTIONS" &
		else
			$NETLS/netlsd $OPTIONS &
		fi

	fi
	;;

'stop')
	killall -TERM  netlsd

	;;

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