#!/bin/sh
#
#	nsfnett3 Rover Startup Script Source
#
#		This file is machine generated - do not edit 
#
#
# @wbn  02/03/92        Modified startup to use a pid File mechanism rather
#                       than a ps aux | grep Process mechanism to assure
#                       daemon is not already running. (Linda Suggestion)
#
#	Do this command periodically to update network picture:
#
#
#
TZ=CUT0		#Assure logs are in Central Universal Time
export TZ
autokill=YES
PINGKYDIR=/usr/local/rover/data/InetRover
#PINGKYDIR=/rtdata/rover/logs/InetRover

export PINGKYDIR
NETWORK=umnet
NETWORKSTATUSFILE=$PINGKYDIR/$NETWORK.STATUS
COMMUNITY=public
#DODISCOVERY=DoDiscovery
if [ "$DODISCOVERY" = "DoDiscovery" ]
then
	SUBNET=141.211.0.0
	SUBNETMASK=255.255.0.0
	SEEDNODE=`ping 141.211.255.255 10 10 | grep from | awk '{ print $4}' | sort | uniq | awk -F: '{ print $1 }'`
	echo `date` Discovering $NETWORK starting with $SEEDNODE
	Discover -c $COMMUNITY -n $NETWORK -r 10 -t 10 -s $SUBNET -m $SUBNETMASK -h $SEEDNODE
cat $PINGKYDIR/$NETWORK.LINKS | awk '{ if ( $1==18) print $3" "$8" 0"; if ($1==22) print $3" "$8" 3"}' >$PINGKYDIR/$NETWORK.LinkSpeed.LW

fi
pidFILE="$PINGKYDIR/$NETWORK.pid"
#
#       Assure no other Rover of this type is running in my PINGKYDIR
#
if [ -r $pidFILE ]
then
        ProcessNum=`cat $pidFILE`
        echo '*************************** ERROR ******************************'
        echo '**'" $0  already running:  Apparently Process ID="$ProcessNum
        echo '** ( pid file exists: '$pidFILE' )'
        echo '*************************** ERROR ******************************'
	if [ "$autokill" = "YES" ]
	then
		echo "auto kill is enabled - Killing old $0 process"
        	ps aux | grep -v grep | grep $ProcessNum
		kill $ProcessNum
		echo ""
		echo `date`" SUCCESS: $0 is now starting - old process was killed"
	else
        	echo "Kill This process and restart - Your request is ignored."
        	echo ""
        	exit 1
	fi
fi

if [ -r $NETWORKSTATUSFILE ]
then
	ls -l $NETWORKSTATUSFILE
else
	echo "">$NETWORKSTATUSFILE
fi
echo $$ > $pidFILE 	#Install a Process ID Registration File
#
#	First time through, resolve IP addresses to DNS names
#	Otherwise, we'll leave the IP Addresses as names
#
meritpoller -t $NETWORK -c $COMMUNITY -s $NETWORK.STATUS  -r

while :
do
	( meritpoller -t $NETWORK -c $COMMUNITY -s $NETWORK.STATUS 2>&1 ) >/tmp/$NETWORK.log
	( SortStatus -P UMN_ -s $NETWORK.STATUS 2>&1  ) >/dev/null # >>$PINGKYDIR/rover.log.`day -0`

	if [ -r $PINGKYDIR/$NETWORK.SLEEP ]
	then
		SLEEPTIME=`cat $PINGKYDIR/$NETWORK.SLEEP`
	fi
	if [ "$SLEEPTIME" = "" ]
	then
		SLEEPTIME=100
	fi
	sleep $SLEEPTIME
done
