#! /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: netdaemons,v 1.17.1.1 92/06/24 13:35:02 marker Exp $
#
# Initialize/Shutdown the network daemons.
#

PATH=/net:/bin:/etc:/usr/bin:/usr/etc:/usr/ucb:

not() {
	eval ${1+"$@"} && return 1 || return 0
}

main() 
{
	case "$1" in
		start)
			netdaemons_start
			;;
		stop)
			;;
		*)
			echo "$0: usage: `basename $0`: {start|stop}"
			exit 1
			;;
	esac
}

netdaemons_start()
{
	#
	# Have they set the hostname yet?  If not, then the network has
	# not been set up, so don't start the daemons.
	#
	if [ "`hostname`" = "no_hostname_set" ] ; then
		echo "WARNING: No hostname set.  Network daemons not started"
		exit 0
	fi

	#
	#   Check for existance of tcp first.
	#
    	if [ ! -x /etc/havetcp ] || not /etc/havetcp
	then
		exit 0
	fi

	if [ -f /etc/named.boot -o -f /etc/init.d/yp ]; then
	    echo "NOTE: 30 second pause after gated/routed starts."
	fi

	echo "Internet daemons:\c"

	if [ -x /etc/gated -a -r /etc/gated.conf ]; then
		rm -f /etc/gated.pid
		gated;				echo " gated\c"
	elif [ -x /etc/routed ]; then
		if [ -r /etc/routed.conf ]; then
			routed `sed -n 1p /etc/routed.conf`
		else
			routed
		fi
		echo " routed\c"
	fi

	# Wait 30 seconds for routed/gated to get routing tables, so
	# named will succeed.
	if [ -f /etc/named.boot -o -f /etc/init.d/yp ]; then
	    sleep 30;
	fi

	# snmpd
	if [ -x /etc/snmpd ]; then
		/etc/snmpd;		echo " snmpd\c"
	fi

	# snmptrapd
	if [ -x /etc/snmptrapd ]; then
		/etc/snmptrapd;		echo " snmptrapd\c"
	fi

	#  named
	#  If there is nothing at /etc/named.pid, make the link
	#
	rm -f /usr/var/run/named.pid
	if test ! -f /etc/named.pid -a ! -h /etc/named.pid
		then
		ln -s /usr/var/run/named.pid /etc/named.pid
	fi
	if [ -x /etc/named -a -r /etc/named.boot ]; then
		/etc/named /etc/named.boot;		echo " named\c"
	fi

	#   Add routing commands here
	#   Example: "route add destination gateway 1"
	#
	rpcbind > /dev/console 2>&1 &
						echo " rpcbind\c"
	inetd
						echo " inetd\c"

	#   Small networks can use rwho.  However, large sites, with > 20 rwho
	#   machines can saturate the network.  In large networks, comment out
	#   the following 6 lines.
	if [ -x /usr/etc/rwhod ]; then
		if [ ! -d /usr/spool/rwho ]; then
			mkdir /usr/spool/rwho
	    	fi
		rwhod;				echo " rwhod\c"
	fi

	#  Start up timed if timed.conf is present.  The distributed system
	#  is supplied with a "slave" timed.conf, so a bidding will now
	#  take place to elect a master.  User processes will not be started
	#  until a master is elected.
	#
	if [ -x /etc/timed -a -r /etc/timed.conf ]; then
		state=`sed -n 1p /etc/timed.conf`
		case "$state" in
			[Mm][Aa][Ss][Tt][Ee][Rr])
				/etc/timed -M `tail +2 /etc/timed.conf`
					echo " timed(master)\c"
				;;
			[Ss][Ll][Aa][Vv][Ee])
				/etc/timed `tail +2 /etc/timed.conf`
					echo " timed(slave)\c"
				;;
			*)
				/etc/timed
					echo " timed(slave)\c"
				;;
		esac
	fi
	echo "."
}


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



