Metropoli BBS
VIEWER: reconf MODE: TEXT (ASCII)
:
#		(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 installing an LLI driver using netconfig
#
# The name it is called with will cause different operation.
# e3A0 e3A1 e3A2 e3A3		== 3Com501 boards 0 - 3
# e3B0 .....	 e3B3		== 3Com503 boards 0 - 3
# e3C0 .....	 e3C3		== 3Com523 boards 0 - 3
# wdn0 .....	 wdn3		== Western Digital boards 0 - 3
# nat0 .....	 nat3		== National NE2000 boards 0 - 3
# wdt0 .....	 wdt3		== Western Digital 8013 boards 0 - 3
# son0 .....	 son3		== Sonic boards 0 - 3
# d65e0.....	 d65e3		== D-Link DE-650 boards 0 - 3
# exos0 ....	 exos3		== Excelan 205T boards 0 - 3
# tok0 tok1			== Token Ring Adapter 0, 1
# hpi0 hpi1 hpi2 hpi3		== HP ThinLAN/EtherTwist ISA LAN Adapters 0 - 3
# hpe0 hpe1 hpe2 hpe3		== HP EtherTwist EISA Slave LAN Adapters 0 - 3
# i3B0 ....	 i3B3		== Interlan ES3210 boards 0 - 3
# i6E0				== Interlan NI6510 board 0
#
LIB=/usr/lib/lli
CONF=/etc/conf
PATH=/bin:/usr/bin:/etc/:$CONF/bin:$LIB
#
# Set possible return codes for this script
#
OK=0;	FAIL=1; RELINK=2;

BRAM="0"
ERAM="0"

#
# Prompt the user for a hex value, it must be within a given range
# Usage:
#	prompt_range "Message" default min max [step]
#
prompt_range() {
	mesg=$1
	default=$2
	range_min=$3 range_max=$4
	step="1"
	if [ $# -eq 5 ]
	then
		step=$5
	fi

	while :
	do
		echo "${mesg} (${range_min}..${range_max}) [${default}] or 'q' to quit: \c"
		read result
		case $result in
		Q|q)
			return $FAIL
			;;
		"")
			result=$default
			;;
		esac

		hc $result $range_min $range_max $step
		case $? in
		0) return $OK;;
		1) cleanup $FAIL;;
		2) cleanup $FAIL;;
		esac
	done
}

#
# Prompt the user to make a selection a list of values
# Usage:
#	prompt_select "Message" default "value_list"
prompt_select() {
	mesg=$1
	default=$2
	values=$3

	while :
	do
		if [ "$default" = "" ]
		then
			echo "${mesg} (${values}) or 'q' to quit: \c"
		else
			echo "${mesg} (${values}) [${default}] or 'q' to quit: \c"
		fi
		read result
		case $result in
		Q|q)
			return $FAIL
			;;
		"")
			result=$default
			;;
		esac

		for i in $values
		do
			if [ "$i" = "$result" ]
			then
				return $OK
			fi
		done
		echo "Illegal value, must be one of (${values})"
	done
}

#
# prompt the user to answer a yes no question or 'q' to quit
# Usage:
#	prompt_yn "Message" default
prompt_yn() {
	mesg=$1
	default=$2

	while :
	do
		echo "${mesg} (y/n) [${default}] or 'q' to quit: \c"
		read result

		case $result in
		q|Q) return $FAIL;;
		y|Y) result="Y"; return $OK;;
		n|N) result="N"; return $OK;;
		"") result=`echo $default | tr "yn" "YN"`; return $OK;;
		esac

		echo "Illegal value, please type 'y' 'n' or 'q'"
	done
}

#
# Fake up an mdevice and an sdevice for idcheck
# Do not remove $base if called with an argument...
#
makedevs() {
	dir=`pwd`
	rm -fr /tmp/dev$$
	mkdir /tmp/dev$$
	cd /etc/conf/cf.d
	cp mdevice /tmp/dev$$
	cd ../sdevice.d
	cat * > /tmp/dev$$/sdevice
	[ $1 ] && {
		# remove driver being reconfigured from sdevice & mdevice files.
		sed -e "/^$base/d" < /tmp/dev$$/sdevice > /tmp/bog$$
		mv /tmp/bog$$ /tmp/dev$$/sdevice
		sed -e "/^$base/d" < /tmp/dev$$/mdevice > /tmp/bog$$
		mv /tmp/bog$$ /tmp/dev$$/mdevice
	}
	cd $dir
}

cleanup() {
	cd /
	rm -fr /tmp/dev$$
	rm -fr /tmp/$base
	exit $1
}

# Removes the given interrupt vector for the $clash device.
rmvector() {
	clash=$1
	vec=$2

	cd $confdir
	echo "\nRemoving interrupt vector $vec for the $clash device ..."

	[ "$vec" = "2" ] && vec=9
	major=`./configure -j $clash` && {
		# remove device but leave it required
		./configure -d -c -m $major -v $vec -Y >> conflog 2>&1 || {
			cd $currdir
			cleanup $FAIL
		}
		# remove required setting if no more left
		if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
		then
			true
		else
			./configure -d -c -m $major -v $vec -R -Y >> conflog 2>&1 || {
				cd $currdir
				cleanup $FAIL
			}
		fi
	}
	cd $currdir
	return $OK
}

# On unix, we must check the files in sdevice.d.
# Sets the variable $clash to the driver code name if there is a driver that
# has already been allocated the given vector. Uses awk.
dointclash() {
	driver=$1
	vec=$2

	[ "$vec" = "2" ] && vec=9
	cd $confdir/../sdevice.d
	clash=`cat * | awk '{ if ( $6 == intr && $2 == "Y" ) exit } \
			END { print $1 }' intr=$vec`

	cd $currdir

	[ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
	# found a clash
	return $OK
}

checkvec() {
	driver=$1
	vector=$2
	clash=

	currdir=`pwd`
	confdir=/etc/conf/cf.d

	while dointclash $driver $vector
	do
		prompt_select "Interrupt vector $vector is already in use for the $clash device.\n\n\
The alternatives available to you are:\n\n\
\t1. Continue the installation and remove vector $vector for the $clash device.\n\
\t2. Select a different interrupt vector.\n\n\
Select an option" 1 "1 2" || {
			cleanup $FAIL
		}
		case $result in
		1)	rmvector $clash $vector || {
				echo "Failed to remove vector $vector"
				cleanup $FAIL
			}
			makedevs
			return $OK
			;;
		2)	return $FAIL
			;;
		esac
	done
	return $OK
}

doaddrclash() {
	driver=$1
	addr1=$2
	addr2=$3

	cd $confdir
	clash=`../bin/idcheck -ar -l $addr1 -u $addr2 -i /tmp/dev$$`
	cd $currdir

	[ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
	# found a clash
	return $OK
}

# Removes the $clash device.
rmaddr() {
	clash=$1

	cd $confdir
	echo "\nRemoving the $clash device ..."

	major=`./configure -j $clash` && {
		# remove device but leave it required
		if [ "$major" != "0" ]
		then
			./configure -d -c -m $major -Y >> conflog 2>&1 || {
				cd $currdir
				cleanup $FAIL
			}
		else
			sed -e "s/Y/N/" ../sdevice.d/$clash > /tmp/bog$$
			mv /tmp/bog$$ ../sdevice.d/$clash
		fi
		# remove required setting if no more left
		if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
		then
			true
		elif [ "$major" != "0" ]
		then
			./configure -d -c -m $major -R -Y >> conflog 2>&1 || {
				cd $currdir
				cleanup $FAIL
			}
		fi
	}
	cd $currdir
	return $OK
}

checkaddr() {
	driver=$1
	addr1=$2
	addr2=$3
	clash=

	currdir=`pwd`
	confdir=/etc/conf/cf.d

	while doaddrclash $driver $addr1 $addr2
	do
		if [ "$clash" = "ad" ]
		then
			echo "\n\nWARNING: Do not remove the $clash device \c"
			echo "if you are using an Adaptec disk controller"
		fi
		prompt_select "Addresses $addr1-$addr2 are already in use by the $clash device.\n\n\
The alternatives available to you are:\n\n\
\t1. Continue the installation and remove the $clash device.\n\
\t2. Select a different address.\n\n\
Select an option" 1 "1 2" || {
			cleanup $FAIL
		}
		case $result in
		1)	rmaddr $clash || {
				echo "Failed to remove $clash device"
				cleanup $FAIL
			}
			makedevs
			return $OK
			;;
		2)	return $FAIL
			;;
		esac
	done
	return $OK
}

doramclash() {
	driver=$1
	addr1=$2
	addr2=$3

	cd $confdir
	clash=`../bin/idcheck -cr -l $addr1 -u $addr2 -i /tmp/dev$$`
	cd $currdir

	[ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
	# found a clash
	return $OK
}

checkram() {
	driver=$1
	addr1=$2
	addr2=$3
	clash=

	currdir=`pwd`
	confdir=/etc/conf/cf.d

	while doramclash $driver $addr1 $addr2
	do
		prompt_yn "
Ram addresses $addr1-$addr2 is already in use for the $clash device.
You must choose a unique address for this device to work.
Do you wish to choose another address now?" y || cleanup $FAIL
		if [ "$result" = "Y" ]
		then
			return $FAIL
		else
			cleanup $FAIL
		fi
	done
	return $OK
}

# On unix, we must check the lines in mdevice file.
# Sets the variable $clash to the driver code name if there is a driver that
# has already been allocated the given channel. Uses awk.
dodmaclash() {
	driver=$1
	chan=$2
	clash=

	# -1 is never a clash
	[ "$chan" = "-1" ] && return $FAIL

	cd $confdir
	clash=`awk '{ if ( $1 != driver && $9 == dma ) print $1 }' dma=$chan driver=$driver mdevice`

	[ "$clash" = "" ] && {
		cd $currdir
		return $FAIL
	}

	cd ../sdevice.d
	cat $clash | awk '{ if ( $2 == "Y" ) exit 1 }' || return $OK

	if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
	then
		prompt_yn "
DMA channel ${chan} is already in use by the $clash device.
However, the $clash device is not currently configured into the kernel.
Do you wish to remove DMA channel ${chan} from the $clash device?" y || cleanup $FAIL
		if [ "$result" = "Y" ]
		then
			sed -e "s/Y/N/" $clash > /tmp/bog$$
			mv /tmp/bog$$ $clash
			cd $currdir
			return $FAIL
		else
			cd $currdir
			return $FAIL
		fi
	fi

	# Should be release >3.2.2, clash driver not installed if we get here.
	cd $currdir
	return $FAIL
}

#
# Check if there is a clash of DMA channels
#
checkdma() {
	driver=$1
	channel=$2
	clash=

	currdir=`pwd`
	confdir=/etc/conf/cf.d

	while dodmaclash $driver $channel
	do
		prompt_yn "
DMA channel ${channel} is already in use by the $clash device.
You must choose a unique channel for this device to work.
Do you wish to choose another channel now?" y || cleanup $FAIL
		if [ "$result" = "Y" ]
		then
			return $FAIL
		else
			cleanup $FAIL
		fi
	done
	return $OK
}

check_args() {
	name=$1
	bd=$2

	case $name in
	e3A) echo "Configuring 3Com501 board $bd";
		PREFIX="e3c";
		MAX_BD=3;
		;;
	e3B) echo "Configuring 3Com503 board $bd";
		PREFIX="e503";
		MAX_BD=3;
		;;
	e3C) echo "Configuring 3Com523 board $bd";
		PREFIX="emc";
		MAX_BD=3;
		;;
	e3D) echo "Configuring 3Com507 board $bd";
		PREFIX="e3d";
		MAX_BD=3;
		;;
	wdn) echo "Configuring Western Digital 8003/8013 board $bd";
		PREFIX="wdn";
		MAX_BD=3;
		;;
	wdt) echo "Configuring WD8013 board $bd";
		PREFIX="wdt";
		MAX_BD=3;
		;;
	nat) echo "Configuring National Semiconductor NE2000 board $bd";
		PREFIX="nat";
		MAX_BD=3;
		;;
       d65e) echo "Configuring D-Link DE-650 board $bd";
		PREFIX="d65e";
		MAX_BD=2;
		;;
	tok) echo "Configuring IBM Token Ring Adapter $bd";
		PREFIX="tok";
		MAX_BD=1;
		;;
	exos) echo "Configuring Excelan 205 Ethernet Adapter $bd";
		PREFIX="exos";
		MAX_BD=3;
		;;
	hpi) echo "Configuring HP ISA LAN adapter $bd";
		PREFIX="hpi";
		MAX_BD=3;
		;;
	hpe) echo "Configuring HP EISA Slave LAN adapter $bd";
		PREFIX="hpe";
		MAX_BD=3;
		;;
	i3B) echo "Configuring Racal InterLan ES 3210 board $bd";
		PREFIX="i3B";
		MAX_BD=3;
		;;
	i6E) echo "Configuring Racal InterLan NL 6510 board $bd";
		PREFIX="i6E";
		MAX_BD=0;
		;;
	*) echo "ERROR: Unknown LLI driver being configured ($name$bd)";
		cleanup $FAIL;
		;;
	esac

	if [ $bd -gt $MAX_BD ]
	then
		echo "ERROR: Only boards 0..$MAX_BD are supported by this driver";
		cleanup $FAIL
	fi
	echo
}

#
# function to produce the info for the System file for the 3C501 & 3C503
# boards
#
system_e3A() {
	bd=$1

	case $bd in
	0) IRQ=3; BIO=300;;
	1) IRQ=2; BIO=310;;
	2) IRQ=5; BIO=330;;
	3) IRQ=7; BIO=350;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "2 3 4 5 6 7" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_range "Enter I/O base address" $BIO "100" "3f0" "10" || cleanup $FAIL
		bio=$result
		EIO=`ha $bio 0f`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	NMINORS="1"

	# up the 2k block buffers, this driver uses more than most drivers.
	awk '/^NBLK2048/ {
		NEW=$2+8
		printf "%s\t%s\n",$1,NEW
		next
	}
	{ print } ' < /etc/conf/cf.d/stune > /tmp/bog$$
	mv /tmp/bog$$ /etc/conf/cf.d/stune
}

#
# function to produce the info for the System file for the 3C501 & 3C503
# boards
#
system_e3B() {
	bd=$1

	case $bd in
	0) IRQ=3; BIO=300;;
	1) IRQ=2; BIO=310;;
	2) IRQ=5; BIO=330;;
	3) IRQ=4; BIO=350;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "2 3 4 5" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_select "Enter I/O base address" $BIO "250 280 2A0 2E0 300 310 330 350" || cleanup $FAIL
		bio=$result
		EIO=`ha $bio 0f`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	NMINORS="1"

	# set the thick/thin thing
	prompt_yn "Does this 503 board use thick (AUI) ethernet?" "n" || cleanup $FAIL
	thick=0
	[ "$result" = "Y" ] && thick=1

	currdir=`pwd`
	cd /etc/conf/pack.d/e3B0
	sed -e "s/fine XCVR$bd.*/fine XCVR$bd   $thick/" < space.c > /tmp/bog$$
	mv /tmp/bog$$ space.c
	cd $currdir
}

#
# function to produce the information for the System file for the 3C523
#
system_e3C() {
	bd=$1

	case $bd in
	0) IRQ=3; BIO=300; BRAM=c0000;;
	1) IRQ=7; BIO=1300; BRAM=c8000;;
	2) IRQ=9; BIO=2300; BRAM=d0000;;
	3) IRQ=12; BIO=3300; BRAM=d8000;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "3 7 9 12" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_range "Enter I/O base address" $BIO "300" "3300" "1000" || cleanup $FAIL
		bio=$result
		EIO=`ha $bio 8`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	while :
	do
		prompt_range "Enter RAM base address" $BRAM "c0000" "d8000" "8000" || cleanup $FAIL
		bram=$result
		ERAM=`ha $bram 5fff`
		checkram $name$bd $bram $ERAM && break
	done
	BRAM=$bram

	NMINORS="1"
}

#
# function to produce the information for the System file for the 3C507
# board
#
system_e3D() {
	bd=$1

	case $bd in
	0) IRQ=3; BIO=300; BRAM=c0000;;
	1) IRQ=9; BIO=310; BRAM=d0000;;
	2) IRQ=5; BIO=320; BRAM=c8000;;
	3) IRQ=7; BIO=330; BRAM=d8000;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "3 5 7 9 10 11 12 15" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_select "Enter I/O base address" $BIO "200 210 220 230 240 250 260 280 290 2a0 2b0 2c0 2d0 2e0 300 310 320 330 340 350 360 380 390 3a0 3e0" || cleanup $FAIL
		bio=$result
		EIO=`ha $bio f`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	while :
	do
		prompt_select "Enter RAM base address" $BRAM "c0000 c8000 d0000 d8000 f00000 f20000 f40000 f60000 f80000" || cleanup $FAIL
		bram=$result

		case $bram in
		c[08]000|d0000) sizelist="16 32 48 64";;
		d8000)		sizelist="16 32";;
		*)		sizelist="64";;
		esac
		prompt_select "Enter RAM Size in k" 64 "$sizelist" || cleanup $FAIL
		case $result in
		16) size=3fff ;;
		32) size=7fff ;;
		48) size=bfff ;;
		64) size=ffff ;;
		esac
		ERAM=`ha $bram $size`
		checkram $name$bd $bram $ERAM && break
	done
	BRAM=$bram

	NMINORS="32"
}

#
# function to produce the information for the space.c file for the token ring
#
space_token() {

	# Set whether Netbeui is above us or not
	nbe=0
	[ "$name_above" = "nbe" ] && nbe=1

	currdir=`pwd`
	cd /etc/conf/pack.d/tok0
	sed -e "s/fine TOK$bd.*/fine TOK$bd     $nbe/" < space.c > /tmp/bog$$
	cp /tmp/bog$$ space.c
	rm -r /tmp/bog$$
	cd $currdir
}

#
# function to restore and remove address conflicts in the sio driver
#
sio_conflict() {
	if [ "$BIO" = "$OBIO" ]
	then
		return $OK
	fi

	currdir=`pwd`
	cd /etc/conf/pack.d/sio
	grep "/* LLI {.*$OBIO" space.c > /dev/null && {
		echo "Restoring serial cards using base address 0x$OBIO into link kit..."
		sed -e /"LLI.*$OBIO,/s/^\/\* LLI //" space.c >/tmp/bog$$
		mv /tmp/bog$$ space.c
	}
	grep "(sd)0x$BIO" space.c > /dev/null && {
		echo "Removing serial cards using base address 0x$BIO from link kit..."
		[ ! -f space.c.rls ] && cp space.c space.c.rls
		sed -e /"(sd)0x$BIO,/s/^{/\/* LLI {/p" space.c >/tmp/bog$$
		mv /tmp/bog$$ space.c
	}
	cd $currdir
}

# restorevector check for sio (vecs 3-4) and pa drivers (vec 7)
# if these are being released by lli then let us restore them to sio or pa
restorevector() {
	currdir=`pwd`
	cd /etc/conf/cf.d

	intvector=$1
	test="0"
	[ "$intvector" = "3" -o "$intvector" = "4" ] && {
		prompt_yn "Restore vector $intvector to sio driver" y
		[ "$result" = "Y" ] && {
			echo "Restoring vector $intvector to sio driver"
			siomajor=`./configure -j sio`
			./configure -m $siomajor -c -v $intvector -a -Y
			return $OK
		}
	}
	[ "$intvector" = "7" ] && {
		prompt_yn "Restore vector $intvector to pa driver" y
		[ "$result" = "Y" ] && {
			echo "Restoring vector $intvector to pa driver"
			pamajor=`./configure -j pa`
			./configure -m $pamajor -c -v $intvector -a -Y
			return $OK
		}
	}
	return $OK
}

#
# determine release, and AT or MCA bus - set rel and type variables accordingly.
#
os_type() {
	rel=`sed -n 's/^#rel=\(.*\).$/\1/p' /etc/perms/rts`
	if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
	then
		type=`sed -n 's/^#typ=\(.*\)$/\1/p' /etc/perms/inst`
	else
		# 3.2.4 - one release supports AT, MCA, and EISA.
		uname -X | grep "BusType = MCA" >/dev/null 2>&1
		if [ $? -eq 0 ]
		then
			type=386MC
		else
			type=386GT
		fi
	fi
}

#
# function to produce the information for the System file for the token ring
#
# BRAM/ERAM indicate ROM address switch settings; BSHRAM/ESHRAM indicate
# shared memory settings.  We assume they're using 16K of SHRAM on the adapter.
#
system_tok() {
	bd=$1

	case $bd in
	0) IRQ=2; BIO=a20; BRAM=cc000; BSHRAM=d8000;;
	1) IRQ=3; BIO=a24; BRAM=dc000; BSHRAM=d4000;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "2 3 6 7" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	EIO=`ha $BIO 3`

	while :
	do
		prompt_range "Enter ROM base address" $BRAM "c0000" "de000" "2000" || cleanup $FAIL
		brom=$result
		ERAM=`ha $brom 1fff`
		checkram $name$bd $brom $ERAM && break
	done
	BRAM=$brom

	# Microchannel tok adapters have a configurable shared RAM address.
	if [ "$type" = "386GT" ]
	then
		ESHRAM=`ha $BSHRAM 3fff`
		doramclash $name$bd $BSHRAM $ESHRAM && {
			echo "The RAM addresses required for $name$bd are in use by the $clash device"
			echo "You must remove $clash before installing $name$bd"
			cleanup $FAIL
		}
	else
		prompt_range "Enter RAM base address" $BSHRAM "c0000" "dc000" "4000" || cleanup $FAIL
		BSHRAM=$result
		ESHRAM=`ha $BSHRAM 3fff`
		doramclash $name$bd $BSHRAM $ESHRAM && {
			echo "The RAM addresses required for $name$bd are in use by the $clash device"
			echo "You must remove $clash before installing $name$bd"
			cleanup $FAIL
		}
	fi

	if [ ! -x /usr/lib/token ]
	then
		mkdir /usr/lib/token
	fi

	prompt_yn "Restrict broadcasts to the local ring" "y" || cleanup $FAIL
	if [ "$result" = "Y" ]
	then
		touch /usr/lib/token/noroute$bd
	else
		rm -f /usr/lib/token/noroute$bd
	fi

	NMINORS="1"

	space_token
}

#
# function to produce the information for the System file for the Excelan
#
system_exos() {
	bd=$1

	case $bd in
	0) IRQ=2; BIO=310; BRAM=d0000;;
	1) IRQ=3; BIO=300; BRAM=d4000;;
	2) IRQ=5; BIO=320; BRAM=d8000;;
	3) IRQ=7; BIO=330; BRAM=dc000;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "2 3 4 5 6 7" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_range "Enter I/O base address" $BIO "300" "330" "10" || cleanup $FAIL
		bio=$result
		EIO=`ha $bio 7`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	while :
	do
		prompt_range "Enter RAM base address" $BRAM "a0000" "f0000" "4000" || cleanup $FAIL
		bram=$result
		ERAM=`ha $bram 3fff`
		checkram $name$bd $bram $ERAM && break
	done
	BRAM=$bram

	NMINORS="32"
}

#
# function to produce the info for the System file for the NE2000
# boards
#
system_nat() {
	bd=$1

	case $bd in
	0) IRQ=3; BIO=300;;
	1) IRQ=2; BIO=320;;
	2) IRQ=5; BIO=340;;
	3) IRQ=4; BIO=360;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "2 3 4 5" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_select "Enter I/O base address" $BIO "300 320 340 360" || cleanup $FAIL
		bio=$result
		EIO=`ha $bio 0f`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	NMINORS="1"

}

#
# function to produce the info for the System file for the SONIC
# boards
#
system_son() {
	bd=$1

	case $bd in
	0) IRQ=9;  BIO=2000;;
	1) IRQ=10; BIO=3000;;
	2) IRQ=11; BIO=4000;;
	3) IRQ=15; BIO=5000;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "9 10 11 15" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_select "Enter I/O base address" $BIO "2000 3000 4000 5000" || cleanup $FAIL
		bio=$result
		EIO=`ha $bio 0f`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	NMINORS="1"

}

#
# function to produce the info for the System file for the DE-650
# boards
#
system_d65e() {
	bd=$1

	case $bd in
	0) IRQ=3; BIO=300; BRAM=d0000; SLOT=0;;
	1) IRQ=4; BIO=320; BRAM=d8000; SLOT=1;;
	2) IRQ=5; BIO=340; BRAM=c0000; SLOT=1;;
	3) IRQ=10; BIO=360; BRAM=c8000; SLOT=1;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "3 4 5 9 10 11 15" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_range "Enter I/O base address" $BIO "300" "360" "20 " || cleanup $FAIL
		bio=$result
		EIO=`ha $bio 1f`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	while :
	do
		prompt_range "Enter RAM base address" $BRAM "c0000" "ec000" "2000" || cleanup $FAIL
		bram=$result
		ERAM=`ha $bram 3fff`
		checkram $name$bd $bram $ERAM && break
	done
	BRAM=$bram

	while :
	do
		prompt_select "Enter PCMCIA Slot Number" $SLOT "0 1" || cleanup $FAIL
		slot=$result

		break
	done
	SLOT=$slot

		case $bd in
		0)
		if grep "#define D65E_0_SLOT" /usr/lib/lli/d65e/Space.c >/dev/null 2>&1
		then
		sed "s/#define D65E_0_SLOT.*/#define D65E_0_SLOT $slot/" /usr/lib/lli/d65e/Space.c >/tmp/bog$$
		cp /tmp/bog$$ /usr/lib/lli/d65e/Space.c
		rm /tmp/bog$$
		else
		echo "#define D65E_0_SLOT $slot\n" >/tmp/bog$$
		cat /usr/lib/lli/d65e/Space.c >>/tmp/bog$$
		cp /tmp/bog$$ /usr/lib/lli/d65e/Space.c
		rm /tmp/bog$$
		fi
		cp /usr/lib/lli/d65e/Space.c /etc/conf/pack.d/d65e0/space.c
		;;
		1)
		if grep "#define D65E1_0_SLOT" /usr/lib/lli/d65e/Space.c >/dev/null 2>&1
		then
		sed "s/#define D65E1_0_SLOT.*/#define D65E1_0_SLOT $slot/" /usr/lib/lli/d65e/Space.c >/tmp/bog$$
		cp /tmp/bog$$ /usr/lib/lli/d65e/Space.c
		rm /tmp/bog$$
		else
		echo "#define D65E1_0_SLOT $slot\n" >/tmp/bog$$
		cat /usr/lib/lli/d65e/Space.c >>/tmp/bog$$
		cp /tmp/bog$$ /usr/lib/lli/d65e/Space.c
		rm /tmp/bog$$
		fi
		cp /usr/lib/lli/d65e/Space.c /etc/conf/pack.d/d65e0/space.c
		;;
		2)
		if grep "#define D65E2_0_SLOT" /usr/lib/lli/d65e/Space.c >/dev/null 2>&1
		then
		sed "s/#define D65E2_0_SLOT.*/#define D65E2_0_SLOT $slot/" /usr/lib/lli/d65e/Space.c >/tmp/bog$$
		cp /tmp/bog$$ /usr/lib/lli/d65e/Space.c
		rm /tmp/bog$$
		else
		echo "#define D65E2_0_SLOT $slot\n" >/tmp/bog$$
		cat /usr/lib/lli/d65e/Space.c >>/tmp/bog$$
		cp /tmp/bog$$ /usr/lib/lli/d65e/Space.c
		rm /tmp/bog$$
		fi
		cp /usr/lib/lli/d65e/Space.c /etc/conf/pack.d/d65e0/space.c
		;;
		3)
		if grep "#define D65E3_SLOT" /usr/lib/lli/d65e/Space.c >/dev/null 2>&1
		then
		sed "s/#define D65E3_0_SLOT.*/#define D65E3_0_SLOT $slot/" /usr/lib/lli/d65e/Space.c >/tmp/bog$$
		cp /tmp/bog$$ /usr/lib/lli/d65e/Space.c
		rm /tmp/bog$$
		else
		echo "#define D65E3_0_SLOT $slot\n" >/tmp/bog$$
		cat /usr/lib/lli/d65e/Space.c >>/tmp/bog$$
		cp /tmp/bog$$ /usr/lib/lli/d65e/Space.c
		rm /tmp/bog$$
		fi
		cp /usr/lib/lli/d65e/Space.c /etc/conf/pack.d/d65e0/space.c
		;;
		esac

	NMINORS="1"

}

#
# function to produce the info for the System file for the WD1013
# boards
#
system_wdt() {
	bd=$1

	case $bd in
	0) IRQ=3; BIO=300; BRAM=c0000;;
	1) IRQ=4; BIO=320; BRAM=c8000;;
	2) IRQ=5; BIO=340; BRAM=d0000;;
	3) IRQ=9; BIO=360; BRAM=d8000;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "3 4 5 7 9 10 11 15" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_range "Enter I/O base address" $BIO "200" "3e0" "20" || cleanup $FAIL
		bio=$result
		EIO=`ha $bio 1f`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	while :
	do
		prompt_range "Enter RAM base address" $BRAM "80000" "f0c000" "2000" || cleanup $FAIL
		bram=$result
		ERAM=`ha $bram 3fff`
		checkram $name$bd $bram $ERAM && break
	done
	BRAM=$bram

	NMINORS="1"

}

#
# function to produce the information for the System file for the western
# digital board
#
system_wdn() {
	bd=$1

	case $bd in
	0) IRQ=3; BIO=240; BRAM=d0000;;
	1) IRQ=2; BIO=380; BRAM=d2000;;
	2) IRQ=5; BIO=260; BRAM=d4000;;
	3) IRQ=7; BIO=340; BRAM=d6000;;
	esac

	if [ "$type" = "386MC" ]
	then
		prompt_yn "\nAre you reconfiguring an Elite series (WD8013EP/A, WD8013WP/A, or\nWD8013EW/A) Western Digital card?" "n" || cleanup $FAIL
		if [ "$result" = "Y" ]
		then
			elite="Y"
			case $bd in
			0) IRQ=3; BIO=800; BRAM=d0000;;
			1) IRQ=4; BIO=1800; BRAM=d2000;;
			2) IRQ=10; BIO=2800; BRAM=d4000;;
			3) IRQ=15; BIO=3800; BRAM=d6000;;
			esac
		fi
	fi

	while :
	do
		if [ "$type" = "386MC" -a "$elite" = "Y" ]
		then
			# WD8013EP/A allows IRQ 14, WD8013WP/A allows IRQ 15
			prompt_select "Enter IRQ" $IRQ "3 4 10 14 15" || cleanup $FAIL
		else
			prompt_select "Enter IRQ" $IRQ "2 3 4 5 7 10 11 15" || cleanup $FAIL
		fi
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		if [ "$type" = "386MC" -a "$elite" = "Y" ]
		then
			prompt_range "Enter I/O base address" $BIO "800" "f800" "1000" || cleanup $FAIL
		else
			prompt_range "Enter I/O base address" $BIO "200" "3e0" "20" || cleanup $FAIL
		fi
		bio=$result
		EIO=`ha $bio 1f`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	while :
	do
		if [ "$type" = "386MC" -a "$elite" = "Y" ]
		then
			prompt_range "Enter RAM base address" $BRAM "c0000" "fde000" "2000" || cleanup $FAIL
		else
			prompt_range "Enter RAM base address" $BRAM "80000" "f0c000" "2000" || cleanup $FAIL
		fi
		bram=$result
		if [ "$type" = "386GT" -o "$elite" = "Y" ]
		then
			prompt_select "Enter RAM Size in k" 8 "8 16" || cleanup $FAIL
			case $result in
				8)  size=1fff ;;
				16) size=3fff ;;
			esac
		else
			size=3fff
		fi
		ERAM=`ha $bram $size`
		checkram $name$bd $bram $ERAM || continue
		hc $bram 100000 f0c000 2000 > /dev/null 2>& 1 && {
			echo "Warning: this address may not be valid if your network adapter"
			echo "is not a Western Digital 16-Bit Elite adapter"
			echo "Shared memory addresses above 1 Meg are supported by 16-bit Elite adapters only."
		}
		break
	done
	BRAM=$bram

	NMINORS="32"

	[ "$rel" = "3.2.1" -o "$rel" = "3.2.0" ] && {
		if [ "$type" = "386GT" ]
		then
			grep "int arch =" /etc/conf/pack.d/wdn0/space.c >/dev/null 2>&1 || {
			echo "int arch = 1;" >> /etc/conf/pack.d/wdn0/space.c
			}
		elif [ "$type" = "386MC" ]
		then
			grep "int arch =" /etc/conf/pack.d/wdn0/space.c >/dev/null 2>&1 || {
			echo "int arch = 2;" >> /etc/conf/pack.d/wdn0/space.c
			}
		fi
	}
}


#
# function to produce info for the System file for HP EISA Slave LAN adapters
#
system_hpe() {
	bd=$1

	case ${bd} in
	0) IRQ=5 ; DMA=3;;
	1) IRQ=7 ; DMA=2;;
	2) IRQ=10; DMA=6;;
	3) IRQ=11; DMA=5;;
	esac

	while :
	do
		prompt_select "Enter DMA channel" $DMA "1 2 3 5 6" || cleanup $FAIL
		dma=$result
		checkdma $name$bd $dma && break
	done
	DMACHAN=$dma

	while :
	do
		prompt_select "Enter IRQ" $IRQ "3 4 5 7 10 11 12" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_select "Enter slot number" "" "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" || cleanup $FAIL
		SLOT=$result
		case $result in
		 0) bio=0C00; EIO=0CFF;;
		 1) bio=1C00; EIO=1CFF;;
		 2) bio=2C00; EIO=2CFF;;
		 3) bio=3C00; EIO=3CFF;;
		 4) bio=4C00; EIO=4CFF;;
		 5) bio=5C00; EIO=5CFF;;
		 6) bio=6C00; EIO=6CFF;;
		 7) bio=7C00; EIO=7CFF;;
		 8) bio=8C00; EIO=8CFF;;
		 9) bio=9C00; EIO=9CFF;;
		10) bio=AC00; EIO=ACFF;;
		11) bio=BC00; EIO=BCFF;;
		12) bio=CC00; EIO=CCFF;;
		13) bio=DC00; EIO=DCFF;;
		14) bio=EC00; EIO=ECFF;;
		15) bio=FC00; EIO=DCFF;;
		*) cleanup $FAIL
		esac
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

BRAM="0"
ERAM="0"
NMINORS="1"
}

#
# function to produce the info for the System file for the HP ISA LAN adapters
#
system_hpi() {
	bd=$1

	case ${bd} in
	0) IRQ=2  ; BIO=300;;
	1) IRQ=3  ; BIO=240;;
	2) IRQ=5  ; BIO=280;;
	3) IRQ=7  ; BIO=2C0;;
	esac

	while :
	do
		echo "IRQs 10 and 11 are only valid for 16-bit adapters."
		prompt_select "Enter IRQ" $IRQ "2 3 4 5 7 10 11" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq
	while :
	do
		prompt_select "Enter I/O base address" $BIO "200 240 280 2C0 300 320 340" || cleanup $FAIL
		bio=$result
		case $result in
		200) EIO=21F ;;
		240) EIO=25F ;;
		280) EIO=29F ;;
		2C0) EIO=2DF ;;
		300) EIO=31F ;;
		320) EIO=33F ;;
		340) EIO=35F ;;
		*) cleanup $FAIL
		esac
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio
	BRAM="0"
	ERAM="0"
	NMINORS="1"
}

#
# Edits the major number into the space.c file for Racal InterLan drivers
#
space_inn() {

	spacef=${CONF:-/etc/conf}/pack.d/${drv}0/space.c
	currdir=`pwd`
	cd $CONF/cf.d
	maj=`./configure -j $base`
	if [ $? -ne 0 -o "$maj" = "" ]
	then
		maj=`./configure -j NEXTMAJOR`
	fi
	cd $currdir

	if [ "$bd" -eq 0 ]
	then
		str="${ucbase}_MAJEDT"
	else
		str="${ucbase}${bd}_MAJEDT"
	fi
	sed "s/$str/$maj/" $spacef >/tmp/bog$$
	cp /tmp/bog$$ $spacef
	rm -f /tmp/bog$$
}

#
# function to produce the information for the System file for the Racal InterLan
# ES-3210 board.
#
system_i3B() {
	ucbase="I3B"
	bd=$1
	spacef=${CONF:-/etc/conf}/pack.d/${drv}0/space.c

	case $bd in
	0) IRQ=9; BIO=1; BRAM=d0000; DMA=NONE;;
	1) IRQ=10; BIO=2; BRAM=d4000; DMA=NONE;;
	2) IRQ=11; BIO=4; BRAM=d8000; DMA=NONE;;
	3) IRQ=12; BIO=5; BRAM=dc000; DMA=NONE;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "3 4 5 6 7 9 10 11 12 14 15" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_range "Enter slot number" $BIO "1" "15" "1" || cleanup $FAIL
		bio=`expr $result * 1000`
		EIO=`ha $bio fff`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	while :
	do
		prompt_range "Enter RAM base address" $BRAM "c0000" "3fffc000" "4000" || cleanup $FAIL
		bram=$result
		ERAM=`ha $bram 3fff`
		checkram $name$bd $bram $ERAM || continue
		break
	done
	BRAM=$bram

	while :
	do
		prompt_select "Enter DMA" $DMA "NONE 0 1 2 3 5 6 7" || cleanup $FAIL
		if [ "$result" = "NONE" ]
		then
			dma=-1
		else
			dma=$result
		fi
		checkdma $name$bd $dma && break
	done
	DMACHAN=$dma
#
# Setup space.c.
# Get the media type (thick or thin) and edit it into space.c
#
	prompt_yn "Does this ES-3210 board use thick (AUI) ethernet?" "n" || cleanup $FAIL
	if [ "$result" = "Y" ]
	then
		netyp="THIK"
	else
		netyp="THIN"
	fi
	if [ $bd -eq 0 ]
	then
		str="THIKTHIN"
	else
		str="THIKTHIN${bd}"
	fi
	a=`grep -n "^#define[   ]${str}[        ]" $spacef`
	b=`expr "$a" : '.*G1_\(....\)'`
	if [ "$b" != "$netyp" ]
	then
		c=`expr "$a" : '\(.*:\)' | sed 's/://'`
		sed "${c}s/G1_$b/G1_$netyp/" $spacef >/tmp/bog$$
		cp /tmp/bog$$ $spacef
		rm /tmp/bog$$
	fi
	space_inn		# Edit major number it into space.c
	NMINORS="1"
}

#
# function to produce the information for the System file for the Racal InterLan
# NI-6510 board.
#
system_i6E() {
	ucbase="I6E"
	bd=$1
	spacef=${CONF:-/etc/conf}/pack.d/${drv}0/space.c
	BRAM=0

	case $bd in
	0) IRQ=9; BIO=360; DMA=3;;
	1) IRQ=12; BIO=340; DMA=5;;
	esac

	while :
	do
		prompt_select "Enter IRQ" $IRQ "5 9 12 15" || cleanup $FAIL
		irq=$result
		checkvec $name$bd $irq && break
	done
	IRQ=$irq

	while :
	do
		prompt_range "Enter I/O base address" $BIO "300" "360" "20" || cleanup $FAIL
		bio=$result
		EIO=`ha $bio f`
		checkaddr $name$bd $bio $EIO && break
	done
	BIO=$bio

	while :
	do
		prompt_select "Enter DMA" $DMA "0 3 5 6" || cleanup $FAIL
		dma=$result
		checkdma $name$bd $dma && break
	done
	DMACHAN=$dma
	space_inn		# Edit major number it into space.c
	NMINORS="1"
}

# main()
#

#
# get the name of the init script being run, since one script
# is used for multiple drivers; get the number at the end of the
# script's name
#
if [ $# -gt 1 ]
then
	name_below=$1; if_below=$2
	name_above=$3; if_above=$4
	configure=$5
fi

base=`basename $0`
drv=`echo $base | sed -e 's/[0-9]*$//`
bd=`expr $base : '.*\(.\)'`

makedevs $OK
check_args $drv $bd

#
# verify the driver is in the kernel link-kit
#
idcheck -p $base -i /tmp/dev$$
if [ $? -le 16 ]
then
	echo "Error: $base driver is not installed"
	cleanup $FAIL
fi

echo "Reconfiguring the $drv driver"
cd /usr/lib/lli/$drv
makedevs

#
# create the temporary directory for installing the driver
#
cd /tmp; rm -rf $base
mkdir $base; cd $base

DMACHAN="-1"

#
# set rel, type variables.
#
os_type

# get the interrupt vector & Base I/O address for the board that we are removing
currdir=`pwd`
cd /etc/conf/sdevice.d
ivec=`awk '{ if ( $1 != "*" ) print $6 }' < $base`
OBIO=`awk '{ if ( $1 != "*" ) print $7 }' < $base`
cd $currdir

#
# Do special board dependent processing
#
system_$drv $bd

echo
if [ "$IRQ" = "2" ]
then
	IRQ=9
fi

echo "$base\tY\t$NMINORS\t5\t1\t$IRQ\t$BIO\t$EIO\t$BRAM\t$ERAM" >./System

#
# All the drivers support more than one board.	In fact all the code to
# support all the boards is in the Driver.o for the board for the 1st board
# (eg the e3A0 driver acually contains enough code for the e3A1, e3A2 & e3A3
# boards).  As we need a Driver.o to be associated with 2nd, 3rd or 4th board
# we install a dummy Driver.o, and a Master and Node which will actually cause
# calls into the base driver.
#
if [ $bd -gt 0 ]
then
	echo "$base     -       iScH    $PREFIX$bd      0       0       1       256     $DMACHAN" >./Master
	echo "clone     $base   c       $base" >./Node

	idinstall -u -m -s -n -e -k $base
else
	echo "$base     I       iScH    $PREFIX 0       0       1       256     $DMACHAN" >./Master
	idinstall -u -m -s -e -k $base
fi

# delete any potential BASE I/O address conflicts with the sio driver
[ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ] && sio_conflict

if [ "$ivec" = "3" -o "$ivec" = "4" -o "$ivec" = "7" ]
then
	[ ${ivec} != ${IRQ} ] && restorevector $ivec
fi

cleanup $RELINK

[ RETURN TO DIRECTORY ]