:
####################################################################
#	@(#)CONFIG	1.8 4/17/95
# 	Copyright (c) Digi, Digi International Inc.
#
#	Installation script for Digi EPCA Async Driver.
#	Copyright (c) 1988-96 Digi International Inc.
#
#	For HP-UX 10.X
#
#	NOTE: It is expected that the Install script will call this	
#	      script.
#				
#	      The Install script is initially invoked by sysadm or
#	      installpkg.
#				
#	      Products supported  - EPC/X, C/X, PC/Xem
#	      Platforms supported - EISA and ISA and PCI
#				
####################################################################
 
#MAXPORT="896"				# Maximum number of ports
#IOLEN="3"
NHOSTS=1                                # Default # of installed boards

#TPO="DigiPrint"				# Transparent print name
#CONCNAME="Concentrator"
#SFX=" a b c d e f g h i j k l m n "	# Available suffix string

NAME="epca"
#BN=`expr "${NAME}" : "\(.*\)."`		# Base name as 'epc'
PLATFORM="EISA"				# Default platform
BRDNAME="Digi System"
REVSTRING=`uname -s -r`
FULLNAME="Digi AccelePort EPC/X, C/X, Xem, Xr and Xr 920"
prod=`uname -r`
major_id=`expr "$prod" : ".*\.\([^\.]*\)\..*"`
minor_id=`expr "$prod" : ".*\.[^\.]*\.\(.*\)"`

#INSTALLDIR=`pwd`			# Capture original directory

##CONFBIN=/etc/conf/bi 
TMPERR=/tmp/config.log
ERROR1="Errors have been written to the file ${TMPERR}."
ERROR2="The $FULLNAME was not installed.
Please call Digi Technical Support if you need additional information."
#NOTOOL="ERROR: Incomplete set of Software Integration Tools.  Can not install
#device driver for ${FULLNAME}."

#
#	yes or no
#
getyn='( while	read yn
	do	case "$yn" in
			[yY])	exit 0
				;;
			[nN])	exit 1
				;;
			*)	echo "	Please answer y or n : \c" >&2
				;;
		esac
	done)'

#
#	get number of ports
#
getnport()
{
	echo "\t\tHow many ports are on module ${m}: (8,16)? \c"

	while :
	do
		read nports
		case "$nports" in
			8|16)
				break
				;;
			*)
				echo "\t\t\tPlease enter 8 or 16: \c"
				;;
		esac
	done

	eval nports${n}${l}c${c}m$m=$nports
}

#
#	get number of EBI modules
#
getebi()
{
	echo "  How many EBI modules are connected to concentrator $c (0 - $mm): \c"
	while :
	do
		read nm
		case "$nm" in
		0)
			eval nmod${n}${l}c${c}=0
			break
			;;
		[1-$mm])
			avail=`expr "$avail" - "$nm"`
			eval nmod${n}${l}c${c}=$nm
			m=1
			while [ "$m" -le "$nm" ]
			do
				getnport
				if [ "$AUTOIDS" = "no" ]
				then
					echo "  Please select an ID letter for module $m: \c"
					readid
				else
					nextid
				fi
				eval id$n${l}c${c}m$m=$id1
				eval idn$n${l}c${c}m$m=$id2
				if [ $id2 -eq 1 ]
				then
					tmpid="$tmpid $id1"
				fi
				m=`expr $m + 1`
			done
			break
			;;
		*)
			echo "    Please enter a number between 0 and $mm: \c"
			continue
			;;
		esac
	done
}

#
#	get number of concentrators
#
getconc()
{
		echo "
How many concentrators are connected to line $l (0 - $mc): \c"
		while :
		do
			read sel
			case "$sel" in
			0)
				eval nconc$n$l="$sel"
				eval baud$n${l}c0=14
				eval nports$n${l}c0=0
				l=`expr $l + 1`
				continue 2
				;;
			[1-$mc])
				avail=`expr "$avail" - "$sel"`
				eval nconc$n$l="$sel"
				break
				;;
			*)
				echo "    Please enter a number between 0 and $mc: \c"
				;;
			esac
		done
}

#
#	Get a concentrator/module ID letter, checking for errors
#
readid()
{
	while :
	do
		read resp
		resp=`echo $resp | tr "[A-Z]" "[a-z]"`
		
		# check if it's valid on this system
		if echo $IDLIST | grep "$resp" >/dev/null
		then
			# check how many times this id has been used
			eval tmp="\$IDCOUNT${resp}"
			if [ -z "$tmp" ]
			then
				tmp=1
			else
				if [ "$tmp" -ge 6 ]
				then
					echo "Sorry, that id has already been used 6 times."
					echo "Please choose a different one."
					echo "Available id's are [$IDLIST2]."
					echo "Please choose one: \c"
					continue;
				fi
				tmp=`expr "$tmp" + 1`
			fi
			eval IDCOUNT${resp}=$tmp
			if [ "$tmp" -ge 6 ]
			then
				# remove SEL from list of available ids
				IDLIST2=`echo $IDLIST|sed "s/$resp *//"`
			fi
			break
		else
			echo "Sorry, that ID is not available on this system."
			echo "Available id's are [$IDLIST2]"
			echo "Please choose one: \c"
			continue
		fi
	done
	id1=$resp
	id2=$tmp
}

#
#	Get next available extend concid from string
#
nextid()
{
	# get the next id from the list
	if [ "$IDLIST1" = " " ]
	then
		# used all ids, start over
		IDLIST1="$IDLIST"
	fi
	id1=`expr "$IDLIST1" : " *\([^ ]*\) "`
	# remove it 
	IDLIST1=`expr "${IDLIST1}" : " *[^ ]*\( .*\)"`

	# count how many times this id has been used
	eval tmp="\$IDCOUNT${id1}"
	if [ -z "$tmp" ]
	then
		tmp=1
	else
		tmp=`expr "$tmp" + 1`
	fi
	eval IDCOUNT${id1}=$tmp
	id2=$tmp
}
#
#	Get next available suffix from string
#
nextsfx()
{
	newsfx=`expr "${SFX}" : " *\([^ ]*\) "`
	SFX=`expr "${SFX}" : " *[^ ]*\( .*\)"`
}

#
#	Configuration for Xr
#
xrconf()
{
	# save state
	tmpid1="$IDLIST1"
	tmpid2="$IDLIST2"
	
	clear
	echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}${altpindisplay}

"
	
	nconc=1
	eval nconc${n}0="1"

	i=1

        nports=8

        eval nports${n}0c${i}=$nports

	if [ "$AUTOIDS" = "no" ]
	then
		echo " Please select an ID letter for adapter $n: \c"
		readid
	else
		nextid
	fi
	eval id${n}0c${i}=$id1
	eval idn${n}0c${i}=$id2
	if [ $id2 -eq 1 ]
	then
		tmpid="$tmpid $id1"
	fi

	iostr=""
	mstr=""
	clear

	echo "You have selected the following configuration for adapter ${n}:
	Adapter Type: ${BNAME}.${iostr}${mstr}  ${altpindisplay}
	Module	Port Names
       --------------------------"
	i=1
	while [ "$i" -le $nconc ]
	do
		eval id=\$id${n}0c${i}
		eval pn=\$idn${n}0c${i}
		eval temp=\$nports${n}0c${i}
		p1=`expr \( "$pn" - 1 \) \* 16 + 1`
		p2=`expr "$p1" + "$temp" - 1`

		# add the leading zero to p1 if necessary
		p1=`expr "00$p1" : ".*\(..\)$"`
		p2=`expr "00$p2" : ".*\(..\)$"`
		string="${Ittyname}${id}${p1} - ${Ittyname}${id}${p2}"
		echo "	  $i	$string"
		i=`expr "$i" + 1`
	done
	echo "
 Is this configuration acceptable (y or n)? \c"
	if eval "$getyn"
	then
		# yes
		return 0
	else
		# no
		# restore state of ID allocation
		IDLIST1="$tmpid1"
		IDLIST2="$tmpid2"
		i=1
		while [ $i -le $nconc ]
		do
			eval id=\$id${n}0c${i}
			eval pn=\$IDCOUNT$id
			pn=`expr "$pn" - 1`
			eval IDCOUNT$id=$pn

			i=`expr $i + 1`
		done
		return 1
	fi
}

#
#	Configuration for PC/Xem
#
emconf()
{
	# save state
	tmpid1="$IDLIST1"
	tmpid2="$IDLIST2"
	
	clear
	echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}${altpindisplay}
 PORTS/16em or PORTS/8em modules:
 This adapter can have 1 or 4 modules connected.

	How many modules are connected to this adapter (1 - 4)? \c"
	
	while :
	do
		read sel
		case "$sel" in
		[1234])
			nconc=$sel
			eval nconc${n}0="${sel}"
			break;
			;;
		*)
			echo "How many modules are connected to this adapter (1 - 4)? \c"
			;;
		esac
	done

	echo
	i=1
	while [ "$i" -le $nconc ]
	do
		echo "		How many ports are on module ${i}: (8,16)? \c"

                read nports
                case "$nports" in
                        8|16)
                        ;;
                *)
                        echo "			Please enter 8 or 16: \c"
                        ;;
                esac

                eval nports${n}0c${i}=$nports

		if [ "$AUTOIDS" = "no" ]
		then
			echo " Please select an ID letter for module $i: \c"
			readid
		else
			nextid
		fi
		eval id${n}0c${i}=$id1
		eval idn${n}0c${i}=$id2
		if [ $id2 -eq 1 ]
		then
			tmpid="$tmpid $id1"
		fi
		i=`expr "$i" + 1`
	done

	iostr=""
	mstr=""
	if [ "$PLATFORM" = "ISA" ] ; then
		iostr="	I/O address:	${porttmp}.
"
	fi
	clear

	echo "You have selected the following configuration for adapter ${n}:
	Adapter Type: ${BNAME}.${iostr}${mstr}  ${altpindisplay}
	Module	Port Names
       --------------------------"
	i=1
	while [ "$i" -le $nconc ]
	do
		eval id=\$id${n}0c${i}
		eval pn=\$idn${n}0c${i}
		eval temp=\$nports${n}0c${i}
		p1=`expr \( "$pn" - 1 \) \* 16 + 1`
		p2=`expr "$p1" + "$temp" - 1`

		# add the leading zero to p1 if necessary
		p1=`expr "00$p1" : ".*\(..\)$"`
		p2=`expr "00$p2" : ".*\(..\)$"`
		string="${Ittyname}${id}${p1} - ${Ittyname}${id}${p2}"
		echo "	  $i	$string"
		i=`expr "$i" + 1`
	done
	echo "
 Is this configuration acceptable (y or n)? \c"
	if eval "$getyn"
	then
		# yes
		return 0
	else
		# no
		# restore state of ID allocation
		IDLIST1="$tmpid1"
		IDLIST2="$tmpid2"
		i=1
		while [ $i -le $nconc ]
		do
			eval id=\$id${n}0c${i}
			eval pn=\$IDCOUNT$id
			pn=`expr "$pn" - 1`
			eval IDCOUNT$id=$pn

			i=`expr $i + 1`
		done
		return 1
	fi
}

#
#	C/X line configuration
#
cxconf()
{
	# save state
	tmpid1="$IDLIST1"
	tmpid2="$IDLIST2"
	
	clear
	echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}${altpindisplay}
Line Configuration:
 The sync lines may be configured two ways.  The basic method has all
 connections wired \"8 wire direct\" at a speed of 1228K bps, and can
 be used for quick set-up for most situations.  The custom method allows
 you to choose speeds and wiring methods individually.

	Do you want to use the basic installation method (y or n)? \c"
	if eval "$getyn"
	then
		# yes - do basic configuration
		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}${altpindisplay}
Basic Configuration:"
		avail=8
		l=1

		while [ $l -le 2 ]
		do
			if [ $avail -le 0 ]
			then
				echo "
	The concentrator limit has been met.  No concentrators may be
	Configured on line $l."
				eval nconc$n$l=0
				eval baud$n${l}c0=14
				eval fbaud$n${l}c0=14
				eval nports$n${l}c0=0
				break
			fi

			echo "
 How many concentrators are connected to line $l (0 - $avail): \c"
			while :
			do
				read sel
				case "$sel" in
				0)
					eval nconc$n$l=0
					eval baud$n${l}c0=14
					eval fbaud$n${l}c0=14
					eval nports$n${l}c0=0
					break;
					;;
				[1-$avail])
					avail=`expr "$avail" - "$sel"`
					eval nconc${n}${l}="$sel"
					eval baud${n}${l}c0=14
					eval fbaud${n}${l}c0=14
					eval nports${n}${l}c0=0
					c=1
					while [ "$c" -le "$sel" ]
					do
						eval baud$n${l}c$c=14
						eval fbaud$n${l}c$c=14
						eval nports$n${l}c$c=16
						if [ "$AUTOIDS" = "no" ]
						then
							echo " Please select an ID letter for concentrator $c: \c"
							readid
						else
							nextid
						fi
						eval id$n${l}c$c=$id1
						eval idn$n${l}c$c=$id2
						if [ $id2 -eq 1 ]
						then
							tmpid="$tmpid $id1"
						fi
						c=`expr $c + 1`
					done
					break;
					;;
				*)
					echo
					echo "   Please enter a number between 0 and $avail: \c"
					continue
					;;
				esac
			done
			l=`expr $l + 1`
		done
	else
		# no - custom configuration
		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}${altpindisplay}
Custom Configuration:"
		avail=8
		l=1
		while [ $l -le 2 ]
		do
			if [ $avail -le 0 ]
			then
				echo "
	The concentrator limit has been met.  No concentrators may be
	Configured on line $l."
				eval nconc$n$l=0
				eval baud$n${l}c0=14
				eval fbaud$n${l}c0=14
				eval nports$n${l}c0=0
				break
			fi

			echo "
Configuring line $l.
 The host adapter supports these cabling options:

	1) 4 wire direct
	2) 8 wire direct (default)
	3) 8 wire synchronous modem
	4) RS-232 synchronous modem

 Please enter the cabling option used on line $l (1-4): \c"
			while :
			do
				read sel
				case "$sel" in
				"")
					option="2"
					break
					;;
				[1-4])
					option="$sel"
					break
					;;
				*)
					echo "   Please enter a number between 1 and 4: \c"
					;;
				esac
			done

			#
			# Direct 4
			#
			if [ "$option" = "1" ]
			then
				echo "
 How many concentrators are connected to line $l (0 - $avail): \c"
				while :
				do
					read sel
					case "$sel" in
					0)
						eval nconc$n$l="$sel"
						eval baud$n${l}c0=14
						eval nports$n${l}c0=0
						l=`expr $l + 1`
						continue 2
						;;
					[1-$avail])
						avail=`expr "$avail" - "$sel"`
						eval nconc$n$l="$sel"
						break
						;;
					*)
						echo "    Please enter a number between 0 and $avail: \c"
						;;
					esac
				done

				echo "
 The baud rates supported for the sync channels, in bits/sec, are:

	1) 230K
	2) 460K

 Please enter selection (1-2): \c"

				while :
				do
					read sel
					case "$sel" in
					[1-2])
						baud="$sel"
						break
						;;
					*)
						echo "    Please enter 1 or 2: \c"
						;;
					esac
				done

				eval nconc=\$nconc$n$l
				eval baud$n${l}c0=$baud
				eval fbaud$n${l}c0=$baud
				eval nports$n${l}c0=0
				c=1
				while [ $c -le $nconc ]
				do
					eval baud$n${l}c$c=$baud
					eval fbaud$n${l}c$c=$baud
					eval nports$n${l}c$c=16
					if [ "$AUTOIDS" = "no" ]
					then
						echo " Please select an ID letter for concentrator $c: \c"
						readid
					else
						nextid
					fi
					eval id$n${l}c$c=$id1
					eval idn$n${l}c$c=$id2
					if [ $id2 -eq 1 ]
					then
						tmpid="$tmpid $id1"
					fi
					c=`expr $c + 1`
				done
			fi
			
			#
			# Direct 8
			#
			if [ "$option" = "2" ]
			then
				echo "
 How many concentrators are connected to line $l (0 - $avail): \c"
				while :
				do
					read sel
					case "$sel" in
					0)
						eval nconc$n$l="$sel"
						eval baud$n${l}c0=14
						eval nports$n${l}c0=0
						l=`expr $l + 1`
						continue 2
						;;
					[1-$avail])
						avail=`expr "$avail" - "$sel"`
						eval nconc$n$l="$sel"
						break
						;;
					*)
						echo "    Please enter a number between 0 and $avail: \c"
						;;
					esac
				done

				echo "
 The baud rates supported for the sync channels, in bits/sec, are:

        1) 2400    5) 38.4K    9) 230K
        2) 4800    6) 57.6K   10) 460K
        3) 9600    7) 76.8K   11) 921K
        4) 19.2K   8) 115K    12) 1228K (default)

 Please enter selection (1-12): \c"

				while :
				do
					read sel
					case "$sel" in
					[1-9]|10|11|12)
						baud=`expr "$sel" + 2`
						break
						;;
					"")
						baud=14
						break
						;;
					*)
						echo "    Please enter a number between 1 and 12: \c"
						;;
					esac
				done

				eval nconc=\$nconc$n$l
				eval baud$n${l}c0=$baud
				eval fbaud$n${l}c0=$baud
				eval nports$n${l}c0=0
				c=1
				while [ $c -le $nconc ]
				do
					eval baud$n${l}c$c=$baud
					eval fbaud$n${l}c$c=$baud
					eval nports$n${l}c$c=16
					if [ "$AUTOIDS" = "no" ]
					then
						echo " Please select an ID letter for concentrator $c: \c"
						readid
					else
						nextid
					fi
					eval id$n${l}c$c=$id1
					eval idn$n${l}c$c=$id2
					if [ $id2 -eq 1 ]
					then
						tmpid="$tmpid $id1"
					fi
					c=`expr $c + 1`
				done
			fi
			
			#
			# Custom 8 (Sync modem)
			#
			if [ "$option" = "3" ]
			then
				echo "
 How many concentrators are connected to line $l (0 - $avail): \c"
				while :
				do
					read sel
					case "$sel" in
					0)
						eval nconc$n$l="$sel"
						eval baud$n${l}c0=14
						eval nports$n${l}c0=0
						l=`expr $l + 1`
						continue 2
						;;
					[1-$avail])
						avail=`expr "$avail" - "$sel"`
						eval nconc$n$l="$sel"
						break
						;;
					*)
						echo "    Please enter a number between 0 and $avail: \c"
						;;
					esac
				done

				echo "
 The baud rates supported for the sync channels, in bits/sec, are:

        1) 2400      6) 38.4K     11) 460K
        2) 4800      7) 57.6K     12) 921K
        3) 9600      8) 76.8K     13) 1228K (default)
        4) 14.4K     9) 115K
        5) 19.2K    10) 230K

 Please enter selection (1-13): \c"

				while :
				do
					read sel
					case "$sel" in
					[1-3])
						baud=`expr "$sel" + 14`
						baud2=`expr "$sel" + 2`
						break
						;;
					4)
						baud=33
						baud2=6
						break
						;;
					[5-9]|1[0123])
						baud=`expr "$sel" + 13`
						baud2=`expr "$sel" + 1`
						break
						;;
					"")
						baud=26
						baud2=14
						break
						;;
					*)
						echo "    Please enter a number between 1 and 13: \c"
						;;
					esac
				done

				eval baud$n${l}c0=$baud
				eval fbaud$n${l}c0=$baud

				eval nports$n${l}c0=0
				
				eval nconc=\$nconc$n$l
				c=1
				while [ $c -lt $nconc ]
				do
					eval nports$n${l}c$c=16

					if [ "$baud2" -lt 10 ]
					then
						eval baud$n${l}c$c=10
					else
						eval baud$n${l}c$c=$baud2
					fi
					eval fbaud$n${l}c$c=$baud2

					c=`expr $c + 1`
				done
				eval nports$n${l}c$c=16
				eval baud$n${l}c$c=$baud
				eval fbaud$n${l}c$c=$baud

				echo
				c=1
				while [ $c -le $nconc ]
				do
					if [ "$AUTOIDS" = "no" ]
					then
						echo " Please select an ID letter for concentrator $c: \c"
						readid
					else
						nextid
					fi
					eval id$n${l}c$c=$id1
					eval idn$n${l}c$c=$id2
					if [ $id2 -eq 1 ]
					then
						tmpid="$tmpid $id1"
					fi
					c=`expr $c + 1`
				done
			fi

			#
			# RS-232 modem
			#
			if [ "$option" = 4 ]
			then
				echo "
 How many concentrators are connected to line $l (0 - $avail): \c"
				while :
				do
					read sel
					case "$sel" in
					0)
						eval nconc$n$l="$sel"
						eval baud$n${l}c0=14
						eval nports$n${l}c0=0
						l=`expr $l + 1`
						continue 2
						;;
					[1-$avail])
						avail=`expr "$avail" - "$sel"`
						eval nconc$n$l="$sel"
						break
						;;
					*)
						echo "    Please enter a number between 0 and $avail: \c"
						;;
					esac
				done

				echo "
 The baud rates supported for the sync channels, in bits/sec, are:

	1) 2400      4) 14.4K      7) 57.6K
	2) 4800      5) 19.2K      8) 64.1K
	3) 9600      6) 38.4K      9) 76.8K

	
 Please enter selection (1-13): \c"

				while :
				do
					read sel
					case "$sel" in
					[1-3])
						baud=`expr "$sel" + 34`
						baud2=`expr "$sel" + 2`
						break
						;;
					4)
						baud=38
						baud2=6
						break
						;;
					[5-7])
						baud=`expr "$sel" + 34`
						baud2=`expr "$sel" + 1`
						break
						;;
					8)
						baud=42
						baud2=9
						break
						;;
					9)
						baud=43
						baud2=9
						break
						;;
					*)
						echo "    Please enter a number between 1 and 9: \c"
						;;
					esac
				done

				eval baud$n${l}c0=$baud
				eval fbaud$n${l}c0=$baud

				eval nports$n${l}c0=0
				
				eval nconc=\$nconc$n$l
				c=1
				while [ $c -lt $nconc ]
				do
					eval nports$n${l}c$c=16

					if [ "$baud2" -lt 10 ]
					then
						eval baud$n${l}c$c=10
					else
						eval baud$n${l}c$c=$baud2
					fi
					eval fbaud$n${l}c$c=$baud2

					c=`expr $c + 1`
				done
				eval nports$n${l}c$c=16
				eval baud$n${l}c$c=$baud
				eval fbaud$n${l}c$c=$baud

				echo
				c=1
				while [ $c -le $nconc ]
				do
					if [ "$AUTOIDS" = "no" ]
					then
						echo " Please select an ID letter for concentrator $c: \c"
						readid
					else
						nextid
					fi
					eval id$n${l}c$c=$id1
					eval idn$n${l}c$c=$id2
					if [ $id2 -eq 1 ]
					then
						tmpid="$tmpid $id1"
					fi
					c=`expr $c + 1`
				done
			fi
			l=`expr $l + 1`
		done
	fi

	clear

	iostr=""
	mstr=""
	if [ "$PLATFORM" = "ISA" ] ; then
		iostr="   I/O Address: ${porttmp}."
	fi
	echo "You have selected the following configuration for adapter ${n}:
  ${BNAME}.${iostr}${mstr}  ${altpindisplay}
	Connections	Speed	Cabling		Port Names
      --------------------------------------------------------"

	l=1
	while [ $l -le 2 ]
	do
		echo "\t  Line $l"
		eval nconc=\$nconc$n$l
		c=0
		while [ $c -lt $nconc ]
		do
			conc=`expr $c + 1`
			echo "      Concentrator $conc\t\c"

			eval baud=\$fbaud$n${l}c$c

			eval id=\$id$n${l}c$conc
			eval pn=\$idn$n${l}c$conc
			p1=`expr \( "$pn" - 1 \) \* 16 + 1`
			p2=`expr "$p1" + 15`
			# add the leading zero to p1 if necessary
			p1=`expr "00$p1" : ".*\(..\)$"`
			pnames="${Ittyname}${id}${p1} - ${Ittyname}${id}${p2}"
			
                        case ${baud} in
                        1)      echo "230K \t4 wire direct\t$pnames"
                                ;;
                        2)      echo "460K \t4 wire direct\t$pnames"
                                ;;
                        3)      echo "2400 \t8 wire direct\t$pnames"
                                ;;
                        4)      echo "4800 \t8 wire direct\t$pnames"
                                ;;
                        5)      echo "9600 \t8 wire direct\t$pnames"
                                ;;
                        6)      echo "19.2K\t8 wire direct\t$pnames"
                                ;;
                        7)      echo "38.4K\t8 wire direct\t$pnames"
                                ;;
                        8)      echo "57.6K\t8 wire direct\t$pnames"
                                ;;
                        9)      echo "76.8K\t8 wire direct\t$pnames"
                                ;;
                        10)     echo "115K \t8 wire direct\t$pnames"
                                ;;
                        11)     echo "230K \t8 wire direct\t$pnames"
                                ;;
                        12)     echo "460K \t8 wire direct\t$pnames"
                                ;;
                        13)     echo "921K \t8 wire direct\t$pnames"
                                ;;
                        14)     echo "1228K\t8 wire direct\t$pnames"
                                ;;
                        15)     echo "2400 \t8 wire modem \t$pnames"
                                ;;
                        16)     echo "4800 \t8 wire modem \t$pnames"
                                ;;
                        17)     echo "9600 \t8 wire modem \t$pnames"
                                ;;
                        18)     echo "19.2K\t8 wire modem \t$pnames"
                                ;;
                        19)     echo "38.4K\t8 wire modem \t$pnames"
                                ;;
                        20)     echo "57.6K\t8 wire modem \t$pnames"
                                ;;
                        21)     echo "76.8K\t8 wire modem \t$pnames"
                                ;;
                        22)     echo "115K \t8 wire modem \t$pnames"
                                ;;
                        23)     echo "230K \t8 wire modem \t$pnames"
                                ;;
                        24)     echo "460K \t8 wire modem \t$pnames"
                                ;;
                        25)     echo "921K \t8 wire modem \t$pnames"
                                ;;
                        26)     echo "1228K\t8 wire modem \t$pnames"
                                ;;
			33)	echo "14.4K\t8 wire modem \t$pnames"
				;;
			35)	echo "2400 \tRS-232 modem \t$pnames"
				;;
			36)	echo "4800 \tRS-232 modem \t$pnames"
				;;
			37)	echo "9600 \tRS-232 modem \t$pnames"
				;;
			38)	echo "14.4K\tRS-232 modem \t$pnames"
				;;
			39)	echo "19.2K\tRS-232 modem \t$pnames"
				;;
			40)	echo "38.4K\tRS-232 modem \t$pnames"
				;;
			41)	echo "57.6K\tRS-232 modem \t$pnames"
				;;
			42)	echo "64.1K\tRS-232 modem \t$pnames"
				;;
			43)	echo "76.8K\tRS-232 modem \t$pnames"
				;;
                        *)      echo "     case got $1           "
                                ;;
			esac

			c=`expr $c + 1`
		done

		l=`expr $l + 1`
	done

	echo "\n  Is this configuration acceptable (y or n)? \c"
	if eval "$getyn"
	then
		# yes
		return 0
	else
		# no
		# restore state if ID allocation
		IDLIST1="$tmpid1"
		IDLIST2="$tmpid2"
		l=1
		while [ $l -le 2 ]
		do
			eval nconc=\$nconc$n$l
			c=1
			while [ $c -le $nconc ]
			do
				eval id=\$id$n${l}c$c
				eval pn=\$IDCOUNT$id
				pn=`expr "$pn" - 1`
				eval IDCOUNT$id=$pn

				c=`expr $c + 1`
			done
			l=`expr $l + 1`
		done
		return 1
	fi

}	# end of cxconf

#
#	epc line configuration
#
epcconf()
{
	# save state
	tmpid1="$IDLIST1"
	tmpid2="$IDLIST2"
	
	clear
	echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}${altpindisplay}
Line Configuration:
 The sync lines may be configured two ways.  The basic method has all
 connections wired \"8 wire direct\" at a speed of either 1228K bps or
 10M bps, and can be used for quick set-up for most situations.  The
 custom method allows you to choose speeds and wiring methods
 individually.

	Do you want to use the basic installation method (y or n)? \c"
	if eval "$getyn"
	then
		# yes - do basic configuration
		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}${altpindisplay}
Basic Configuration:

 One of two line speeds must be chosen for the basic configuration
 method.  The choices are 1228K bps and 10M bps.  Running the sync
 lines at 1228K bps maintains compatibility with C/CON-16
 concentrators.  Running the sync lines at 10M bps allows higher
 performance, but is not compatible with C-CON/16 concentrators and
 restricts the length of the sync cable.  For more information, see
 the manual.

	1) 1228K bps
	2) 10M bps

 Which speed do you wish to run the sync lines at? \c"
		while :
		do
			read ans
			case $ans in
				1)
					syncbaud=14
					break
					;;
				2)
					syncbaud=74
					break
					;;
			esac
			echo "	Please choose 1 or 2.
 Which speed do you wish to run the sync lines at? \c"
		done

		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}${altpindisplay}
Basic Configuration:"

		avail=14
		l=1

		while [ $l -le 2 ]
		do
			if [ $avail -le 0 ]
			then
				echo "
	The concentrator limit has been met.  No concentrators may be
	Configured on line $l."
				eval nconc$n$l=0
				eval baud$n${l}c0=$syncbaud
				eval fbaud$n${l}c0=$syncbaud
				eval nports$n${l}c0=0
				break
			fi

			if [ $avail -lt 8 ]
			then
				mc=$avail
			else
				mc=8
			fi

			echo "
 How many concentrators are connected to line $l (0 - $mc): \c"
			while :
			do
				read sel
				case "$sel" in
				0)
					eval nconc$n$l=0
					eval baud$n${l}c0=$syncbaud
					eval fbaud$n${l}c0=$syncbaud
					eval nports$n${l}c0=0
					break
					;;
				[1-$mc])
					avail=`expr "$avail" - "$sel"`
					eval nconc${n}${l}="$sel"
					eval baud${n}${l}c0=$syncbaud
					eval fbaud${n}${l}c0=$syncbaud
					eval nports${n}${l}c0=0
					c=1
					while [ "$c" -le "$sel" ]
					do
						eval baud$n${l}c$c=$syncbaud
						eval fbaud$n${l}c$c=$syncbaud
						eval nports$n${l}c$c=16
						if [ "$AUTOIDS" = "no" ]
						then
							echo " Please select an ID letter for concentrator $c: \c"
							readid
						else
							nextid
						fi
						eval id$n${l}c$c=$id1
						eval idn$n${l}c$c=$id2
						if [ $id2 -eq 1 ]
						then
							tmpid="$tmpid $id1"
						fi
						if [ $avail -lt 3 ] ; then
							mm=$avail
						else
							mm=3
						fi
						if [ "$mm" -gt 0 ] ; then
							getebi
						fi
						c=`expr $c + 1`
					done
					break;
					;;
				*)
					echo
					echo "   Please enter a number between 0 and $mc: \c"
					continue
					;;
				esac
			done
			l=`expr $l + 1`
		done
	else
		# no - custom configuration
		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}${altpindisplay}
Custom Configuration:"
		avail=14
		l=1
		while [ $l -le 2 ]
		do
			if [ $avail -le 0 ]
			then
				echo "
	The concentrator limit has been met.  No concentrators may be
	Configured on line $l."
				eval nconc$n$l=0
				eval baud$n${l}c0=14
				eval fbaud$n${l}c0=14
				eval nports$n${l}c0=0
				break
			fi

			if [ $avail -lt 8 ]
			then
				mc=$avail
			else
				mc=8
			fi

			echo "
Configuring line $l.
 The host adapter supports these cabling options:

	1) 4 wire direct
	2) 8 wire direct (default)
	3) 8 wire synchronous modem
	4) RS-232 synchronous modem

 Please enter the cabling option used on line $l (1-4): \c"
			while :
			do
				read sel
				case "$sel" in
				"")
					option=2
					break
					;;
				[1-4])
					option="$sel"
					break
					;;
				*)
					echo "   Please enter a number between 1 and 4: \c"
					;;
				esac
			done

			#
			# Direct 4
			#
			if [ "$option" = 1 ]
			then
				echo "
 How many concentrators are connected to line $l (0 - $mc): \c"
				while :
				do
					read sel
					case "$sel" in
					0)
						eval nconc$n$l="$sel"
						eval baud$n${l}c0=14
						eval nports$n${l}c0=0
						l=`expr $l + 1`
						continue 2
						;;
					[1-$mc])
						avail=`expr "$avail" - "$sel"`
						eval nconc$n$l="$sel"
						break
						;;
					*)
						echo "    Please enter a number between 0 and $mc: \c"
						;;
					esac
				done

				echo "
 The baud rates supported for the sync channels, in bits/sec, are:

	1) 230K
	2) 460K
	3) 921K*			* These rates are not compatible
	4) 1843K*			  with C/CON-16 concentrators.


 Please enter selection (1-4): \c"

				while :
				do
					read sel
					case "$sel" in
					[1-2])
						baud="$sel"
						break
						;;
					3)
						baud=67
						break
						;;
					4)
						baud=69
						break
						;;
					*)
						echo "    Please enter 1 - 4: \c"
						;;
					esac
				done

				eval nconc=\$nconc$n$l
				eval baud$n${l}c0=$baud
				eval fbaud$n${l}c0=$baud
				eval nports$n${l}c0=0
				c=1
				while [ $c -le $nconc ]
				do
					eval baud$n${l}c$c=$baud
					eval fbaud$n${l}c$c=$baud
					eval nports$n${l}c$c=16
					if [ "$AUTOIDS" = "no" ]
					then
						echo " Please select an ID letter for concentrator $c: \c"
						readid
					else
						nextid
					fi
					eval id$n${l}c$c=$id1
					eval idn$n${l}c$c=$id2
					if [ $id2 -eq 1 ]
					then
						tmpid="$tmpid $id1"
					fi
					if [ $avail -lt 3 ] ; then
						mm=$avail
					else
						mm=3
					fi
					if [ "$mm" -gt 0 ] ; then
						getebi
					fi
					c=`expr $c + 1`
				done
			fi
			
			#
			# Direct 8
			#
			if [ "$option" = 2 ]
			then
				echo "
 How many concentrators are connected to line $l (0 - $mc): \c"
				while :
				do
					read sel
					case "$sel" in
					0)
						eval nconc$n$l="$sel"
						eval baud$n${l}c0=14
						eval nports$n${l}c0=0
						l=`expr $l + 1`
						continue 2
						;;
					[1-$mc])
						avail=`expr "$avail" - "$sel"`
						eval nconc$n$l="$sel"
						break
						;;
					*)
						echo "    Please enter a number between 0 and $mc: \c"
						;;
					esac
				done

				echo "
 The baud rates supported for the sync channels, in bits/sec, are:

        1) 2400    5) 38.4K    9) 230K             13) 1843k*  17) 10M*
        2) 4800    6) 57.6K   10) 460K             14) 2458k*
        3) 9600    7) 76.8K   11) 921K             15) 3686k*
        4) 19.2K   8) 115K    12) 1228K (default)  16) 7373k*

    * Rates with an asterisk are incompatible with C/CON-16 concentrators.

 Please enter selection (1-17): \c"

				while :
				do
					read sel
					case "$sel" in
					[1-9]|10|11|12)
						baud=`expr "$sel" + 2`
						break
						;;
					1[3-7])
						baud=`expr "$sel" + 57`
						break
						;;
					"")
						baud=14
						break
						;;
					*)
						echo "    Please enter a number between 1 and 17: \c"
						;;
					esac
				done

				eval nconc=\$nconc$n$l
				eval baud$n${l}c0=$baud
				eval fbaud$n${l}c0=$baud
				eval nports$n${l}c0=0
				c=1
				while [ $c -le $nconc ]
				do
					eval baud$n${l}c$c=$baud
					eval fbaud$n${l}c$c=$baud
					eval nports$n${l}c$c=16
					if [ "$AUTOIDS" = "no" ]
					then
						echo " Please select an ID letter for concentrator $c: \c"
						readid
					else
						nextid
					fi
					eval id$n${l}c$c=$id1
					eval idn$n${l}c$c=$id2
					if [ $id2 -eq 1 ]
					then
						tmpid="$tmpid $id1"
					fi
					if [ $avail -lt 3 ] ; then
						mm=$avail
					else
						mm=3
					fi
					if [ "$mm" -gt 0 ] ; then
						getebi
					fi
					c=`expr $c + 1`
				done
			fi
			
			#
			# Custom 8 (Sync modem)
			#
			if [ "$option" = 3 ]
			then
				echo "
 How many concentrators are connected to line $l (0 - $mc): \c"
				while :
				do
					read sel
					case "$sel" in
					0)
						eval nconc$n$l="$sel"
						eval baud$n${l}c0=14
						eval nports$n${l}c0=0
						l=`expr $l + 1`
						continue 2
						;;
					[1-$mc])
						avail=`expr "$avail" - "$sel"`
						eval nconc$n$l="$sel"
						break
						;;
					*)
						echo "    Please enter a number between 0 and $mc: \c"
						;;
					esac
				done

				echo "
 The baud rates supported for the sync channels, in bits/sec, are:

        1) 2400      6) 38.4K     11) 460K
        2) 4800      7) 57.6K     12) 921K
        3) 9600      8) 76.8K     13) 1228K (default)
        4) 14.4K     9) 115K
        5) 19.2K    10) 230K

 Please enter selection (1-13): \c"

				while :
				do
					read sel
					case "$sel" in
					[1-3])
						baud=`expr "$sel" + 14`
						baud2=`expr "$sel" + 2`
						break
						;;
					4)
						baud=33
						baud2=6
						break
						;;
					[5-9]|1[0123])
						baud=`expr "$sel" + 13`
						baud2=`expr "$sel" + 1`
						break
						;;
					"")
						baud=26
						baud2=14
						break
						;;
					*)
						echo "    Please enter a number between 1 and 13: \c"
						;;
					esac
				done

				eval baud$n${l}c0=$baud
				eval fbaud$n${l}c0=$baud
				eval nports$n${l}c0=0
				eval nconc=\$nconc$n$l
				c=1
				while [ $c -lt $nconc ]
				do
					eval nports$n${l}c$c=16
					if [ "$baud2" -lt 10 ]
					then
						eval baud$n${l}c$c=10
					else
						eval baud$n${l}c$c=$baud2
					fi
					eval fbaud$n${l}c$c=$baud2
					c=`expr $c + 1`
				done
				eval nports$n${l}c$c=16
				eval baud$n${l}c$c=$baud
				eval fbaud$n${l}c$c=$baud

				echo
				c=1
				while [ $c -le $nconc ]
				do
					if [ "$AUTOIDS" = "no" ]
					then
						echo " Please select an ID letter for concentrator $c: \c"
						readid
					else
						nextid
					fi
					eval id$n${l}c$c=$id1
					eval idn$n${l}c$c=$id2
					if [ $id2 -eq 1 ]
					then
						tmpid="$tmpid $id1"
					fi
					if [ $avail -lt 3 ] ; then
						mm=$avail
					else
						mm=3
					fi
					if [ "$mm" -gt 0 ] ; then
						getebi
					fi
					c=`expr $c + 1`
				done
			fi

			#
			# RS-232 modem
			#
			if [ "$option" = 4 ]
			then
				echo "
 How many concentrators are connected to line $l (0 - $mc): \c"
				while :
				do
					read sel
					case "$sel" in
					0)
						eval nconc$n$l="$sel"
						eval baud$n${l}c0=14
						eval nports$n${l}c0=0
						l=`expr $l + 1`
						continue 2
						;;
					[1-$mc])
						avail=`expr "$avail" - "$sel"`
						eval nconc$n$l="$sel"
						break
						;;
					*)
						echo "    Please enter a number between 0 and $mc: \c"
						;;
					esac
				done

				echo "
 The baud rates supported for the sync channels, in bits/sec, are:

	1) 2400      4) 14.4K      7) 57.6K
	2) 4800      5) 19.2K      8) 64.1K
	3) 9600      6) 38.4K      9) 76.8K
	
 Please enter selection (1-13): \c"

				while :
				do
					read sel
					case "$sel" in
					[1-3])
						baud=`expr "$sel" + 34`
						baud2=`expr "$sel" + 2`
						break
						;;
					4)
						baud=38
						baud2=6
						break
						;;
					[5-7])
						baud=`expr "$sel" + 34`
						baud2=`expr "$sel" + 1`
						break
						;;
					8)
						baud=42
						baud2=9
						break
						;;
					9)
						baud=43
						baud2=9
						break
						;;
					*)
						echo "    Please enter a number between 1 and 9: \c"
						;;
					esac
				done

				eval baud$n${l}c0=$baud
				eval fbaud$n${l}c0=$baud
				eval nports$n${l}c0=0
				eval nconc=\$nconc$n$l
				c=1
				while [ $c -lt $nconc ]
				do
					eval nports$n${l}c$c=16
					if [ "$baud2" -lt 10 ]
					then
						eval baud$n${l}c$c=10
					else
						eval baud$n${l}c$c=$baud2
					fi
					eval fbaud$n${l}c$c=$baud2
					c=`expr $c + 1`
				done
				eval nports$n${l}c$c=16
				eval baud$n${l}c$c=$baud
				eval fbaud$n${l}c$c=$baud

				echo
				c=1
				while [ $c -le $nconc ]
				do
					if [ "$AUTOIDS" = "no" ]
					then
						echo " Please select an ID letter for concentrator $c: \c"
						readid
					else
						nextid
					fi
					eval id$n${l}c$c=$id1
					eval idn$n${l}c$c=$id2
					if [ $id2 -eq 1 ]
					then
						tmpid="$tmpid $id1"
					fi
					if [ $avail -lt 3 ] ; then
						mm=$avail
					else
						mm=3
					fi
					if [ "$mm" -gt 0 ] ; then
						getebi
					fi
					c=`expr $c + 1`
				done
			fi
			l=`expr $l + 1`
		done
	fi

	clear

	iostr=""
	mstr=""
	if [ "$PLATFORM" = "ISA" ] ; then
		iostr="   I/O Address: ${porttmp}."
	fi
	echo "You have selected the following configuration for adapter ${n}:
  ${BNAME}.${iostr}${mstr}  ${altpindisplay}
	Connections	Speed	Cabling		Port Names
      --------------------------------------------------------"

	l=1
	while [ $l -le 2 ]
	do
		echo "\t  Line $l"
		eval nconc=\$nconc$n$l
		c=0
		while [ $c -lt $nconc ]
		do
			conc=`expr $c + 1`
			echo "      Concentrator $conc\t\c"

			eval baud=\$fbaud$n${l}c$c

			eval id=\$id$n${l}c$conc
			eval pn=\$idn$n${l}c$conc
			p1=`expr \( "$pn" - 1 \) \* 16 + 1`
			p2=`expr "$p1" + 15`
			# add the leading zero to p1 if necessary
			p1=`expr "00$p1" : ".*\(..\)$"`
			pnames="${Ittyname}${id}${p1} - ${Ittyname}${id}${p2}"

                        case ${baud} in
			1)	echo "230K \t4 wire direct\t$pnames"
				;;
			2)	echo "460K \t4 wire direct\t$pnames"
				;;
			3)	echo "2400 \t8 wire direct\t$pnames"
				;;
			4)	echo "4800 \t8 wire direct\t$pnames"
				;;
			5)	echo "9600 \t8 wire direct\t$pnames"
				;;
			6)	echo "19.2K\t8 wire direct\t$pnames"
				;;
			7)	echo "38.4K\t8 wire direct\t$pnames"
				;;
			8)	echo "57.6K\t8 wire direct\t$pnames"
				;;
			9)	echo "76.8K\t8 wire direct\t$pnames"
				;;
			10)	echo "115K \t8 wire direct\t$pnames"
				;;
			11)	echo "230K \t8 wire direct\t$pnames"
				;;
			12)	echo "460K \t8 wire direct\t$pnames"
				;;
			13)	echo "921K \t8 wire direct\t$pnames"
				;;
			14)	echo "1228K\t8 wire direct\t$pnames"
				;;
			15)	echo "2400 \t8 wire modem \t$pnames"
				;;
			16)	echo "4800 \t8 wire modem \t$pnames"
				;;
			17)	echo "9600 \t8 wire modem \t$pnames"
				;;
			18)	echo "19.2K\t8 wire modem \t$pnames"
				;;
			19)	echo "38.4K\t8 wire modem \t$pnames"
				;;
			20)	echo "57.6K\t8 wire modem \t$pnames"
				;;
			21)	echo "76.8K\t8 wire modem \t$pnames"
				;;
			22)	echo "115K \t8 wire modem \t$pnames"
				;;
			23)	echo "230K \t8 wire modem \t$pnames"
				;;
			24)	echo "460K \t8 wire modem \t$pnames"
				;;
			25)	echo "921K \t8 wire modem \t$pnames"
				;;
			26)	echo "1228K\t8 wire modem \t$pnames"
				;;
			33)	echo "14.4K\t8 wire modem \t$pnames"
				;;
			35)	echo "2400 \tRS-232 modem \t$pnames"
				;;
			36)	echo "4800 \tRS-232 modem \t$pnames"
				;;
			37)	echo "9600 \tRS-232 modem \t$pnames"
				;;
			38)	echo "14.4K\tRS-232 modem \t$pnames"
				;;
			39)	echo "19.2K\tRS-232 modem \t$pnames"
				;;
			40)	echo "38.4K\tRS-232 modem \t$pnames"
				;;
			41)	echo "57.6K\tRS-232 modem \t$pnames"
				;;
			42)	echo "64.1K\tRS-232 modem \t$pnames"
				;;
			43)	echo "76.8K\tRS-232 modem \t$pnames"
				;;
			60)	echo "115K \t4 wire direct\t$pnames"
				;;
			61)	echo "115K \t4 wire direct\t$pnames"
				;;
			62)	echo "230K \t4 wire direct\t$pnames"
				;;
			63)	echo "230K \t4 wire direct\t$pnames"
				;;
			64)	echo "460K \t4 wire direct\t$pnames"
				;;
			65)	echo "460K \t4 wire direct\t$pnames"
				;;
			66)	echo "921K \t4 wire direct\t$pnames"
				;;
			67)	echo "921K \t4 wire direct\t$pnames"
				;;
			68)	echo "1843K\t4 wire direct\t$pnames"
				;;
			69)	echo "1843K\t4 wire direct\t$pnames"
				;;
			70)	echo "1843K\t8 wire direct\t$pnames"
				;;
			71)	echo "2458K\t8 wire direct\t$pnames"
				;;
			72)	echo "3686K\t8 wire direct\t$pnames"
				;;
			73)	echo "7373K\t8 wire direct\t$pnames"
				;;
			74)	echo "10M  \t8 wire direct\t$pnames"
				;;
                        *)      echo "     case got $1           "
                                ;;
			esac

			eval nm=\$nmod${n}${l}c${conc}
			if [ "$nm" != 0 ]
			then
				m=1
				while [ "$m" -le "$nm" ]
				do
					eval id=\$id$n${l}c${conc}m$m
					eval pn=\$idn$n${l}c${conc}m$m
					p1=`expr \( "$pn" - 1 \) \* 16 + 1`
					eval temp=\$nports${n}${l}c${conc}m$m
					p2=`expr "$p1" + "$temp" - 1`
					# add the leading zero to p1 and p2 if necessary
					p1=`expr "00$p1" : ".*\(..\)$"`
					p2=`expr "00$p2" : ".*\(..\)$"`
					pnames="${Ittyname}${id}${p1} - ${Ittyname}${id}${p2}"
					echo "           EBI Module $m\t\c"
					echo "     \t             \t$pnames"
					m=`expr $m + 1`
				done
			fi

			c=`expr $c + 1`
		done

		l=`expr $l + 1`
	done

	echo "\n  Is this configuration acceptable (y or n)? \c"
	if eval "$getyn"
	then
		# yes
		return 0
	else
		# no
		# restore state if ID allocation
		IDLIST1="$tmpid1"
		IDLIST2="$tmpid2"
		l=1
		while [ $l -le 2 ]
		do
			eval nconc=\$nconc$n$l
			c=1
			while [ $c -le $nconc ]
			do
				eval id=\$id$n${l}c$c
				eval pn=\$IDCOUNT$id
				pn=`expr "$pn" - 1`
				eval IDCOUNT$id=$pn

				eval nm=\$nmod${n}${l}c${c}
				m=1
				while [ "$m" -le "$nm" ]
				do
					eval id=\$id$n${l}c${c}m$m
					eval pn=\$IDCOUNT$id
					pn=`expr "$pn" - 1`
					eval IDCOUNT$id=$pn

					m=`expr $m + 1`
				done

				c=`expr $c + 1`
			done
			l=`expr $l + 1`
		done
		return 1
	fi

}	# end of epcconf

#########################################################################
#                                                                       #
#  Main - CONFIG                                                        #
#                                                                       #
#########################################################################

#
#	Copyright
#
clear
echo "

		Copyright 1996-98 Digi International, Inc.
 			All rights reserved."

OPSYS="HP-UX"

#
#	Query for installation options
#
echo "
			RESTRICTED RIGHTS LEGEND

	Use, duplication, or disclosure by the Government is subject to
	restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
	in Technical Data and Computer Software clause at DFARS 252.227-7013.

		Digi International Inc. d/b/a Digi
			11001 Bren Road East
                        Minnetonka, MN 55343






	Please hit <Return> to continue: \c"
read dummy
clear
echo "
This script installs the ${FULLNAME}
driver for:

			${REVSTRING}


This script also installs the information needed by ${OPSYS} to use
these additional ports.  This driver currently supports 4 asynchronous
serial adapters.

    
	Please hit <Return> to continue: \c"
read dummy
clear

# Call the Remove script to remove all of the old junk
# if the driver appears to be installed
#if [ -f /etc/conf/digi/epca/Remove ]
#then
#	/etc/conf/digi/epca/Remove install
#fi

# Call the unconfigure script to remove all the old junk
# if the driver appears to be installed
if [ -f /var/adm/sw/products/EPCA/unconfigure ]
then
	/var/adm/sw/products/EPCA/unconfigure install
fi

Ittyname='tty'
Ottyname='cu'
prname='pr'

#
#	Ask which slot the board is going to be installed in
#
#clear
#echo "Which slot is your host adapter installed (1-4)? \c"
#
#while :
#do
#	read slot
#
#	case "$slot" in
#	[1-4])
#		slot=`expr $slot - 1`
#		break
#		;;
#	*)
#		echo "Which slot is your host adapter installed (1-4)? \c"
#		;;
#
#	esac
#done

#
#	Get available concentrator ID's from system
#
#
echo "\nSearching for port names already in use..."
ID1=
ID2=
IDLIST=

if [ "$Ittyname" = "tty" ]
then
	#skip p 'cause /dev/ttypxx is used for pseudo ttys
	#tmpstr="a b c d e f g h i j k l m n o q r s t u v w x y z"
	tmpstr="a b c d e f g h i j k l m n o"
else
	#tmpstr="a b c d e f g h i j k l m n o p q r s t u v w x y z"
	tmpstr="a b c d e f g h i j k l m n o"
fi

for i in $tmpstr
do
	if ls /dev/${Ittyname}${i}[0-9][0-9] >/dev/null 2>&1
	then
		if [ "`echo ${usedid} | grep ${i}`" ]
		then
			IDTMP="${IDTMP} ${i}"
		else
			ID2="${ID2} ${i}"    # We may not need this at all ???
		fi
	else
		ID1="${ID1} ${i}"
	fi
done

IDLIST="${IDTMP} ${ID1} "		# This is the available ID list
IDLIST1="$IDLIST"
IDLIST2="$IDLIST"

clear
cat <<!
The port names (in the /dev directory) will look like:

	/dev/${Ittyname}a01

where \`${Ittyname}' is the basename, \`a' is an ID letter that can be
different for each port box, and \`01' is the port number.

Systems with a large number of ports may need to use some letters more
than once.  When this occurs, the first box to use an ID letter will
get port numbers 01-16, the second box to use that letter will get
port numbers 17-32, and so on.

!

echo "   Do you want to continue (y or n)? \c"
if eval "$getyn"
then
	AUTOIDS=yes
else
	exit 1
fi

#
#	Configuration loop
#
#
#	Initialize variables
#
fepport=""
fepmem=""
nports=""
config=""
slot_string=""

clear

#
#	Custom installation
#
echo "
How many adapters do you wish to install (1-4)? \c"

while :
do
	read nbrds
	case ${nbrds} in
	1|2|3|4) NHOSTS=nbrds
		break
		;;
	*)	echo "Please enter a number between 1 and 4: \c"
		;;
	esac
done

tmpid=""
n=1
while [ $n -le ${nbrds} ]
do
	iodisplay=""
	memdisplay=""
	altpindisplay=""

	clear
	echo " Configuring adapter ${n}..."

	#
	# get board type
	#
	echo "

	Adapters supported:

	EISA Adapters
		1) AccelePort Xem EISA
		2) AccelePort C/X EISA
		3) AccelePort EPC/X EISA "

	if [ $minor_id -gt 10 ]
	then
	echo "
	PCI Adapters
		4) AccelePort Xr PCI
		5) AccelePort Xem PCI
		6) AccelePort C/X PCI
		7) AccelePort EPC/X PCI "
	fi

	echo "
	What type is adapter number ${n}? \c"

	while :
	do
		read btype
		btype=`expr $btype + 3`
		case $btype in
#		1)
#			BTYPE=$btype
#			BNAME="PC/Xem"
#			PLATFORM=ISA
#			break
#			;;
#		2)
#			BTYPE=$btype
#			BNAME="ISA C/X Host Adapter"
#			PLATFORM=ISA
#			break
#			;;
#		3)
#			BTYPE=$btype
#			BNAME="ISA EPC/X Host Adapter"
#			PLATFORM=ISA
#			break
#			;;
		4)
			BTYPE=$btype
			BNAME="AccelePort Xem EISA"
			PLATFORM=EISA
			break
			;;
		5)
			BTYPE=$btype
			BNAME="AccelePort C/X EISA"
			PLATFORM=EISA
			break
			;;
		6)
			BTYPE=$btype
			BNAME="AccelePort EPC/X EISA"
			PLATFORM=EISA
			break
			;;
		7)
			BTYPE=$btype
			BNAME="AccelePort Xr PCI"
			PLATFORM=PCI
			break
			;;
		8)
			BTYPE=$btype
			BNAME="AccelePort Xem PCI"
			PLATFORM=PCI
			break
			;;
		9)
			BTYPE=$btype
			BNAME="AccelePort C/X PCI"
			PLATFORM=PCI
			break
			;;
		10)
			BTYPE=$btype
			BNAME="AccelePort EPC/X PCI"
			PLATFORM=PCI
			break
			;;
		*)
#			echo "Please enter a number between 4 and 6: \c"
			echo "Please enter a number between 1 and 7: \c"
			;;
		esac
	done

	case $BTYPE in
	1|2|3|4|5|6)
		#
		#	Ask which slot the board is going to be installed in
		#
		clear
		echo "In what slot is host adapter ${n} installed (1-4)? \c"

		while :
		do
			read slot

			case "$slot" in
			[1-4])
				slot_entered=$slot
				slot=`expr $slot - 1`
				break
				;;
			*)
				echo "In what slot is host adapter ${n} installed (1-4)? \c"
				;;

			esac
		done

		slot_string="${slot_string} -s ${slot}"

		;;
	7|8|9|10)
		slot=127
		slot_string="${slot_string} -s 127"
		;;
	esac


	case $BTYPE in

	# *****************************
	# PC/Xem ISA Board
	# *****************************

	1)	
		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}


Selecting the I/O port:
 The I/O port choice must match the setting of the dip switches on the
 adapter, and must not conflict with other devices in the system.
 Problems with the I/O port selection should be checked for if your
 system fails to find the adapter or your system locks up.

	The I/O port address choices, in hexadecimal, are:

		104	204	304
		114	224	324
		124

	Please enter selection (104-324): \c"

		while :
		do
			read sel
			case "${sel}" in
			104|114|124|204|224|304|324) ;;
			*)	echo "	Please enter a number between 104 and 324: \c"
				continue
				;;
			esac

			case " ${fepport} " in
			*" ${sel} "*)	echo "
	Conflict with previously selected I/O address.
	Please enter another selection (104-324): \c"
				continue
				;;
			esac

			porttmp="${sel}"
			break
		done

		conftmp="${conftmp} ${sel}"
		iodisplay=" I/O port is ${porttmp}. "
		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}

Selecting the memory address:
 The memory address choice must not conflict with other devices in the
 system.  Problems with the memory address selection should be checked
 for if your system fails to find \"adapter memory\" or your system
 locks up.

	The memory address choices, in hexadecimal, are:

   *80) 0x00080000 *A0) 0x000A0000  C0) 0x000C0000  E0) 0x000E0000
   *88) 0x00088000 *A8) 0x000A8000  C8) 0x000C8000  E8) 0x000E8000
   *90) 0x00090000 *B0) 0x000B0000  D0) 0x000D0000  F0) 0x000F0000
   *98) 0x00098000 *B8) 0x000B8000  D8) 0x000D8000  F8) 0x000F8000

        *NOTE: selections 80-98 usually conflict with system memory.
               selections A0-B8 usually conflict with video boards.

	Please enter selection code (80-F8): \c"

		while :
		do
			read sel
			sel=`echo ${sel} | tr "[a-z]" "[A-Z]"`
			case "${sel}" in
			[89][08]|[A-F][08]) memtmp="${memtmp} ${sel}"
				conftmp="${conftmp} ${sel}"
				memory="0x000${sel}000"
				;;
			*)	echo "	Please enter a number between 80 and F8: \c"
				continue
				;;
			esac
			memdisplay=" Memory Address is ${memory}.
"
			break

		done
		;;

	# *****************************
	# C/X ISA Host adapter questions
	# *****************************

	2)	
		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}

Selecting the I/O port:
 The I/O port choice must match the setting of the dip switches on the
 adapter, and must not conflict with other devices in the system.
 Problems with the I/O port selection should be checked for if your
 system fails to find the adapter or your system locks up.

	The I/O port address choices, in hexadecimal, are:

		108	208	308
		118	228	328
		128

	Please enter selection (108-328): \c"

		while :
		do
			read sel
			case "${sel}" in
			108|118|128|208|228|308|328) ;;
			*)	echo "	Please enter a number between 108 and 328: \c"
				continue
				;;
			esac

			case " ${fepport} " in
			*" ${sel} "*)	echo "
	Conflict with previously selected I/O address.
	Please enter another selection (108-328): \c"
				continue
				;;
			esac

			porttmp="${sel}"
			break
		done

		conftmp="${conftmp} ${sel}"
		iodisplay=" I/O port is ${porttmp}.
"


		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}

Selecting the memory address:
 The memory address choice must not conflict with other devices in the
 system.  Problems with the memory address selection should be checked
 for if your system fails to find \"adapter memory\" or your system
 locks up.

	The memory address choices, in hexadecimal, are:

   *80) 0x00080000 *A0) 0x000A0000  C0) 0x000C0000  E0) 0x000E0000
   *88) 0x00088000 *A8) 0x000A8000  C8) 0x000C8000  E8) 0x000E8000
   *90) 0x00090000 *B0) 0x000B0000  D0) 0x000D0000  F0) 0x000F0000
   *98) 0x00098000 *B8) 0x000B8000  D8) 0x000D8000  F8) 0x000F8000

        *NOTE: selections 80-98 usually conflict with system memory.
               selections A0-B8 usually conflict with video boards.

	Please enter selection code (80-F8): \c"

		while :
		do
			read sel
			sel=`echo ${sel} | tr "[a-z]" "[A-Z]"`
			case "${sel}" in
			[89][08]|[A-F][08]) memtmp="${memtmp} ${sel}"
				conftmp="${conftmp} ${sel}"
				memory="0x000${sel}000"
				;;
			*)	echo "	Please enter a number between 80 and F8: \c"
				continue
				;;
			esac
			memdisplay=" Memory Address is ${memory}.
"
			break

		done
		;;

	# *****************************
	# EPC ISA Host adapter questions
	# *****************************

	3)	
		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}

Selecting the I/O port:
 The I/O port choice must match the setting of the dip switches on the
 adapter, and must not conflict with other devices in the system.
 Problems with the I/O port selection should be checked for if your
 system fails to find the adapter or your system locks up.

	The I/O port address choices, in hexadecimal, are:

		108	208	308
		118	228	328
		128

	Please enter selection (108-328): \c"

		while :
		do
			read sel
			case "${sel}" in
			108|118|128|208|228|308|328) ;;
			*)	echo "	Please enter a number between 108 and 328: \c"
				continue
				;;
			esac

			case " ${fepport} " in
			*" ${sel} "*)	echo "
	Conflict with previously selected I/O address.
	Please enter another selection (108-328): \c"
				continue
				;;
			esac

			porttmp="${sel}"
			break
		done

		conftmp="${conftmp} ${sel}"
		iodisplay=" I/O port is ${porttmp}.
"
		clear
		echo " Configuring adapter ${n}.
 Adapter type is ${BNAME}.
${iodisplay}${memdisplay}

Selecting the memory address:
 The memory address choice must not conflict with other devices in the
 system.  Problems with the memory address selection should be checked
 for if your system fails to find \"adapter memory\" or your system
 locks up.

	The memory address choices, in hexadecimal, are:

   *80) 0x00080000 *A0) 0x000A0000  C0) 0x000C0000  E0) 0x000E0000
   *88) 0x00088000 *A8) 0x000A8000  C8) 0x000C8000  E8) 0x000E8000
   *90) 0x00090000 *B0) 0x000B0000  D0) 0x000D0000  F0) 0x000F0000
   *98) 0x00098000 *B8) 0x000B8000  D8) 0x000D8000  F8) 0x000F8000

        *NOTE: selections 80-98 usually conflict with system memory.
               selections A0-B8 usually conflict with video boards.

	Please enter selection code (80-F8): \c"

		while :
		do
			read sel
			sel=`echo ${sel} | tr "[a-z]" "[A-Z]"`
			case "${sel}" in
			[89][08]|[A-F][08]) memtmp="${memtmp} ${sel}"
				conftmp="${conftmp} ${sel}"
				memory="0x000${sel}000"
				;;
			*)	echo "	Please enter a number between 80 and F8: \c"
				continue
				;;
			esac
			memdisplay=" Memory Address is ${memory}.
"
			break

		done
		;;

	# *****************************
	# EISA/Xem Board
	# *****************************

	4)	
		# No I/O port asked for EISA
		porttmp=0
		conftmp="${conftmp} 0"
#		clear
#		echo " Configuring board ${n}.
# Board type is ${BNAME}.
#${iodisplay}${memdisplay}
#Selecting the memory address:
# The memory address choice must not conflict with other devices in the system.
# Problems with the memory address selection should be checked for if your
# system fails to find \"board memory\" or your system locks up.
#
#	The memory address choices, in hexadecimal, are:
#
#   *80) 0x00080000 *A0) 0x000A0000  C0) 0x000C0000  E0) 0x000E0000
#   *88) 0x00088000 *A8) 0x000A8000  C8) 0x000C8000  E8) 0x000E8000
#   *90) 0x00090000 *B0) 0x000B0000  D0) 0x000D0000  F0) 0x000F0000
#   *98) 0x00098000 *B8) 0x000B8000  D8) 0x000D8000  F8) 0x000F8000
#        *NOTE: selections 80-98 usually conflict with system memory.
#               selections A0-B8 usually conflict with video boards.
#
#  F000) 0xF0000000  F400) 0xF4000000  F800) 0xF8000000  FC00) 0xFC000000
#  F100) 0xF1000000  F500) 0xF5000000  F900) 0xF9000000  FD00) 0xFD000000
#  F200) 0xF2000000  F600) 0xF6000000  FA00) 0xFA000000  FE00) 0xFE000000
#  F300) 0xF3000000  F700) 0xF7000000  FB00) 0xFB000000  FF00) 0xFF000000
#
#	Please enter selection code (80-F8 or F000-FF00): \c"
#
#		while :
#		do
#			read sel
#			sel=`echo ${sel} | tr "[a-z]" "[A-Z]"`
#			case "${sel}" in
#			[89][08]|[A-F][08])
#				memtmp="${memtmp} ${sel}"
#				conftmp="${conftmp} ${sel}"
#				memory="0x000${sel}000"
#				;;
#			F[0-9A-F]00)
#				memtmp="${memtmp} ${sel}0"
#				conftmp="${conftmp} ${sel}"
#				memory="0x${sel}0000"
#				;;
#			*)	echo "	Please enter a number between 80 and F8 or F000 and FF00: \c"
#				continue
#				;;
#			esac
#			memdisplay=" Memory Address is ${memory}.
#"
#			break
#
#		done
		# No memory address in EISA
		memtmp="${memtmp} 80"
		conftmp="${conftmp} 80"
		memory="0x00000000"
		memdisplay=""
		;;

	# *****************************
	# EISA C/X Host adapter questions
	# *****************************

	5)	
		# No I/O port asked for EISA
		porttmp=0
		conftmp="${conftmp} 0"

#		clear
#		echo " Configuring board ${n}.
# Board type is ${BNAME}.
#${iodisplay}${memdisplay}
#Selecting the memory address:
# The memory address choice must not conflict with other devices in the system.
# Problems with the memory address selection should be checked for if your
# system fails to find \"board memory\" or your system locks up.
#
#	The memory address choices, in hexadecimal, are:
#
#   *80) 0x00080000 *A0) 0x000A0000  C0) 0x000C0000  E0) 0x000E0000
#   *88) 0x00088000 *A8) 0x000A8000  C8) 0x000C8000  E8) 0x000E8000
#   *90) 0x00090000 *B0) 0x000B0000  D0) 0x000D0000  F0) 0x000F0000
#   *98) 0x00098000 *B8) 0x000B8000  D8) 0x000D8000  F8) 0x000F8000
#        *NOTE: selections 80-98 usually conflict with system memory.
#               selections A0-B8 usually conflict with video boards.
#
#  F000) 0xF0000000  F400) 0xF4000000  F800) 0xF8000000  FC00) 0xFC000000
#  F100) 0xF1000000  F500) 0xF5000000  F900) 0xF9000000  FD00) 0xFD000000
#  F200) 0xF2000000  F600) 0xF6000000  FA00) 0xFA000000  FE00) 0xFE000000
#  F300) 0xF3000000  F700) 0xF7000000  FB00) 0xFB000000  FF00) 0xFF000000
#
#	Please enter selection code (80-F8 or F000-FF00): \c"
#
#		while :
#		do
#			read sel
#			sel=`echo ${sel} | tr "[a-z]" "[A-Z]"`
#			case "${sel}" in
#			[89][08]|[A-F][08]) memtmp="${memtmp} ${sel}"
#				conftmp="${conftmp} ${sel}"
#				memory="0x000${sel}000"
#				;;
#			F[0-9A-F]00)
#				memtmp="${memtmp} ${sel}0"
#				conftmp="${conftmp} ${sel}"
#				memory="0x${sel}0000"
#				;;
#			*)	echo "	Please enter a number between 80 and F8 or F000 and FF00: \c"
#				continue
#				;;
#			esac
#			memdisplay=" Memory Address is ${memory}.
#"
#			break
#
#		done
		# No memory address in EISA
		memtmp="${memtmp} 80"
		conftmp="${conftmp} 80"
		memory="0x00000000"
		memdisplay=""
		;;

	# *****************************
	# EISA EPC Host adapter questions
	# *****************************

	6)	
		# No I/O port asked for EISA
		porttmp=0
		conftmp="${conftmp} 0"

#		clear
#		echo " Configuring board ${n}, in slot ${slot_entered}.
# Board type is ${BNAME}.
#${iodisplay}${memdisplay}
#Selecting the memory address:
# The memory address choice must not conflict with other devices in the system.
# Problems with the memory address selection should be checked for if your
# system fails to find \"board memory\" or your system locks up.
#
#	The memory address choices, in hexadecimal, are:
#
#   *80) 0x00080000 *A0) 0x000A0000  C0) 0x000C0000  E0) 0x000E0000
#   *88) 0x00088000 *A8) 0x000A8000  C8) 0x000C8000  E8) 0x000E8000
#   *90) 0x00090000 *B0) 0x000B0000  D0) 0x000D0000  F0) 0x000F0000
#   *98) 0x00098000 *B8) 0x000B8000  D8) 0x000D8000  F8) 0x000F8000
#        *NOTE: selections 80-98 usually conflict with system memory.
#               selections A0-B8 usually conflict with video boards.
#
#  F000) 0xF0000000  F400) 0xF4000000  F800) 0xF8000000  FC00) 0xFC000000
#  F100) 0xF1000000  F500) 0xF5000000  F900) 0xF9000000  FD00) 0xFD000000
#  F200) 0xF2000000  F600) 0xF6000000  FA00) 0xFA000000  FE00) 0xFE000000
#  F300) 0xF3000000  F700) 0xF7000000  FB00) 0xFB000000  FF00) 0xFF000000
#
#	Please enter selection code (80-F8 or F000-FF00): \c"
#
#		while :
#		do
#			read sel
#			sel=`echo ${sel} | tr "[a-z]" "[A-Z]"`
#			case "${sel}" in
#			[89][08]|[A-F][08]) memtmp="${memtmp} ${sel}"
#				conftmp="${conftmp} ${sel}"
#				memory="0x000${sel}000"
#				;;
#			F[0-9A-F]00)
#				memtmp="${memtmp} ${sel}0"
#				conftmp="${conftmp} ${sel}"
#				memory="0x${sel}0000"
#				;;
#			*)	echo "	Please enter a number between 80 and F8 or F000 and FF00: \c"
#				continue
#				;;
#			esac
#			memdisplay=" Memory Address is ${memory}.
#"
#			break
#
#		done
		# No memory address in EISA
		memtmp="${memtmp} 80"
		conftmp="${conftmp} 80"
		memory="0x00000000"
		memdisplay=""
		;;

	# *****************************
	# PCI Xr Host adapter questions
	# *****************************

	7)	
		# No I/O port asked for PCI
		porttmp=0
		conftmp="${conftmp} 0"

		# No memory address in PCI
		memtmp="${memtmp} 80"
		conftmp="${conftmp} 80"
		memory="0x00000000"
		memdisplay=""
		;;

	# *****************************
	# PCI Xem Host adapter questions
	# *****************************

	8)	
		# No I/O port asked for PCI
		porttmp=0
		conftmp="${conftmp} 0"

		# No memory address in PCI
		memtmp="${memtmp} 80"
		conftmp="${conftmp} 80"
		memory="0x00000000"
		memdisplay=""
		;;

	# *****************************
	# PCI C/X Host adapter questions
	# *****************************

	9)	
		# No I/O port asked for PCI
		porttmp=0
		conftmp="${conftmp} 0"

		# No memory address in PCI
		memtmp="${memtmp} 80"
		conftmp="${conftmp} 80"
		memory="0x00000000"
		memdisplay=""
		;;

	# *****************************
	# PCI EPC Host adapter questions
	# *****************************

	10)	
		# No I/O port asked for PCI
		porttmp=0
		conftmp="${conftmp} 0"

		# No memory address in PCI
		memtmp="${memtmp} 80"
		conftmp="${conftmp} 80"
		memory="0x00000000"
		memdisplay=""
		;;

	esac

	echo "
	The default setting for altpin is off.
	Is this acceptable (y or n)? \c"

	if eval "$getyn" ; then
		altpin=0
		echo "
		Altpin is set to off\n"
		altpindisplay=" Altpin is set to off.
"
	else
		altpin=1
		echo "
		Altpin is set to on\n"
		altpindisplay=" Altpin is set to on.
"
	fi

	case $BTYPE in
		1|4|8)
			emconf
			;;
		2|5|9)
			cxconf
			;;
		3|6|10)
			epcconf
			;;
		7)
			xrconf
			;;
	esac

	if [ $? -eq 0 ]
	then
		fepmem="$fepmem $memtmp"
		config="$config $conftmp"
		fepport="$fepport $porttmp"
		concids="$concids $tmpid"
		eval btype${n}=\$BTYPE
		eval bname${n}=\$BNAME
		eval fepmem$n="$memory"
		eval fepport$n="$porttmp"
		eval fepaltpin$n="$altpin"
		memtmp=""
		conftmp=""
		porttmp=""
		tmpid=""
		n=`expr ${n} + 1`
	else
		memtmp=""
		conftmp=""
		porttmp=""
		tmpid=""
		memory=""
		altpin=""
		echo "\nHit <Return> to re-configure adapter #${n}: \c"
		read aa
	fi
done


 echo "\n
Do you wish to update /etc/ttytype (y or n)? \c"

if eval "$getyn"
then
	ttyupdate=1
else
	ttyupdate=0
fi

# --------------------------------------------------------
#
#     Now we're done asking questions.  Here is where the
#     actual configuring starts to happen.
#
# --------------------------------------------------------

#
#	generate configuration file
#	also, count the total number of ports for use later
#
clear
echo "\n\nGenerating configuration file...\c"

total=0

exec 3>/tmp/config$$

echo "CONFIG_BEGIN" >&3
n=1
while [ $n -le $nbrds ]
do
	eval btype=\$btype$n
	case $btype in
	1)
		# PC/Xem
		echo "board isa_pcm" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		c=1
		eval nconc=\$nconc${n}0
		while [ "$c" -le "$nconc" ]
		do
			echo "\tmodule ports" >&3
			eval nports=\$nports${n}0c${c}
                        echo "\t\tnports $nports" >&3
			eval id=\$id${n}0c${c}
			echo "\t\tid $id" >&3
			c=`expr $c + 1`
			total=`expr $total + $nports`
		done
		;;
	4)
		# EISA/Xem
		echo "board eisa_pcm" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		c=1
		eval nconc=\$nconc${n}0
		while [ "$c" -le "$nconc" ]
		do
			echo "\tmodule ports" >&3
			eval nports=\$nports${n}0c${c}
			echo "\t\tnports $nports" >&3
			eval id=\$id${n}0c${c}
			echo "\t\tid $id" >&3
			c=`expr $c + 1`
			total=`expr $total + $nports`
		done
		;;
	8)
		# PCI Xem
		echo "board pci_xem" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		c=1
		eval nconc=\$nconc${n}0
		while [ "$c" -le "$nconc" ]
		do
			echo "\tmodule ports" >&3
			eval nports=\$nports${n}0c${c}
			echo "\t\tnports $nports" >&3
			eval id=\$id${n}0c${c}
			echo "\t\tid $id" >&3
			c=`expr $c + 1`
			total=`expr $total + $nports`
		done
		;;
	7)
		# PCI Xr
		echo "board pci_xr" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		c=1
		eval nconc=\$nconc${n}0
		while [ "$c" -le "$nconc" ]
		do
			echo "\tmodule ports" >&3
			eval nports=\$nports${n}0c${c}
			echo "\t\tnports $nports" >&3
			eval id=\$id${n}0c${c}
			echo "\t\tid $id" >&3
			c=`expr $c + 1`
			total=`expr $total + $nports`
		done
		;;
	2)
		# ISA C/X
		echo "board isa_cx" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		l=0
		while [ $l -lt 2 ]
		do
			echo "\t\tline $l" >&3
			l=`expr $l + 1`
			eval spd=\$baud$n${l}c0
			echo "\t\t\tspeed $spd" >&3
			c=1
			eval nconc=\$nconc$n$l
			while [ "$c" -le "$nconc" ]
			do
				echo "\t\t\tconc cx" >&3
				echo "\t\t\t\tnports 16" >&3
				eval spd=\$baud$n${l}c$c
				echo "\t\t\t\tspeed $spd" >&3
				eval id=\$id$n${l}c${c}
				echo "\t\t\t\tid $id" >&3
				c=`expr $c + 1`
				total=`expr $total + 16`
			done
		done
		;;
	5)
		# EISA C/X
		echo "board eisa_cx" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		l=0
		while [ $l -lt 2 ]
		do
			echo "\t\tline $l" >&3
			l=`expr $l + 1`
			eval spd=\$baud$n${l}c0
			echo "\t\t\tspeed $spd" >&3
			c=1
			eval nconc=\$nconc$n$l
			while [ "$c" -le "$nconc" ]
			do
				echo "\t\t\tconc cx" >&3
				echo "\t\t\t\tnports 16" >&3
				eval spd=\$baud$n${l}c$c
				echo "\t\t\t\tspeed $spd" >&3
				eval id=\$id$n${l}c${c}
				echo "\t\t\t\tid $id" >&3
				c=`expr $c + 1`
				total=`expr $total + 16`
			done
		done
		;;
	9)
		# PCI C/X
		echo "board pci_cx" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		l=0
		while [ $l -lt 2 ]
		do
			echo "\t\tline $l" >&3
			l=`expr $l + 1`
			eval spd=\$baud$n${l}c0
			echo "\t\t\tspeed $spd" >&3
			c=1
			eval nconc=\$nconc$n$l
			while [ "$c" -le "$nconc" ]
			do
				echo "\t\t\tconc cx" >&3
				echo "\t\t\t\tnports 16" >&3
				eval spd=\$baud$n${l}c$c
				echo "\t\t\t\tspeed $spd" >&3
				eval id=\$id$n${l}c${c}
				echo "\t\t\t\tid $id" >&3
				c=`expr $c + 1`
				total=`expr $total + 16`
			done
		done
		;;
	3)
		# ISA EPC
		echo "board isa_epc" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		l=0
		while [ $l -lt 2 ]
		do
			echo "\t\tline $l" >&3
			l=`expr $l + 1`
			eval spd=\$baud$n${l}c0
			echo "\t\t\tspeed $spd" >&3
			c=1
			eval nconc=\$nconc$n$l
			while [ "$c" -le "$nconc" ]
			do
				echo "\t\t\tconc epc" >&3
				echo "\t\t\t\tnports 16" >&3
				eval spd=\$baud$n${l}c$c
				echo "\t\t\t\tspeed $spd" >&3
				eval id=\$id$n${l}c${c}
				echo "\t\t\t\tid $id" >&3

				m=1
				eval nm=\$nmod$n${l}c$c
				while [ "$m" -le "$nm" ]
				do
					echo "\t\t\t\tmodule ports" >&3
					eval nports=\$nports${n}${l}c${c}m$m
					echo "\t\t\t\t\tnports $nports" >&3
					eval id=\$id$n${l}c${c}m$m
					echo "\t\t\t\t\tid $id" >&3
					m=`expr $m + 1`
					total=`expr $total + $nports`
				done
			
				c=`expr $c + 1`
				total=`expr $total + 16`
			done
		done
		;;
	6)
		# EISA EPC
		echo "board eisa_epc" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		l=0
		while [ $l -lt 2 ]
		do
			echo "\t\tline $l" >&3
			l=`expr $l + 1`
			eval spd=\$baud$n${l}c0
			echo "\t\t\tspeed $spd" >&3
			c=1
			eval nconc=\$nconc$n$l
			while [ "$c" -le "$nconc" ]
			do
				echo "\t\t\tconc epc" >&3
				echo "\t\t\t\tnports 16" >&3
				eval spd=\$baud$n${l}c$c
				echo "\t\t\t\tspeed $spd" >&3
				eval id=\$id$n${l}c${c}
				echo "\t\t\t\tid $id" >&3

				m=1
				eval nm=\$nmod$n${l}c$c
				while [ "$m" -le "$nm" ]
				do
					echo "\t\t\t\tmodule ports" >&3
					eval nports=\$nports${n}${l}c${c}m$m
					echo "\t\t\t\t\tnports $nports" >&3
					eval id=\$id$n${l}c${c}m$m
					echo "\t\t\t\t\tid $id" >&3
					m=`expr $m + 1`
					total=`expr $total + $nports`
				done
			
				c=`expr $c + 1`
				total=`expr $total + 16`
			done
		done
		;;
	10)
		# PCI EPC
		echo "board pci_epc" >&3
		eval io=\$fepport$n
		echo "\tio 0x$io" >&3
		eval mem=\$fepmem$n
		echo "\tmem $mem" >&3
		eval altp=\$fepaltpin$n
		echo "\taltpin $altp" >&3
		l=0
		while [ $l -lt 2 ]
		do
			echo "\t\tline $l" >&3
			l=`expr $l + 1`
			eval spd=\$baud$n${l}c0
			echo "\t\t\tspeed $spd" >&3
			c=1
			eval nconc=\$nconc$n$l
			while [ "$c" -le "$nconc" ]
			do
				echo "\t\t\tconc epc" >&3
				echo "\t\t\t\tnports 16" >&3
				eval spd=\$baud$n${l}c$c
				echo "\t\t\t\tspeed $spd" >&3
				eval id=\$id$n${l}c${c}
				echo "\t\t\t\tid $id" >&3

				m=1
				eval nm=\$nmod$n${l}c$c
				while [ "$m" -le "$nm" ]
				do
					echo "\t\t\t\tmodule ports" >&3
					eval nports=\$nports${n}${l}c${c}m$m
					echo "\t\t\t\t\tnports $nports" >&3
					eval id=\$id$n${l}c${c}m$m
					echo "\t\t\t\t\tid $id" >&3
					m=`expr $m + 1`
					total=`expr $total + $nports`
				done
			
				c=`expr $c + 1`
				total=`expr $total + 16`
			done
		done
		;;
	esac
	n=`expr $n + 1`
done

echo "ttyname $Ittyname" >&3
echo "cuname $Ottyname" >&3
echo "prname $prname" >&3
#echo "altpin $altpin" >&3
echo "CONFIG_END" >&3
exec 3>&-

#
# Run epcconfig for space allocation etc.
#
# -u - create space.c file
# -n - create node file
# -i - create /etc/inittab file
# -t - create ttytype file
# -T - create mktty.sh script (checks for and creates ttys)
# echo "This is the slot string ${slot_string}"
options="-u /etc/conf/digi/Space.c -i /tmp/Init ${slot_string}"
options="$options -T /etc/conf/digi/epca/mktty.sh"
if [ $ttyupdate = 1 ]
then
	options="$options -t /tmp/ttytype"
fi

/etc/conf/digi/epca/epcconfig $options </tmp/config$$ 2>/tmp/config.log

if [ $? != 0 ]
then
	echo "\nError in config file, see /tmp/config.log for details."
	exit 1
fi

echo " done.\n"

#
# cat /tmp/Init to the end of /etc/inittab
#
if [ -f /tmp/Init ]
then
	chmod 644 /etc/inittab
	cat /tmp/Init >> /etc/inittab
	chmod 444 /etc/inittab
fi

echo "\nInstalling ${BRDNAME} driver ... "

echo
mjrs=
tot=$total

# Move download program into place
#
#[ -f /etc/digidl ] && mv /etc/digidl /etc/digidl.old
#
#if [ -f /tmp/digidl ]
#then
#	mv /tmp/digidl /etc/digidl
#fi
#
#if [ -f /etc/digidl ]
#then
#	chmod 711 /etc/digidl
#fi
	
# Set up an rc file to start the download program
cat <<! >/etc/rc.config.d/digiepca
#
# Set digi_download to 0 to disable BIOS & FEP downloads
#                   to 1 to enable downloads
#
export digi_download=1

#
# Set digi_portconfig to the path of an optional port configuration
#                     script which should be executed after the ports
#                     are enabled
export digi_portconfig="/usr/conf/digi/portconfig"
!
 
cat <<! >/sbin/init.d/digiepca
#!/sbin/sh
#
# Startup and kill script for the Digi download program
#
export PATH=/sbin:/usr/sbin:/usr/bin

case "\$1" in
"start_msg")
	echo "Starting the Digi download process" 
	;;
"start")
	if [ "\$digi_download" -ne 0 ]
	then
		chown root /dev/dl
		chmod 600 /dev/dl
		cd /etc/conf/digi/epca
		/sbin/sh ./mktty.sh
		./digidl &
		sleep 60
		[ -x "\$digi_portconfig" ] && [ ! -d "\$digi_portconfig" ] && \\
									  \$digi_portconfig
	else
		exit 2
	fi
	exit 0
	;;
"stop_msg")
	echo "Stopping the Digi download process"
	;;
"stop")
	PID=\`ps -e | awk '\$4 == "digidl" {print \$1}'\`
	[ -z "\$PID" ] && exit 2
	kill "\$PID"
	;;
*)
	echo "Usage: \$0 {start|stop|start_msg|stop_msg}"
	exit 1
	;;
esac

exit 0;
!

chmod 555 /sbin/init.d/digiepca
chown bin:bin /sbin/init.d/digiepca
ln -s /sbin/init.d/digiepca /sbin/rc3.d/S100digiepca
ln -s /sbin/init.d/digiepca /sbin/rc2.d/K900digiepca

cd /tmp
#
#	Save names and ids for removal script
#
ids=""
set ${concids} 0

while [ ${1} != "0" ]
do
	ids="${ids}${1}"
	ids="${ids}`echo ${1} | tr "[a-z]" "[A-Z]"`"
	shift
done

echo "${Ittyname}" >/tmp/${NAME}ttyname
echo "${Ottyname}" >/tmp/${NAME}ottyname
echo "${ids}" >>/tmp/${NAME}ttyname
echo "${prname}" >/tmp/${NAME}prname

echo "Installing ${OPSYS} device information ... \c"

#
#	Remove old devices
#
#for i in $concids
#do
#	rm -f /dev/${Ittyname}${slot}[${i}][0-9][0-9]
#	rm -f /dev/${Ottyname}[${i}][0-9][0-9]
#	rm -f /dev/${prname}[${i}][0-9][0-9]
#done
#rm -f /dev/dl

#
#	edit gettydefs
#

echo
echo "\nEditing /etc/gettydefs to remove IXANY ..."

if [ ! -s /etc/gettydefs.digi ]
then
	cp /etc/gettydefs /etc/gettydefs.digi
fi

ed gettydefs >/dev/null 2>/dev/null <<!
g/ IXANY/s/ IXANY//g
w
q
!
chmod 644 /etc/gettydefs

#
# Remove past entries from /etc/ttys and /etc/ttytype
#
set ${concids} 0
ids=""

while [ ${1} != "0" ]
do
	ids="${ids}${1}"
	ids="${ids}`echo ${1} | tr "[a-z]" "[A-Z]"`"
	shift
done

#
#	Remove terminal definitions from Init
# 
if [ $ttyupdate = 1 ]
then
	if grep -s ${Ittyname}[${ids}][0-9][0-9] /etc/ttytype > /dev/null
	then
		echo " \cRemoving past entries for ${BRDNAME} ports from /etc/ttytype ... \c"

		mv /etc/ttytype /etc/ttytype.${NAME}
		sed -e '
/'"${Ittyname}[${ids}]"'[0-9][0-9]$/ D
' /etc/ttytype.${NAME} > /etc/ttytype 
	fi 

	echo "\nAdding ${BRDNAME} entries to /etc/ttytype ..."
fi

#
#	Edit /etc/ttytype
#
if [ ${ttyupdate} -eq 1 ]
then
	cat /tmp/ttytype >>/etc/ttytype
fi

chmod 666 /etc/ttytype

tot=$total
n=1
DRVIDS=

for sfx in a b c d e f g h i j k l m n
do
	if [ "$tot" -le "0" ]
	then
		break
	fi

	DRVIDS="$DRVIDS ${dn}"

	tot=`expr "$tot" - "64"`
	n=`expr "$n" + "1"`
done

#
# Add the appropriate lines in the config files.
#
#
# First create the master file.
#
if [ -f /usr/conf/master.d/emux ]
then
	rm -f /usr/conf/master.d/emux
fi

cat > /usr/conf/master.d/emux <<.
\$DRIVER_INSTALL
***************
* Driver      Block major      Char major       Required for
*                                              minimal system
emux              -1               -1                0
\$\$\$

\$DRIVER_LIBRARY
***************
* Driver handle    <libraries>
*  
emux			libdigi.a
\$\$\$

\$LIBRARY
********
* Library   <required>
*
libdigi.a       0
\$\$\$
.

#
if [ -f /stand/build/system ]
then
	mv /stand/build/system /stand/build/system.bak
fi
/usr/lbin/sysadm/system_prep -s /stand/build/system
awk '/^[^*]/ && zz==0 {zz = 1; print "emux"} {print $0}' \
    < /stand/build/system > /tmp/digi_tmp_system

if [ -f /tmp/digi_tmp_system ]
then
	mv /tmp/digi_tmp_system /stand/build/system
fi

AR_BASE="/usr/conf/digi"
cc -c -O -s -o ${AR_BASE}/space.o ${AR_BASE}/Space.c

if [ -f /usr/conf/lib/libdigi.a ]
then
	rm -f /usr/conf/lib/libdigi.a
fi

if [ -f /usr/bin/ar ]
then
/usr/bin/ar r /usr/conf/lib/libdigi.a ${AR_BASE}/emux.o ${AR_BASE}/space.o \
	${AR_BASE}/emux_images.o 
else
	echo "The file '/usr/sbin/ar' does not exist, please install it and try again"
	exit 1
fi

#VCM

cd /stand/build
echo "Generating new kernel 'make' file ..."
/usr/sbin/config -s system

echo "Generating a new kernel ..."
make -f config.mk 2>> /tmp/config.log


if [ $? != 0 ]
then
	echo "There was an error during Kernel reconfiguration.
$ERROR1

$ERROR2"
	exit 1
fi


if [ -f /stand/vmunix ]
then
	echo 'Making a backup copy of the current UNIX kernel to "/stand/vmunix.bak" ...  '
	mv /stand/vmunix /stand/vmunix.bak
fi

echo "\nInstalling the new kernel"
mv /stand/build/system /stand/system
mv /stand/build/vmunix_test /stand/vmunix

#if [ -f /tmp/mktty.sh ]
#then
#	echo 'Creating devices ...'
#	chmod 711 /tmp/mktty.sh
#	/tmp/mktty.sh
#fi

#echo "$DRVIDS" >/etc/conf/digi/${NAME}/${NAME}drvids
mv /tmp/${NAME}ttyname /etc/conf/digi/${NAME}/${NAME}ttyname
mv /tmp/${NAME}ottyname /etc/conf/digi/${NAME}/${NAME}ottyname
mv /tmp/${NAME}prname /etc/conf/digi/${NAME}/${NAME}prname

# remove installation files/programs
rm -f /tmp/config$$ /tmp/ttytype /tmp/ttys /tmp/Init 

# remove lib files
#rm -f /etc/conf/digi/epca/emux.o /etc/conf/digi/epca/emux_images.o
#rm -f /etc/conf/digi/epca/space.o /etc/conf/digi/epca/locore.o

# echo "Should be removing mktty files now, uncomment me NOW"
#rm -f /tmp/mktty.sh /tmp/mktty.info
#chmod 700 /tmp/hpinst
#mv /tmp/hpinst /etc/conf/digi/epca/hprm
#if [ -f /etc/conf/digi/epca/downld ]
#then
#	mv /etc/conf/digi/epca/downld /etc/conf/digi/epca/digidl
#fi

echo "
Your HP-UX installation was successful, you need to reboot before you
can use your ports.\n"

exit 0
