#ident	"@(#)initpkg:common/cmd/initpkg/init.d/nfs	1.1.24.19"

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

mldmode > /dev/null 2>&1
if [ "$?" = "0" ]
then			# Enhanced Security running
	exit
fi

case "$1" in
'start')
	
	NETPATH="tcp:ipx:spx:ticlts:ticots:udp:ticotsord"
	export NETPATH

	# Clean up /etc/dfs/sharetab - remove all nfs entries
	if [ -s /etc/dfs/sharetab ]
	then
		/usr/bin/rm /tmp/newsharetab >/dev/null 2>&1
		while read path res fstype access descr
		do
			if [ "$fstype" != "nfs" ]
			then
				echo "$path\t$res\t$fstype\t$access\t$descr"
			fi
		done < /etc/dfs/sharetab >> /tmp/newsharetab
		/usr/bin/cp /tmp/newsharetab /etc/dfs/sharetab
		/usr/bin/rm /tmp/newsharetab
	fi

	# All nfs modules will be automatically loaded here
	if [ -s /etc/dfs/dfstab ]
	then
		/usr/sbin/shareall -F nfs
	fi

	if [ -x /usr/lib/nfs/nfsd ]
	then
		/usr/lib/nfs/nfsd -a &
	fi
	if [ -x /usr/lib/nfs/biod ]
	then
		/usr/lib/nfs/biod &
	fi
	if [ -x /usr/lib/nfs/mountd ]
	then
		(umask 022; >/etc/rmtab)
		/usr/lib/nfs/mountd &
	fi
	if [ -x /usr/lib/nfs/statd -a -x /usr/lib/nfs/lockd ]
	then
		if [ -f /etc/smworking ]
		then
			/usr/bin/rm /etc/smworking
		fi
		/usr/lib/nfs/statd &
		/usr/lib/nfs/lockd &
	fi
	if [ -x /usr/lib/nfs/bootparamd ]
	then
		/usr/lib/nfs/bootparamd &
	fi
	if [ -x /usr/lib/nfs/pcnfsd ]
	then
		/usr/lib/nfs/pcnfsd &
	fi

	# Wait until all daemons are running before calling mountall
	wait

	# Mount all NFS files listed in /etc/vfstab
	/sbin/mountall -F nfs &

	if [ -x /usr/lib/nfs/automount -a -s /etc/auto.master ]
	then
		/usr/lib/nfs/automount
	fi
	;;
'stop')
	if [ -f /etc/rmtab ]
	then
		echo > /etc/rmtab
	fi
	if [ -f /etc/smworking ]
	then
		/usr/bin/rm /etc/smworking
	fi

	# Do this now to avoid trying to umount without daemons running.

	/sbin/umountall -k -F nfs

	# Clean up sharetab before going down.

	if [  -s /etc/dfs/sharetab ]
	then
		/usr/sbin/unshareall -F nfs
	fi

	if [ -z "$_AUTOKILL" ]
	then
		kill -9 `/usr/bin/ps -e | /usr/bin/sed -n \
	                -e'/ biod$/s/[^0-9 \t].*//p' \
	                -e'/ nfsd$/s/[^0-9 \t].*//p' \
	                -e'/ mountd$/s/[^0-9 \t].*//p' \
	                -e'/ lockd$/s/[^0-9 \t].*//p' \
	                -e'/ statd$/s/[^0-9 \t].*//p' \
	                -e'/ bootpara$/s/[^0-9 \t].*//p' \
	                -e'/ pcnfsd$/s/[^0-9 \t].*//p'` 2>/dev/null
	fi

	# kill automount with -15, not -9
	kill `/usr/bin/ps -e | /usr/bin/sed -n \
		-e'/ automoun$/s/[^0-9 \t].*//p'` 2>/dev/null

	if [ -z "$_AUTOKILL" ]
	then
		# unload all nfs modules
		modadmin -U nfs klm krpc des ktli 2>/dev/null
	fi
	;;
*)
	echo "Usage: /etc/init.d/nfs { start | stop }"
	;;
esac
