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

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

  # See how we were called.
  case "$1" in
    start)
	echo -n "Starting network daemons "
	# Start syslogd.
	daemon /usr/sbin/syslogd

	# See if we want to start a name daemon.
	# First see if we have any routes set up to the rest of the world.
	netstat -rn | egrep -s -v "Kernel routing|Destination "
	if [ $? = 0 ]
	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
		grep -s nameserver /etc/resolv.conf
		if [ $? = 0 ]
		then
			grep -s "127\\.0\\.0\\.1" /etc/resolv.conf
			if [ $? = 0 ]
			then
				# localhost was listed.
				start=1
			fi
		else
			# No nameserver listed, default is localhost.
			start=1
		fi
		if [ $start = 1 ]
		then
			# Start 'er up!
			echo
			daemon /usr/sbin/named > /dev/null
		fi
	fi
	echo
	;;
    stop)
	# Right, stop all TCP services.
	echo -n "Shutting down network daemons "
	killproc syslogd
	killproc named
	echo
	;;
    *)
	# Oops someone made a typo.
	echo "Usage: /etc/init.d/netservers {start|stop}"
	exit 1
  esac

  exit 0
