#
#        Copyright(C) 1997 Network Flight Recorder, Inc.
#        All rights reserved.
#
#        Use and distribution of this software and its source code
#        are governed by the terms and conditions of the
#        Network Flight Recorder Software License ("LICENSE.TXT")
#
# By Mark Sienkiewicz / NFR
#

HOME=`pwd`
export HOME

rm -rf debug* nfrd.log vars
mkdir vars

verb=""
no_ncode=""
for x in $*
do
	case "$1"
	in
	-v)
		verb="-V -V -V -V -d -d -d -d -d"
		echo verbose nfrd selected
		;;
	-n)
		no_ncode="yes"
		echo not loading N code
		;;
	esac
	shift
done

sock=100`date +%S`
echo $sock > etc/sock_id

sync
echo give sync some time...
sleep 1


bin/nfrd $verb -t 10000 -v vars -p $sock &

echo 'Type INTR to kill control and stop viewing nfrd output'
echo 'nfrd will continue to run'

sleep 2

case  "$no_ncode" 
in
"yes") exit 0
	;;
esac

(
echo read conf/timestamp.nfr
cd packages
for p in *
do
	if [ ! -d  $p ]
	then
		continue
	fi
	if test -f $p.cfg 
	then
		grep "^enabled=false" $p.cfg >/dev/null && continue
	fi
	if test -f $p.nfr
	then
		# echo scope $p
		echo read packages/$p.nfr
	fi
	(
	cd $p
	for b in *.cfg
	do
		if grep "^enabled=true" $b > /dev/null
		then
			n=`echo $b | sed s/\\.cfg$//`
			# echo scope ${p}_$n >&2
			echo read packages/$p/$n.nfr >&2
			# echo scope ${p}_$n
			echo read packages/$p/$n.nfr
		fi
	done
	)
done
# one of these should work...
echo intf ef0
echo intf le0
# this one is common on linux
echo intf eth0
) | bin/control localhost $sock

