#!/sbin/sh
#
# network	Start the basic networking servers.
#
# Version:	@(#) /sbin/init.d/network 1.01 26-Oct-1993
#
# Author:	Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#

  # Source function library.
  . /sbin/init.d/functions

  # See how we were called.
  case "$1" in
    start)
        echo -n "Starting network daemons: "
	daemon /usr/sbin/lpd
	## in.timed does not work on my system
	## `recvfrom: Connection refused'
	## by my own machine -- why
	##[ -f /usr/sbin/netdate ] && netdate -l 4 wilma > /dev/null
	##daemon /usr/sbin/in.timed -t

	# ntp1 and ntp2 defined in /etc/hosts
	[ -f /usr/sbin/ntpdate ] && ntpdate -bs ntp1 ntp2
	daemon /usr/sbin/xntpd

	# See if we want to start a name daemon.
	# First see if we have any routes set up to the rest of the world.
	route="`netstat -rn | egrep -sv 'Kernel routing|Destination'`"
	if [ "$route" != "" ]
	then
	    # Ok, we have some route. If we want to be a name
	    # server, localhost is listed in /etc/resolv.conf as
	    # nameserver, OR no nameserver is listed.
	    start=0
	    name="`grep -s nameserver /etc/resolv.conf`"
	    if [ "$name" != "" ]
	    then
		local="`grep -s '127.0.0.1' /etc/resolv.conf`"
		if [ "$local" != "" ]
		then
		    # localhost was listed.
		    start=1
		fi
	    else
		# No nameserver listed, default is localhost.
		start=1
	    fi
	    if [ $start = 1 ]
	    then
		# Start 'er up!
		daemon /usr/sbin/named
	    fi
	fi
	echo
	;;
    stop)
	# Right, stop all TCP services.
	echo -n "Shutting down network daemons: "
	##killproc -TERM in.timed
	killproc -TERM xntpd
        killproc -TERM named
	killproc -TERM lpd
	echo
	;;
    *)
	# Oops someone made a typo.
	echo "Usage: /sbin/init.d/network {start|stop}"
	exit 1
  esac

exit 0
