#!/bin/sh
#ident	"@(#)nfs.server	1.11	93/08/16 SMI"	/* SVr4.0 1.1.13.1	*/

if [ ! -d /usr/bin ]
then			# /usr not mounted
	exit
fi

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


# Start/stop processes required for server NFS

case "$1" in
'start')

	# Clean up /etc/dfs/sharetab - remove all nfs entries
	#
	if [ -f /etc/dfs/sharetab ] ; then
		/usr/bin/awk '$3 != "nfs"' /etc/dfs/sharetab |
		/usr/bin/sed -e 's/ /	/' > /tmp/sharetab
		mv /tmp/sharetab /etc/dfs/sharetab
		chmod 644 /etc/dfs/sharetab
	fi

	[ -f /etc/dfs/dfstab ] && /usr/sbin/shareall -F nfs

	if grep -s nfs /etc/dfs/sharetab >/dev/null ; then
		/usr/lib/nfs/nfsd -a 16
		/usr/lib/nfs/mountd
	fi

	#
	# if /tftpboot exists become a boot server
	#
	if [ -d /tftpboot ] ; then
		/usr/sbin/in.rarpd -a
		/usr/sbin/rpc.bootparamd
	fi
	;;

'stop')
	if grep -s nfs /etc/dfs/sharetab >/dev/null ; then
		/usr/sbin/unshareall -F nfs
	fi
	killproc nfsd
	killproc mountd
	killproc bootpara
	killproc in.rarpd
	;;
*)
	echo "Usage: /etc/init.d/nfs.server { start | stop }"
	;;
esac
