#! /bin/sh
#
# |-----------------------------------------------------------|
# | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
# | All Rights Reserved                                       |
# |-----------------------------------------------------------|
# |          Restricted Rights Legend                         |
# | Use, duplication, or disclosure by the Government is      |
# | subject to restrictions as set forth in                   |
# | subparagraph (c)(1)(ii) of the Rights in Technical        |
# | Data and Computer Software Clause of DFARS 252.227-7013.  |
# |         MIPS Computer Systems, Inc.                       |
# |         950 DeGuigne Avenue                               |
# |         Sunnyvale, California 94088-3650, USA             |
# |-----------------------------------------------------------|
#
# $Header: yp_client,v 1.2.1.1 92/06/24 13:35:08 marker Exp $
#
# start this node as a yp client

USAGE="usage: /etc/init.d/yp {start|stop}" ;
MFILE=/etc/my_yp_master

main() {
	case $1 in
	start)	yp_start ${1+"$@"} ;;
	stop)	yp_stop ${1+"$@"} ;;
	*)	echo "$USAGE"; exit 1 ;;
	esac
}

yp_start() {
	pid=`ps -e | grep 'y[p]bind' | sed 's/ *//' | sed 's/ .*$//'`
	if [ "x$pid" != "x" ] ; then
		echo
		echo "yp is running.  Please use '/etc/init.d/yp stop'."
		exit 1
	fi
	echo " ypbind\c"
	nohup /etc/ypbind -ypset </dev/null >/dev/null 2>&1
	sleep 1
	/usr/bin/ypwhich </dev/null >/dev/null 2>&1
	sleep 1
	if [ -r $MFILE ] ; then
		echo " ypset \c"
		/usr/etc/yp/ypset `cat $MFILE`
		if [ $? != 0 ] ; then
			echo
			echo "Please verify that $MFILE is correct."
		fi
	fi
	echo " ypwhich: \c"
	/usr/bin/ypwhich
}

yp_stop() {
	pid=`ps -e | grep 'y[p]bind' | sed 's/ *//' | sed 's/ .*$//'`
	if [ "x$pid" != "x" ] ; then
		kill $pid
	fi
}

main ${1+"$@"}
exit 0
