:
#      @(#)tcp.sh	5.10.1.6 Lachman System V STREAMS TCP  source
#
#	System V STREAMS TCP - Release 4.0
#
#   Copyright 1990 Interactive Systems Corporation,(ISC)
#   All Rights Reserved.
#
#	Copyright 1987, 1988, 1989 Lachman Associates, Incorporated (LAI)
#	All Rights Reserved.
#
#	The copyright above and this notice must be preserved in all
#	copies of this source code.  The copyright above does not
#	evidence any actual or intended publication of this source
#	code.
#
#	This is unpublished proprietary trade secret source code of
#	Lachman Associates.  This source code may not be copied,
#	disclosed, distributed, demonstrated or licensed except as
#	expressly authorized by Lachman Associates.
#
#	System V STREAMS TCP was jointly developed by Lachman
#	Associates and Convergent Technologies.
#
#      SCCS IDENTIFICATION

#
# TCP start/stop script
# Usage: tcp [ start | stop ]
#

#
# DOMAIN now set in DEFAULT
#

DEFAULT=/etc/default/tcp

PATH=/bin:/usr/bin:/etc:/usr/etc:/usr/local/bin
PROCS="cpd slink inetd strerr routed rwhod sendmail timed named syslogd rlogind telnetd rshd gated rarpd slattach bootpd pppd xntpd"

# 
# defaults will be overridden from /etc/default/tcp
#

DOMAIN=sco.COM
IPADDR=
NETMASK=
BROADCAST=

if [ -r $DEFAULT ]; then
	. $DEFAULT
fi

# figure out which kernel we're running
if [ -x /bin/ps ] ; then
    /bin/su root -c "/bin/ps -e" > /tmp/ps.err$$ 2>&1
    if grep "not the booted" /tmp/ps.err$$ > /dev/null ; then
	PS="/bin/ps -n /unix.old"
	K=/unix.old
    else
        PS="/bin/ps"
	K=/unix
    fi
    rm -f /tmp/ps.err$$
else
    echo "$0: Can't find ps"
    exit 1
fi

case "$1" in

start)
	set `who -r`
	if [ $9 != "S" ]; then
		exit 0
	fi
	/bin/su root -c "$PS -e" 2>/dev/null | \
		/usr/bin/fgrep slink > /dev/null 2>&1

	if [ $? -eq 0 ]; then
		exit 0
	fi
        echo "Starting TCP/IP: \c"
 
 	#
 	# Clean up temporary data files so the will be rebuilt freshly
 	#
 	rm -f /etc/netstat_data
 	rm -f /etc/arp_data
 	rm -f /etc/trpt_data

	#
	# Network initialization commands -- edit as appropriate.
	#
	# epump 	# for 3b2/EMD
	# nistart ni0	# for i386/NI

	#
	# STREAMS & socket initialization
	#
	cpd ; echo "cpd \c"
	slink ; echo "slink \c"
	ldsocket; echo "ldsocket \c"

	#
	# set the host name
	#
	hostname `uname -n`.$DOMAIN

	#
	# Interface configuration -- edit as appropriate.
	#
	ifconfig lo0 localhost
	ifconfig lan0 $IPADDR netmask $NETMASK broadcast $BROADCAST
#	ifconfig lan0 137.46.2.53 -trailers netmask 255.255.0.0 broadcast 137.46.255.255
#	ifconfig en0 `uname -n` $NETMASK -trailers $BROADCAST

	#
	# Daemons & other things -- edit as appropriate
	#
	strerr > /dev/console 2>&1 &
	echo "strerr \c"

	#
	# run these commands to build their cache files 
	#

	if [ -x /usr/bin/netstat ]; then
		/bin/su root -c "/usr/bin/netstat -a $K" > /dev/null 2>&1 &
	fi
	if [ -x /usr/bin/arp ]; then
		/bin/su root -c "/usr/bin/arp -a $K" > /dev/null 2>&1 &
	fi
	if [ -x /usr/bin/trpt ]; then
		/bin/su root -c "/usr/bin/trpt -a $K" > /dev/null 2>&1 &
	fi

	#
	# syslog daemon starts first
	#

	if [ -x /etc/syslogd -a -f /etc/syslog.conf ]; then
		syslogd  ; echo "syslogd \c"
	fi

#
# Initialize PPP interfaces before other things that care
# about interfaces
#
	if [ -x /etc/pppd -a -f /etc/ppphosts ] ;then
		pppd; echo "pppd \c"
	fi
	
#
# Name server should start before almost everything
#

	if [ -x /etc/named -a -f /etc/named.boot ]; then
		named  ; echo "named \c"
	fi

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

#
# Choice of routing daemons.
#
	if [ -x /etc/routed -a ! -f /etc/gated.conf ]; then
		routed -k $K ; echo "routed \c"
	fi

	if [ -x /etc/gated -a -f /etc/gated.conf ]; then
		/etc/gated ; echo "gated \c"
	fi

#	if [ -x /etc/rarpd -a -f /etc/ethers ]; then
#		/etc/rarpd -a ; echo "rarpd \c"
#	fi

#
# Uncomment these lines if you want to run timed.  Add -M
# to the timed command if you want this machine to be a
# potential master server.
#
#	if [ -x /etc/timed -a ! -f /etc/ntp.conf ]; then
#		timed ; echo "timed \c"
#	fi

#
# Xntpd - Don't run this at the same time as timed.
	if [ -x /etc/xntpd -a -f /etc/ntp.conf ]; then
		xntpd ; echo "xntpd \c"
	fi

#
# Rwhod can slow your systems down a lot.
#	if [ -x /etc/rwhod -a -d /usr/spool/rwho ]; then
#		rwhod ; echo "rwhod \c"
#	fi

	if [ -x /usr/lib/sendmail -a -f /usr/lib/sendmail.cf ]
	then
		/bin/su root -c " /usr/lib/sendmail -bd -q1h" 2>/dev/null ; echo "sendmail \c"
	fi

	echo ""
	;;

stop)

	echo "TCP Shutdown..."
# wait for lpd and snmpd to exit
	sleep 2

	/bin/su root -c "$PS -e" 2>/dev/null | \
		/usr/bin/fgrep portmap > /dev/null 2>&1
	if [ $? = 0 ] ; then
		echo "TCP cannot be shutdown while NFS is running..."
		echo "Please type 'nfs stop' before attempting to shutdown TCP."
		exit 1
	fi	
	/bin/su root -c "$PS -e" 2>/dev/null | \
		/usr/bin/fgrep snmpd > /dev/null 2>&1
	if [ $? = 0 ] ; then
		echo "TCP cannot be shutdown while snmp is running..."
		echo "Please type 'snmp stop' before attempting to shutdown TCP."
		exit 1
	fi	
	/bin/su root -c "$PS -e" 2>/dev/null | \
		/usr/bin/fgrep lpd > /dev/null 2>&1
	if [ $? = 0 ] ; then
		echo "TCP cannot be shutdown while remote line printing is running..."
		echo "Please type 'lpd stop' before attempting to shutdown TCP."
		exit 1
	fi	

	#
	# flush all routes to free up streams resources
	#
	route -n -f -k $K > /dev/null 2>&1

	#
	# Find all the other daemons
	#

	PX=""
	OR=""
	for P in $PROCS
	do
		PX="$PX$OR$P"
		OR="|"
	done
	PX="/$PX/"

	#
	# Toast them.
	#

	/bin/su root -c "$PS -e" 2>/dev/null | \
		/usr/bin/awk "$PX { print \"kill \" \$1 }" |\
		/bin/sh > /dev/null 2>&1

	# Wait a few seconds to allow the kills to take effect.
	echo "Stopping TCP/IP daemons..."
	_wait=6
	while [ "$_wait" != "0" ] ; do
		echo ".\c"
		sleep 1
		_wait=`/bin/expr $_wait - 1`
	done
	echo ""

	ldsocket -u > /dev/null 2>&1

	echo "TCP Shutdown Complete."
	;;

*)

	echo "Usage: $0 [ start | stop ]"
	exit 1
	;;

esac

exit 0
