:
#      @(#)sl0	5.4.1.3 Lachman System V STREAMS TCP  source
#      SCCS IDENTIFICATION
#
#	System V STREAMS TCP - Release 4.0
#
#	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.
#
#
: ${OK=0} ${FAIL=1} ${RELINK=2}
PATH=/bin:/usr/bin:/etc:/etc/conf/bin

LOWER_PRD=$1
LOWER_IF=$2
UPPER_PRD=$3
UPPER_IF=$4
CONFIGURE=$5
base=`basename $0`
drv=`echo $base | sed -e 's/[0-9]*$//'`
unit=`expr $base : '.*\(.\)'`
onemore=`expr $unit + 1`

tmp=/tmp/slip$$
NETCF=/usr/lib/netconfig
UNITS=4		# Maximum number of duplicated scripts
		# This limits the number of slip lines configurable

# Function declarations

##############################################################################
#
# Remove temp files and exit with the status passed as argument
#
cleanup() {
	trap '' 1 2 3 15
	[ "$tmp" ] && rm -f $tmp* 
	exit $1
}

##############################################################################
#
# Remove drivers from link kit then cleanup
#
cleanup2() {
	trap '' 1 2 3 15
	/etc/conf/bin/idinstall -d -e slip
	cleanup $1
}

##############################################################################
#
# Print an error message
# Usage: error "message"
# Argument is a quoted error message
#
Error() {
	echo "\nError: $*" >&2
	return 1
}


##############################################################################
#
# Print a warning message
# Usage: warning "message"
# Argument is a quoted warning message
#
warning() {
	echo "\nWarning: $*"
}

##############################################################################
#
# Print a message
# Argument is a quoted message
#
message() {
	echo "$*"
}

##############################################################################
# 
# Now bump to enable the next unit
#
bump() {
	dir=`pwd`
	cd $NETCF/info
	if [ $onemore -lt $UNITS ] ; then
		newfile=${drv}${onemore}
		sed -e '/^NAME=.*'"[^0]"'/s/0\"/'$onemore'\"/p' \
		    -e '/^DESCRIPTION=.*'"[^0]"'/s/0\"/'$onemore'\"/p' ${drv}0 \
		> $newfile
		chown bin $newfile
		chgrp bin $newfile
		chmod 750 $newfile
		cd $NETCF/init
		ln $base ${drv}`expr $unit + 1` > /dev/null 2>&1
		cd $NETCF/remove
		ln $base ${drv}`expr $unit + 1` > /dev/null 2>&1
	fi
	cd $dir
}

##############################################################################
#
# main()
#
trap "cleanup $FAIL" 1 2 3 15

if [ "$CONFIGURE" = "N" ] ; then
	cleanup $OK
fi

message "\nConfiguring SLIP interface sl$unit\n"
# Is this the first slip line?
n_slips=`netconfig -s | grep "#sl" | wc -l`
if [ $n_slips -eq 0 ] ; then
	# Add drivers via idinstall
	message "Installing the slip driver into the link kit ... \c"
	cd /usr/lib/tcprt/ID/slip
	/etc/conf/bin/idcheck -p slip 
	if [ $? -lt 16 ]
	then
		/etc/conf/bin/idinstall -a -e -k  slip >/dev/null 2>&1
	else
		/etc/conf/bin/idinstall -u -e -k  slip >/dev/null 2>&1
	fi
	echo "done."
	bump		# Add new script
	cleanup $RELINK	# Ensure kernel is relinked by netconfig
else
	bump		# Add new script
	cleanup $OK
fi
