#!/sbin/sh

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

case "$1" in
'start')
	set `/usr/bin/who -r`
	if [ $9 = "S" -o $9 = "1" -o $9 = "?" ]
	then
		/sbin/sh /etc/init.d/yp ypstart
	fi
	;;
'ypstart')
#	Configure NIS or NIS+
	if [ -f /etc/.UNCONFIGURED -a -x /usr/sbin/sysidnis ]
	then
		/usr/sbin/sysidnis > /dev/console 2>&1
	fi

#
# NIS (YP) Server side support. 
# 
# Ideally, this belongs before ypbind and after rpcbind, in the rpc 
# startup script. It is located here due to unbundled packaging.
#
	domain=`domainname`
	YPDIR=/usr/lib/netsvc/yp
	if [ X$domain != X -a -d /var/yp/$domain ];then
		echo "starting NIS (YP server) services:\c"
		if [ -f $YPDIR/ypserv ]; then
			$YPDIR/ypserv;	echo ' ypserv\c'
#			Master NIS server runs the XFR daemon.
#			$YPDIR/ypxfrd;	echo ' ypxfrd\c'
		fi

#		if [ -f $YPDIR/rpc.ypupdated ];then
#              		$YPDIR/rpc.ypupdated; echo ' ypupdated\c'
#		fi

#		Edit and uncomment this to automate rpc.yppasswdd startup.
#              	if [ -f $YPDIR/rpc.yppasswdd ];then
#              		$YPDIR/rpc.yppasswdd /var/yp/passwd -m \
#				passwd PWDIR=/var/yp; echo ' yppasswdd\c'
#		fi
		echo " done."
	fi
	;;
'stop')
	# Bring all of the YP "service" daemons to a halt.
	#
	daemons='ypserv ypxfrd rpc.yppasswdd rpc.ypupdated'
	pidlist=`/usr/bin/ps -ef`
	for DAEMON in $daemons
	do
		PID=`echo "$pidlist" | grep $DAEMON |awk '{print $2}'`
		if [ ! -z "$PID" ] ; then
			/usr/bin/kill  ${PID}
		fi
	done
	;;
*)
	echo "Usage: /etc/init.d/yp { start | stop }"
	;;
esac
