:
#		(C) 1989-1990 The Santa Cruz Operation, Inc.  All Rights
#		Reserved.  The user has unlimited right to use, modify
#		and incorporate this code into other products provided
#		it is used with SCO products and the user includes
#		this notice and the associated copyright notices with
#		any such application.
#
# This script is for use on machines without netconfig.  When the user types
# mkdev 'board' (eg mkdev emB) then this script will execute the appropriate
# netconfig script to configure the board.
#
#		Copyright (c) 1992 Cogent Data Technologies, Inc.
#		All Rights Reserved
#
NETCONF=/usr/lib/netconfig
CONF=/etc/conf
PATH=/bin:/usr/bin:/etc/:$CONF/bin:$LIB
OK=0;	FAIL=1;	RELINK=2;

getyn() {
	while	echo "$* (y/n/q) \c">&2
	do	read yn rest
		case $yn in
			[yY]) return 0				;;
			[nN]|[qQ]) return 1			;;
		*)	echo "Please answer y,n or q" >&2	;;
		esac
	done
}

ask_installing() {
	drv=$1
	while	echo "Add (configure) or remove the $drv driver or q to quit (a/r/q) : \c">&2
	do	read yn rest
		case $yn in
			[aA]) return 0				;;
			[rR]) return 1				;;
			[qQ]) exit $OK				;;
		*)	echo "Please answer 'a' or 'r'" >&2	;;
		esac
	done
}

# main()
#
if [ $# = 0 ]
then
	base=`basename $0`
else
	base=$1
fi

/etc/em-lliconfig

relink="N"
first_board="Y"
inst_or_remv="remove"
ask_installing $base && inst_or_remv="install"

cd $NETCONF/info
if [ "$inst_or_remv" = "install" ]
then
#	possbds=`ls ${base}* 2>/dev/null`
	possbds="${base}0 ${base}1 ${base}2 ${base}3"
else
	possbds=`ls -r ${base}* 2>/dev/null`
fi

if [ "$possbds" = "" ]
then
	echo "No netconfig scripts found for $base"
	exit $FAIL
fi

mktcpaug=""
for bd in $possbds
do
	if [ "$inst_or_remv" = "install" ]
	then
		script=$NETCONF/init/$bd
	else
		script=$NETCONF/remove/$bd
	fi
	if [ ! -f $script ]
	then
		echo "Warning: netconfig script ($script) doesn't exist; skipping it."
		continue
	fi

	if [ "$first_board" = "N" -a "$inst_or_remv" = "install" ]
	then
		echo
		getyn "Do you have another $base board to $inst_or_remv?" || break
	fi
	first_board="N"

	# Execute the netconfig script
	$script - - mkdev lli y
	ret=$?
	if [ $ret = $FAIL ]
	then
		exit $FAIL
	elif [ $ret = $RELINK ]
	then
		relink="Y"
		mktcpaug="${mktcpaug} ${base}"
	fi
done

if [ "$inst_or_remv" = "install" ]
then
	echo
	getyn "Do you want to configure TCP/IP for $base ?" && /usr/lib/lli/mkem-tcp $mktcpaug
fi

if [ "$relink" = "Y" ]
then
	echo
	getyn "Relink the kernel now?" || exit $OK

	cd /etc/conf/cf.d
	./link_unix
fi
