:
#	@(#) tape.sh 25.1.1.2 93/01/04 
#
#	Copyright (C) 1986-1993 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
#	mkdev/tape - Tape Drive Configuration
#
# Device node naming conventions
#
# All SCSI tape devices get the following device nodes:
#
#	urStpx		-	rewind, unload
#	nurStpx		-	rewind, no-unload
#	nrStpx		-	no-rewind, no-unload
#	xStpx		-	override/control
#
#	rStpx		-	default; differs per type
#		cartridge - urStpx
#		9-track   - nurStpx
#		DAT       - nurStpx
#		exeabyte  - nurStpx
#
# Additional devices specific to each driver:
#
# 9-track:
#	urhStpx		-	hi-density
#	nurhStpx	-	hi-density
#	nrhStpx		-	hi-density
#
# DAT
#	All device files occur in pairs for partition 0 and 1, e.g.:
#		urStpx.0, urStpx.1
#	Default files are linked to partition 0
#

PATH=/etc:/bin:/usr/bin
LANG=english_us.ascii
export PATH LANG

# Set change to NO
change=NO
tmp=/tmp/tp.$$
DEFAULT=/etc/default/tape

# Define return values
: ${OK=0} ${FAIL=1} ${STOP=10} ${HALT=11}

#minor number bits
NOUNLOAD=4
NOREWIND=8
HIDEN=16
ECC=32
PARTITION1=64
OVERRIDE=128

#Compaq SCSI tape script
CPQS_SCRIPT=/usr/lib/mkdev/.cpqs.tape

# Function definitions
##########################

# ---------- STANDARD ROUTINES -------- These routines are commen to scripts
#					requiring kernel relinking.

# Define traps for critical and non critical code.
set_trap()  {	
	trap 'echo "Interrupted! Exiting ..."; cleanup 1' 1 2 3 15
}
unset_trap()  {
	trap '' 1 2 3 15
}
 
# Remove temp files and exit with the status passed as argument
cleanup() {
	trap '' 1 2 3 15
	[ "$tmp" ] && rm -f $tmp*
	exit $1
}

# clear the screen if it is supported
clearscr() {
	# check if the terminal environment is set up
	[ "$TERM" ] && [ -x /bin/clear ] && clear 2> /dev/null
}

# Prompt for yes or no answer - returns non-zero for no
getyn() {
	while	echo "\n$* (y/n) \c">&2
	do	read yn rest
		case $yn in
		[yY])	return $OK 			;;
		[nN])	return $FAIL			;;
		*)	echo "Please answer y or n" >&2	;;
		esac
	done
}

# Prompt with mesg, return non-zero on q
prompt() {
	while	echo "\n${mesg}or enter q to ${quit}: \c" >&2
	do	read cmd
		case $cmd in
		+x|-x)	set $cmd					;;
		Q|q)	return $FAIL					;;
		!*)	eval `expr "$cmd" : "!\(.*\)"`			;;
		"")	# If there is an argument use it as the default
			# else loop until 'cmd' is set
			[ "$1" ] && { 
				cmd=$1
				return $OK
			}
			: continue
			;;
		*)	return $OK					;;
		esac
	done
}

# Print an error message
error() {
	echo "\nError: $*" >&2
	return $FAIL
}

# Configure error message
conferr()  {
	error "\nConfigure failed to update system configuration.
Check /etc/conf/cf.d/conflog for details."
}

# perms list needed if link kit must be installed
permschk () {
	if [ -f /etc/perms/extmd ]; then
		PERM=/etc/perms/extmd
	else
		error "Cannot locate /etc/perms/extmd. This file
is needed to verify Link Kit installation."
		cleanup $FAIL
	fi
}

# test to see if link kit is installed
linkchk()  {
	cd /
	until	fixperm -i -d LINK $PERM
	do	case $? in
		4)  echo "\nThe Link Kit is not installed." >&2	;;
		5)  echo "\nThe Link Kit is only partially installed." >&2  ;;
		*)  echo "\nError testing for Link Kit.  Exiting." >&2 
			cleanup $FAIL  ;;
		esac

		# Not fully installed. Do so here
		getyn "Do you wish to install it now?" || {
			# answered no
			echo "
The Link Kit must be installed to run this program.  Exiting ..."
			cleanup $OK
		}

		# answered yes, so install link kit
		echo "\nInvoking /etc/custom\n"
		/etc/custom -o -i LINK || {
			# custom exited unsuccessfully
			error "custom failed to install Link Kit successfully.  Please try again."
			cleanup $FAIL
		}
	done
}

asklink()  {
	getyn "
You must create a new kernel to effect the driver change you specified.
Do you wish to create a new kernel now?"  ||  {
		echo "
To create a new kernel execute ./link_unix from the /etc/conf/cf.d directory.
Then you must reboot your system by executing  /etc/shutdown -i0  before the
changes you have specified will be implemented.\n"
			return $FAIL 
		}
	return $OK
}

# re-link new kernel
klink() {
	cd /etc/conf/cf.d
	./link_unix || { 
		echo "\nError: Kernel link failed."
		cleanup $FAIL
	}
	echo "
You have successfully re-linked a new kernel. 
In order for the changes to be reflected on your emergency boot floppy set, 
it is recommended that you run the command '/etc/mkdev fd' and re-create 
the emergency boot floppy set with the newly linked kernel.\n"
	return $OK
}
 
# ---------- DEVICE ROUTINE ---------  This routine creates devices
#					

# create appropriate devices.  arguments are name of device and minor dev #
# usage:  mkdevice name minor#
# Global variables used:  
#	$dev_major: add routines
mkdevice() {
	rm -f /dev/$1
	mknod /dev/$1 c $dev_major $2 || {
		error "\nmkdev tape: mknod failed to create /dev/$1."
		return $FAIL 
	}
	chmod 666 /dev/$1
	return $OK 
}

# ---------- CONFIGURE ROUTINES ------- These routines extract information 
#					from and modify kernel configuration
#					files and parameters.

# This routine sets cf_state and the device major number if applicable. 
# Possible values for cf_state are as follows. 
# 	NO: Device not present in mdevice file and therefore has
#	      no major number.
# 	PART: Device present in mdevice file but the -Y option in the configure
#      	      field of the sdevice file is not set. This causes the driver to 
#	      be excluded from the next reconfiguration.
# 	All:  Device has a major number and the -Y option is set in  
#	      the sdevice file.
confchk () {
	name=$1
	cf_state= 	major=
	cd /etc/conf/cf.d
	major=`./configure -j $name` || {
		cf_state=NO
		return $FAIL
	}
	cf_state=PART
	if [ -r ../sdevice.d/$name ] 
	then
		vars=$*
		set `cat ../sdevice.d/$name` || {
			error "cat failed to read sdevice file."
			cleanup $FAIL
		}
		fieldval=$2
		set $vars
		[ "$fieldval" = "Y" ] && {
			cf_state=YES
			return $OK
		}
	else
		getyn "
This device has an entry in the master device file but no corresponding
system device entry. Do you wish to continue and have a default 
entry created?" || cleanup $FAIL
	fi
	return $FAIL
}

# Add driver according to cf_state. 
# Global variables used and where set:
# 	$fns: add routines; $cf_state: confchk(); 
#	$major: confchk() or add routine
confadd() {
	
	cd /etc/conf/cf.d
	case $cf_state in

	NO) 	echo "\nAdding device to system configuration files ...\c" >&2
		major=`./configure -j NEXTMAJOR`
		[ "$ipl" ] && IPL="-l $ipl"
		[ "$iv" ] && IV="-v $iv"
		./configure -a $fns -c -R -m $major $IPL $IV > conflog 2>&1 || {
			conferr
			return $FAIL
		} ;;
	PART)   echo "\nUpdating system configuration ...\c" >&2
	        ./configure -a -c -m $major -Y -R > conflog ||  {
			conferr
			return $FAIL
		} ;;
	esac
	echo "\n\nSystem files have been successfully updated."
	change=YES
	rm -f conflog
	return $OK
}

# Configure driver out of system configuration files by unsetting -Y option.
# Global variables used and where set:
#	$major: confchk() 
confrm() {
	cd /etc/conf/cf.d
	echo "\nUpdating system files to effect removal of driver ...\c"
	./configure -c -d -m $major -Y -R > conflog 2>&1 || {
		conferr
		return $FAIL
	}
	echo "\n\nSystem files have been updated."
	rm -f conflog
	change=YES
	return $OK
}

# -------TAPE SPECIFIC ROUTINES ------- These routines are specific to 
#					mkdev tape. 
#					

# Edit $DEFAULT.
# This file contains the default device used by /usr/bin/tape and also  
# keeps track of the current driver for use by this script.
# The routine will add curdriver if it is not present in DEFAULT.
edit_def () {
	driver=$1
	case $driver in
		ct) 	tpdev=xct0	cdriv=ct		;;
		mc) 	tpdev=xctmini	cdriv=mc		;;
		ft) 	tpdev=xctmini	cdriv=ft		;;
		Stp) 	tpdev=xct0	cdriv=Stp${SCSIpos}	;;
		$CPQS_DRIVER)	edit_def$CPQS_DRIVER		;;
		NONE)   tpdev=xct0	cdriv=NONE		;;
	esac
	cp $DEFAULT $DEFAULT.00 || {
		error "Cannot backup $DEFAULT"
		cleanup $FAIL
	}
	trap 'mv $DEFAULT.00 $DEFAULT; cleanup $FAIL' 1 2 3 15
	sed "/curdriver/d" $DEFAULT > $tmp
	echo "curdriver=$cdriv" >> $tmp
	sed "s!device = /dev/.*!device = /dev/$tpdev!" $tmp > $DEFAULT
	set_trap
}

# ------- Add Drivers -------- 		These routines add tape drivers to 
#					configuration files and create 
#					necessary devices

# This program examines the mscsi file and returns the number of
# SCSI tape devices configured. SCSIpos is used to calculate minor
# device numbers for SCSI tapes.
# Global variables set: 
#	SCSIpos
find_SCSIpos() {
	[ -r /etc/conf/cf.d/mscsi ] || {
		error "\nCannot read /etc/conf/cf.d/mscsi."
		cleanup $FAIL
	}
	tnum=`sed '/^*/d' /etc/conf/cf.d/mscsi | grep -c "Stp"` 
	[ -n "$tnum" ] || {
		error "\nGrep failed to read /etc/conf/cf.d/mscsi."
		cleanup $FAIL
	}
	# SCSI numbering starts at 0.
	SCSIpos=`expr $tnum - 1`
	return $OK
}

# Determine Qic40 or Qic80, and if we support extended length mode, do
# we want it enabled?

qic40_query() 	{
quit="return to the main menu"
mesg="
	1. Install a Qic-40 Tape Drive
	2. Install a Qic-80 Tape Drive

	Select an option "
	while :
	do
		prompt || return $FAIL
		case $cmd in
		1)	model_is_80=0
			break
			;;
		2)	model_is_80=1
			break
			;;
		*) 	echo "
$cmd not valid. Please enter 1 or 2." 	;;
		esac
	done
# check to see if extended mode is supported. If it is, FT_QIC40XL will
# be defined in space.c

if grep FT_QIC40XL /etc/conf/pack.d/ft/space.c > /dev/null; then

	# extended mode is supported. Give user a choice of enabling or not.

	mesg="
	1. Do not enable Extended Length Mode 
	2. Enable Extended Length Mode
		
	Select an option "

	while :
	do
		prompt || return $FAIL
	# set qic type and mode 
		case $cmd in
		1)	if  [ $model_is_80 -ne 0 ]; then model_type="FT_QIC80"
			else model_type="FT_QIC40"
			fi
			break
			;;
		2)	if  [ $model_is_80 -ne 0 ]; then model_type="FT_QIC80XL"
			else model_type="FT_QIC40XL"
			fi
			break
			;;
		*) 	echo "
$cmd not valid. Please enter 1 or 2." 	;;
		esac
	done
else

	# extended mode is not defined in the space.c file
	# XL mode not supported.

	if   [ $model_is_80 -ne 0 ]; then model_type="FT_QIC80"
	else model_type="FT_QIC40"
	fi
fi

# Now change the space.c file
sed -e "s/FT_QIC40;/$model_type;/" /etc/conf/pack.d/ft/space.c > /tmp/space1$$
sed -e "s/FT_QIC40XL;/$model_type;/" /tmp/space1$$ > /tmp/space2$$
rm /tmp/space1$$
sed -e "s/FT_QIC60;/$model_type;/" /tmp/space2$$ > /tmp/space3$$
rm /tmp/space2$$
sed -e "s/FT_QIC80;/$model_type;/" /tmp/space3$$ > /tmp/space4$$
rm /tmp/space3$$
sed -e "s/FT_QIC80XL;/$model_type;/" /tmp/space4$$ > /tmp/space5$$
rm /tmp/space4$$
cp /tmp/space5$$ /etc/conf/pack.d/ft/space.c
rm /tmp/space5$$
return $OK
}

# This routine sets QICpos used to calculate the minor device number
# for QIC-40/QIC-80 tape devices.  It also sets QICsoft for soft select.
# Global variables set: 
#	QICpos	QICsoft
ask_QICpos() {
	minidef=$1
	if grep FT_SOFT_SELECT /etc/conf/pack.d/ft/space.c > /dev/null; then
		softok=1
	fi
	while :
	do	echo "\nEnter one of the following:\n"
		echo "\t1-4\tthe drive select unit number for the"
		echo "\t\tQIC-40 or QIC-80 Tape Driver\n"
		if [ $softok ]; then
			echo "\ts\ta Soft Select mode drive with no select"
			echo "\t\tjumpers installed\n"
		fi
		echo "\tReturn\tthe default value of $minidef\n"
		mesg="Select an option "
		quit="return to the main menu"
		prompt $minidef	|| return $FAIL
		case $cmd in
		"")	tnum=$minidef
			soft=0
				break
				;;
		[1-4])	tnum=$cmd
			soft=0
				break
				;;
		Q|q)	return $FAIL
				break
				;;
		S|s)	if [ $softok ]; then
				tnum=4
				soft=1
				break
			else
				echo "\n$cmd is not valid. Please choose from the list of options."
				continue
			fi
				;;
		*)	echo "\n$cmd is not valid. Please choose from the list of options."
				continue
				;;
		esac
	done
	
	# Numbering starts at 0 for minor number calculation.
	QICpos=`expr $tnum - 1`
	QICsoft=$soft
	return $OK
}

# This routine sets MINIpos, used to calculate the minor device number
# for mini tape devices.
# Global variables used and where set:
# 	$DESCR: menu routines
# Global variables set: 
#	MINIpos
ask_MINIpos() {
	minidef=$1
	driver=$2
	tnum=
	case $driver in
	mc)	lastunit=2;
		;;
	ft)	lastunit=4;
		;;
	esac
	mesg="If you have changed the unit number for the $DESCR
enter the new number [1-$lastunit] or press <Return> to use the default
value of $minidef "
	while :
	do	prompt $minidef || return $FAIL
		case $cmd in
		[1-$lastunit])	tnum=$cmd
				break
				;;
		*)		echo "
$cmd is not valid. Please choose a number between 1 and $lastunit."
				continue
				;;
		esac
	done
	# Numbering starts at 0 for minor number calculation.
	MINIpos=`expr $tnum - 1`
	return $OK
}

# Create all non-default tape devices. 
# Global variables used and where set:
# 	$SCSIpos: find_SCSIpos(); $MINIpos: find_MINIpos()
mk_nodes() {
	driver=$1
	case $driver in
	ct) 	#  Qic-02 Cartridge Tape.
		# Since ct can only be a default device, we create the
		# nodes in lnk_defaults. 
		devs=
		;;
	mc) 	#  Irwin mini tape.
		# mkdevice 	"rmc0"     0 
		# mkdevice 	"mcdaemon" 112
		# MINIpos is the unit number and is set in addmini.
		# To be consistent with other drivers, node file is not
		# put into the linkkit and the node are made here.
		  nodefile="/etc/conf/node.d/mc"
		  [ -s "$nodefile" ] && rm $nodefile
		minor=`expr 0 + $MINIpos`;	mkdevice "rmc$MINIpos" $minor
		minor=112;			mkdevice "mcdaemon" $minor
		devs="\t/dev/rmc$MINIpos\t/dev/mcdaemon"
		;;
	ft) 	#  Qic-40 mini tape.
		# mkdevice "rft0"   1
		# mkdevice "xft0" 129
		# MINIpos is the unit number and is set in addqic40.
		minor=`expr 0 + $QICpos`;   mkdevice "rft0"    $minor
		minor=`expr 128 + $QICpos`; mkdevice "xft0"    $minor
		devs="\t/dev/rft0\t/dev/xft0"
		;;
	 Stp) 	# Scsi tape driver.
		# Minor number is determined by adding base number plus
		# position of device in mscsi file; plus no-unload bit 0x04
		# and high-density bit 0x10 for 9-track reel-to-reel tapes.
		# SCSIpos is set in addscsi and Ninetrack in installmenu.
		# See top of file for device file naming conventions

		#Common to all Stp types
		minor=`expr 0	+ $SCSIpos`
		mkdevice "urStp${SCSIpos}"    $minor
		minor=`expr $NOREWIND + $NOUNLOAD + $SCSIpos`
		mkdevice "nrStp${SCSIpos}"   $minor
		minor=`expr $NOUNLOAD + $SCSIpos`
		mkdevice "nurStp${SCSIpos}"   $minor
		minor=`expr $OVERRIDE + $SCSIpos`
		mkdevice "xStp${SCSIpos}"    $minor
		devs="\
/dev/rStp${SCSIpos}\t(default)
/dev/urStp${SCSIpos}\t(rewind, unload)
/dev/nurStp${SCSIpos}\t(rewind, no unload)
/dev/nrStp${SCSIpos}\t(no rewind, no unload)
/dev/xStp${SCSIpos}\t(Control)"

		#Specific to each Stp type
		case $Stptype in
		ct)
			ln -f /dev/urStp${SCSIpos} /dev/rStp${SCSIpos}
			;;
		ex)
			ln -f /dev/nurStp${SCSIpos} /dev/rStp${SCSIpos}
			;;
		nt)	#hi density devices
			minor=`expr 0 + $SCSIpos + $HIDEN`
			mkdevice "urhStp${SCSIpos}"    $minor
			minor=`expr $NOREWIND + $NOUNLOAD + $SCSIpos + $HIDEN`
			mkdevice "nrhStp${SCSIpos}"   $minor
			minor=`expr $NOUNLOAD + $SCSIpos + $HIDEN`
			mkdevice "nurhStp${SCSIpos}"   $minor
			ln -f /dev/nurStp${SCSIpos} /dev/rStp${SCSIpos}
			ln -f /dev/nurhStp${SCSIpos} /dev/rhStp${SCSIpos}
			devs="\
$devs
/dev/rhStp${SCSIpos}\t(6250 bpi)
/dev/urhStp${SCSIpos}\t(6250 bpi)
/dev/nrhStp${SCSIpos}\t(6250 bpi)
/dev/nurhStp${SCSIpos}\t(6250 bpi)\n"
			;;
		dat)
			#partition 0 links to default
			ln -f /dev/urStp${SCSIpos} /dev/urStp${SCSIpos}.0
			ln -f /dev/nrStp${SCSIpos} /dev/nrStp${SCSIpos}.0
			ln -f /dev/nurStp${SCSIpos} /dev/nurStp${SCSIpos}.0
			ln -f /dev/xStp${SCSIpos} /dev/xStp${SCSIpos}.0
			ln -f /dev/nurStp${SCSIpos}.0 /dev/rStp${SCSIpos}.0 

			#partition 1
			minor=`expr 0	+ $SCSIpos + $PARTITION1`
			mkdevice "urStp${SCSIpos}.1"    $minor
			minor=`expr $NOREWIND + $NOUNLOAD + $SCSIpos + $PARTITION1`
			mkdevice "nrStp${SCSIpos}.1"   $minor
			minor=`expr $NOUNLOAD + $SCSIpos + $PARTITION1`
			mkdevice "nurStp${SCSIpos}.1"   $minor
			minor=`expr $OVERRIDE + $SCSIpos + $PARTITION1`
			mkdevice "xStp${SCSIpos}.1"    $minor
			ln -f /dev/nurStp${SCSIpos}.1 /dev/rStp${SCSIpos}.1 
			ln -f /dev/nurStp${SCSIpos} /dev/rStp${SCSIpos}

			devs="
Tape Partition 1	Tape Partition 2
================	================
/dev/urStp${SCSIpos}.0	\t/dev/urStp${SCSIpos}.1\t(rewind, unload)
/dev/nurStp${SCSIpos}.0	\t/dev/nurStp${SCSIpos}.1\t(rewind, no unload)
/dev/nrStp${SCSIpos}.0	\t/dev/nrStp${SCSIpos}.1\t(no rewind, no unload)
/dev/xStp${SCSIpos}.0	\t/dev/xStp${SCSIpos}.1\t(control)

For convenience the following links to traditional SCSI tape device
names have also been created:

/dev/rStp${SCSIpos}	linked to /dev/nurStp${SCSIpos}.0
/dev/rStp${SCSIpos}.0	linked to /dev/nurStp${SCSIpos}.0
/dev/rStp${SCSIpos}.1	linked to /dev/nurStp${SCSIpos}.1
/dev/urStp${SCSIpos}	linked to /dev/urStp${SCSIpos}.0
/dev/nurStp${SCSIpos}	linked to /dev/nurStp${SCSIpos}.0
/dev/nrStp${SCSIpos}	linked to /dev/nrStp${SCSIpos}.0
/dev/xStp${SCSIpos}	linked to /dev/xStp${SCSIpos}.0"
			;;
		esac
		;;
	$CPQS_DRIVER)
		mk_nodes$CPQS_DRIVER
		;;
	esac
	[ $driver != "ft" ] && clearscr
	[ -n "$devs" ] && echo "
The following special devices have been created:\n$devs"
	if [ $driver != "ft" ]; then
		echo "\nPress <Return> to Continue."
		read input
		clearscr
	fi
}

# Link a tapes nodes to the default devices. Note that this does not 
# necessarily mean that this tape is also the one listed in $DEFAULT.
# Global variables used and where set:
# 	$SCSIpos: find_SCSIpos(); $DESCR: menu routines
lnk_defaults() {
	driver=$1
	devs=
	case $driver in
	ct) 	#   Qic-02 Cartridge Tape. 
		# Qic-02 must use the default nodes. Therefore all ct nodes are
		# created here.
		rm_defaults "ct"
		[ -d /dev/rmt ] || mkdir /dev/rmt
		mkdevice rct0	   0; lnk_rmt rct0 0b; lnk_rmt rct0 c0s0r; lnk_rmt rct0 c0s0
		mkdevice nrct0     8; lnk_rmt nrct0 0bn; lnk_rmt nrct0 c0s0nr; lnk_rmt nrct0 c0s0n
		mkdevice rct2	  16; lnk_rmt rct2 0a;
		mkdevice nrct2    24; lnk_rmt nrct2 0an;
		mkdevice erct0    32; lnk_rmt erct0 0be;
		mkdevice xct0    128 
		devs="/dev/xct0
\t/dev/rct0 \tlinked to  /dev/rmt/0b\n\t/dev/nrct0 \tlinked to  /dev/rmt/0bn
\t/dev/rct0 \tlinked to  /dev/rmt/c0s0r\n\t/dev/nrct0 \tlinked to  /dev/rmt/c0s0nr
\t/dev/rct0 \tlinked to  /dev/rmt/c0s0\n\t/dev/nrct0 \tlinked to  /dev/rmt/c0s0n
\t/dev/rct2 \tlinked to  /dev/rmt/0a\n\t/dev/nrct2 \tlinked to  /dev/rmt/0an
\t/dev/erct0 \tlinked to  /dev/rmt/0be"
		;;
	mc) 	#  Irwin mini tape. 
		unit=
		if   [ -c /dev/rmc0 ]; then unit=0
		elif [ -c /dev/rmc1 ]; then unit=1
		fi
		if [ "$unit" ]; then
			rm_defaults "mc"
			ln /dev/rmc$unit  /dev/rctmini 
			ln /dev/rmc$unit  /dev/xctmini
			devs="/dev/rctmini \tlinked to /dev/rmc$unit
\t/dev/xctmini \tlinked to /dev/rmc$unit"
		fi
		;;
	ft) 	#  Qic-40 mini tape.
		if [ -c /dev/rft0 -a -c /dev/xft0 ]; then
			rm_defaults "ft"
			ln /dev/rft0  /dev/rctmini
			ln /dev/xft0  /dev/xctmini
			devs="/dev/rctmini \tlinked to /dev/rft0
\t/dev/xctmini \tlinked to /dev/xft0"
		fi
		;;
	 Stp) 	#  Scsi tape driver.
		hiden=""
		[ -c /dev/rhStp${SCSIpos} -a \
		  -c /dev/nrhStp${SCSIpos} ] && getyn "
Do you wish to use high density (6250bpi) defaults" && hiden=h
		if [ -c /dev/r${hiden}Stp${SCSIpos} -a \
		     -c /dev/nr${hiden}Stp${SCSIpos} -a \
		     -c /dev/xStp${SCSIpos} ]; then
			rm_defaults "Stp"
			[ -d /dev/rmt ] || mkdir /dev/rmt
			ln /dev/r${hiden}Stp${SCSIpos}	/dev/rct0
			ln /dev/r${hiden}Stp${SCSIpos}	/dev/rmt/0b

			ln /dev/nr${hiden}Stp${SCSIpos}	/dev/nrct0 
			ln /dev/nr${hiden}Stp${SCSIpos}	/dev/rmt/0bn

			ln /dev/xStp${SCSIpos}		/dev/xct0

			devs="/dev/xct0 \tlinked to  /dev/xStp${SCSIpos}
\t/dev/rct0 \tlinked to  /dev/r${hiden}Stp${SCSIpos}\t and /dev/rmt/0b
\t/dev/nrct0 \tlinked to  /dev/nr${hiden}Stp${SCSIpos}\t and /dev/rmt/0bn"
		fi
		;;
	$CPQS_DRIVER)
		lnk_defaults$CPQS_DRIVER
		;;
	esac
	if [ -n "$devs" ]; then
		echo "
Default special devices have been created with the following links:
\t$devs"
	else
		error "
Tape driver $DRIVER nodes do not exist or are not character special. Cannot link
to default devices."  
		return $FAIL
	fi
	return $OK
}

# Check $DEFAULT for presence of another default tape drive.
# Global variables used and where set:
# 	$DESCR: menu routines
def_driveclash() {
	pos=0
	[ -n "$MINIpos" ] && pos=$MINIpos
	[ -n "$SCSIpos" ] && pos=$SCSIpos
	# curdriver is added to $DEFAULT the first time mkdev tape runs.
	grep -s "curdriver" $DEFAULT > /dev/null && {
		grep -s "curdriver=${DRIVER}${pos}" $DEFAULT > /dev/null ||
		grep -s "curdriver=NONE" $DEFAULT > /dev/null || { 
			getyn "
Another Tape Drive is currently listed as the default in 
$DEFAULT. Do you wish to change this to the 
current $DESCR?" || return $FAIL
		}
	}
	return $OK
}
	
# Check for conflicting default devices. Return OK if no conflict. 
# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines 
def_nodeclash() {
	case $DRIVER in
	ct) 	#  Qic-02 Cartridge Tape.
		# Check for conflicts with SCSI.
		confchk "Stp" || return $OK
		echo "
The presence of a SCSI Tape Drive has been detected. The 
$DESCR must use default devices to function properly. 
Therefore, any SCSI links to default devices will be removed. 
Access to a SCSI tape can be made through the following devices: 
	/dev/rStp[0-3]	/dev/xStp[0-3]	/dev/nrStp[0-3]"

		# Check for conflicts with Compaq SCSI. 
		confchk $CPQS_DRIVER && { 
			echo "$CPQS_CLASHMES" 
			return $OK
		}
		return $OK
		;;

	ft|mc) 	#  Qic-40 mini tape or Irwin mini tape
		grep "device = /dev/xctmini" $DEFAULT > /dev/null 2>&1 && {
			getyn "
Another tape drive is currently linked to the default device /dev/xctmini. 
Do you wish to remove this link and have the $DESCR 
linked to the default devices?" || return $FAIL
		}
		return $OK
		;;

	Stp) 	#  Scsi tape driver.
		# Check for conflict with ct devices.
		confchk "ct" && { 
			echo "
The presence of a Cartridge Tape Drive has been detected. The Cartridge
Tape Drive must use the default devices to function properly. Therefore,
SCSI devices will be created without default device links."
			return $FAIL
		}

		# Check for conflict with cpqs devices.
		confchk $CPQS_DRIVER && { 
			getyn "
The presence of the $CPQS_DESCR has been detected in the kernel. 
Do you want the SCSI Tape Drive you are presently adding to be linked to
the default tape devices (ie. /dev/rct0, /dev/xct0, etc.) instead ?" ||
			return $FAIL
		}

		# Is another SCSI Drive the current default.
		grep -s "curdriver=Stp" $DEFAULT > /dev/null && {
		    grep -s "curdriver=Stp${SCSIpos}" $DEFAULT > /dev/null ||
		    getyn "
Another SCSI Tape Drive is currently linked to the default 
device /dev/xct0. Would you like the current SCSI Drive
linked to the default devices?" || return $FAIL
		}
		return $OK 
		;;
	$CPQS_DRIVER)
		def_nodeclash$CPQS_DRIVER
		return $?
		;;
	esac
}

# Add the QIC-02 driver to configuration files and make devices. 
# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines; $major: confchk() or confadd()
# Global variables set:
# 	fns, dev_major	
addqic02 () {
	# Check for the presence of the link kit. Install if it not present.
	permschk && linkchk

	confchk "$DRIVER"  && {
		getyn "
The ${DESCR}r is already present in system configuration files.
Do you wish to continue?" || return $FAIL 
	}
	# ctconfig allows user to modify interrupt and base address
	# (it edits values in /etc/conf/pack.d/ct/space.c )
	cd /etc/conf/pack.d/ct
	./ctconfig || {
		error "
The system must be configured in order to use the $DESCR.  
Exiting ...\n"
		cleanup $FAIL 
	}
	# Remove tmp file created by ctconfig.
	rm -f /tmp/ctconfig*
        fns="ctinit ctioctl ctread ctwrite ctopen ctclose"
	confadd || cleanup $FAIL
	cd /

	# Set dev_major for use in mkdevice(). 
	dev_major=$major
	# mk_nodes() is not required ct. Nodes created in lnk_defaults().
	# Presently, def_nodeclash will always return true for ct since
	# it must use default devices. 
	def_nodeclash && {
		# Link driver to default devices.
		lnk_defaults "$DRIVER"
		def_driveclash && {
			# edit /etc/default/tape.
			edit_def "$DRIVER"
		}
	}
	return $OK
}

# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines; $major: confchk() or confadd() 
# 	$SCSIpos: find_SCSIpos()
# Global variables set:
# 	dev_major, change
addscsi () {
	# Check for the presence of the link kit. Install if it not present.
	permschk && linkchk

	# Configure the driver if necassary.
	confchk "$DRIVER"  || {
		# Add scsi driver to config files.
		confadd || cleanup $FAIL
	}
	find_SCSIpos ; oSCSIpos=$SCSIpos
	[ $oSCSIpos -ge 3 ] && {
		echo "
Sorry, the maximum of four SCSI Tape Drives has been reached. Unable to
configure another one."
		return $FAIL
	}
	getyn "The $DESCR must be configured before use. 
Do you wish to configure the $DESCR now?" || {
		echo "
The $DESCR has been added to system configuration files.
However, /etc/conf/cf.d/mscsi must also be updated before using
a $DESCR. It is advisable to reinvoke mkdev tape to 
accomplish this."
		return $FAIL
	}

	# Edit /etc/conf/cf.d/mscsi
	/bin/sh /usr/lib/mkdev/.scsi -a -t -n || return $FAIL

	while :
	do 	find_SCSIpos ; nSCSIpos=$SCSIpos
	 	differ=`expr $nSCSIpos - $oSCSIpos`
	 	case $differ in
	 	0) 	
			getyn "
The number of SCSI Tape Drives has not been changed.
Do you wish to try again?" || return $FAIL
			;;
		[1-4]) 	break
			;;
		[5-9]) 	echo "
A maximum of four SCSI Tape Drives are allowed. Please reconfigure."
			;;
		*) 	error "$differ not valid."
			return $FAIL
			;;
		esac
		echo "
Invoking the interface to the master SCSI device file."
		/bin/sh /usr/lib/mkdev/.scsi || return $FAIL
	done
	change=YES

	# Set dev_major for use in mkdevice(). 
	dev_major=$major

	SCSIpos=$oSCSIpos
	while [ $SCSIpos -lt $nSCSIpos ]
	do
		SCSIpos=`expr $SCSIpos + 1`
		# Create pure scsi devices.
		mk_nodes "$DRIVER"
	done
	def_nodeclash && {
		# Link driver to default devices.
		lnk_defaults "$DRIVER"
		def_driveclash && {
			# edit /etc/default/tape.
			edit_def "$DRIVER"
		}
	}
	return $OK
}

# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines;  $major: confchk() or confadd()
#	$MINIpos: ask_MINIpos()
# Global variables set:
# 	fns, dev_major
addqic40 () {
	# Check for the presence of the link kit. Install if it not present.
	permschk && linkchk

	confchk "$DRIVER" && {
		getyn "
The ${DESCR}r is already present in system
configuration files. Do you wish to continue?" || return $FAIL 
	}
	qic40_query || return $FAIL
	# Set the unit number QICpos ("2" is the default) and QICsoft.
	ask_QICpos "2" || return $FAIL
	if [ $QICsoft -eq 0 ] 
	then
		sed -e "s/FT_SOFT_SELECT;/FT_HARD_SELECT;/" /etc/conf/pack.d/ft/space.c > /tmp/space$$
	else
		sed -e "s/FT_HARD_SELECT;/FT_SOFT_SELECT;/" /etc/conf/pack.d/ft/space.c > /tmp/space$$
	fi
	cp /etc/conf/pack.d/ft/space.c /etc/conf/pack.d/ft/space.c.bak
	mv /tmp/space$$ /etc/conf/pack.d/ft/space.c

	fns="ftinit ftioctl ftread ftwrite ftopen ftclose ftpoll"
	# Add to configuration files.
	confadd || cleanup $FAIL

	# Set dev_major for use in mkdevice(). major was set in confchk().
	dev_major=$major
	# Create QIC-40/QIC-80 devices.
	mk_nodes "$DRIVER"
	def_nodeclash && {
		# Link driver to default devices.
		lnk_defaults "$DRIVER"
		def_driveclash && {
			# edit /etc/default/tape.
			edit_def "$DRIVER"
		}
	}
	return $OK
}

# add irwin minitape driver
# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines; $major: confchk() or confadd()
#	$MINIpos: ask_MINIpos()
# Global variables set:
# 	fns, dev_major	
addmini () {
	# Check for the presence of the link kit. Install if it not present.
	permschk && linkchk

	confchk "$DRIVER" && {
		getyn "
The ${DESCR}r is already present in system configuration files.
Do you wish to continue?" ||  return $FAIL
	}
	# Set the unit number MINIpos. "1" is the default.
	ask_MINIpos "1" "$DRIVER" || return $FAIL

	fns="mcinit mcioctl mcread mcwrite mcopen mcclose mcpoll"
	# Add to configuration files.
	confadd || cleanup $FAIL

	# Set dev_major for use in mkdevice(). major was set in confchk().
	dev_major=$major
	# Create pure irwin devices.
	mk_nodes "$DRIVER"
	def_nodeclash && {
		# Link driver to default devices.
		lnk_defaults "$DRIVER"
		def_driveclash && {
			# edit /etc/default/tape.
			edit_def "$DRIVER"
		}
	}
	# Install rc script
	cp /etc/conf/pack.d/mc/rc /etc/conf/rc.d/mc
	return $OK
}	

# ------- Remove Drivers -------- 	These routines remove tape drivers from 
#					configuration files and delete 
#					appropriate devices.

# Global variables set:
# 	SCSIpos	
askSCSI_def() {
	clearscr
	echo "\nThe SCSI configuration file currently has entries for the\
 following Tape Drives:\n"
	echo "\tDrive\tAdapter\tAdapter\n\tNumber\tType\tNumber\tID\tLUN"
	echo "\t-----------------------------------"
	tnum=1
	grep -v "*" /etc/conf/cf.d/mscsi | \
	while read ha Sdev hanum id lun
	do
		case $Sdev in
		Stp)	echo "\t$tnum\t$ha\t$hanum\t$id\t$lun"
			tnum=`expr $tnum + 1`
			;;
		esac
	done
	while mesg="
Please enter the Drive Number of the SCSI Tape you would like to 
become the new default "
	do prompt || return $FAIL
		case $cmd in
		[1-4])	tnum=`expr $cmd - 1`
			if [ -c /dev/xStp${tnum} ]; then
				SCSIpos=$tnum
				break
			else
				echo "
Error: There are no corresponding special devices for the SCSI device chosen."
			continue
			fi		;;
		*) 	echo "
$cmd not valid. Please enter a number between 1-4." 	;;
		esac
	done
	return $OK
}

# Global variables used and where set:
# 	$DRIVER: menu routines
# 	$SCSIpos: askSCSI_def() or find_SCSIpos()
is_default() {
	case $DRIVER in
	ct) 	#  Qic-02 Cartridge Tape.
		grep "curdriver=ct" $DEFAULT > /dev/null 2>&1 && return $OK
		;;

	ft) 	#  Qic-40 mini tape.
		grep "curdriver=ft" $DEFAULT > /dev/null 2>&1 && return $OK
		;;

	mc) 	#  Irwin mini tape.
		grep "curdriver=mc" $DEFAULT > /dev/null 2>&1 && return $OK
		;;

	Stp) 	#  Scsi tape driver.
		tag="curdriver=Stp${SCSIpos}"
		grep "$tag" $DEFAULT > /dev/null 2>&1 && return $OK
		;;
	$CPQS_DRIVER)
		is_default$CPQS_DRIVER
		return $?
		;;
	esac
	return $FAIL
}

# Remove all non-default tape devices. 
# Global variables used and where set:
# 	$SCSIpos: askSCSI_def() 
rm_nodes() {
	driver=$1
	case $driver in
	ct) 	# Qic-02 Cartridge Tape.
		# Since ct always was the default device, we remove the
		# nodes in lnk_defaults
		;;
	mc) 	# Irwin mini tape.
		rm -rf /dev/rmc0 /dev/rmc1 /dev/mcdaemon
		;;
	ft) 	# Qic-40 mini tape.
		rm -rf /dev/rft0  /dev/xft0
		;;
	Stp) 	# Scsi tape driver.
		rm -rf 	/dev/rStp${SCSIpos}  /dev/nrStp${SCSIpos}  \
		 	/dev/urStp${SCSIpos}  /dev/nurStp${SCSIpos}  \
			/dev/rhStp${SCSIpos} /dev/nrhStp${SCSIpos} \
			/dev/urhStp${SCSIpos} /dev/nurhStp${SCSIpos} \
		 	/dev/rStp${SCSIpos}.[01]  /dev/nrStp${SCSIpos}.[01]  \
		 	/dev/urStp${SCSIpos}.[01]  /dev/nurStp${SCSIpos}.[01]  \
			/dev/xStp${SCSIpos}.[01] /dev/xStp${SCSIpos}
		;;
	$CPQS_DRIVER)
		rm_nodes$CPQS_DRIVER
		;;
	esac
}

# Remove default tape devices. 
rm_defaults() {
	case $1 in
	mc) 	# Irwin mini tape.
	 	rm -rf /dev/rctmini  /dev/xctmini
		;;
	ft) 	# Qic-40 mini tape.
	 	rm -rf /dev/rctmini  /dev/xctmini
		;;
	*)	rm -rf /dev/rct0   	/dev/rmt/0b
		rm -rf /dev/nrct0 	/dev/rmt/0bn
		rm -rf /dev/rct2	/dev/rmt/0a
		rm -rf /dev/nrct2	/dev/rmt/0an
		rm -rf /dev/erct0	/dev/rmt/0be
		rm -rf /dev/xct0    
		[ -c /dev/rmt/c0s0 ] && rm -rf /dev/rmt/c0s0
		[ -c /dev/rmt/c0s0n ] && rm -rf /dev/rmt/c0s0n
		[ -c /dev/rmt/c0s0r ] && rm -rf /dev/rmt/c0s0r
		[ -c /dev/rmt/c0s0nr ] && rm -rf /dev/rmt/c0s0nr
		;;
	esac
	rmdir /dev/rmt 2>/dev/null
	return $OK
}

# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines
rmqic02 () {
	# Check for the presence of the link kit. Install if it not present.
	permschk && linkchk
	confchk "$DRIVER" || {
		echo "
The ${DESCR}r is not currently configured.\n"
		return $FAIL
	}
	confrm || cleanup $FAIL
	rm_nodes "$DRIVER"
	is_default && {
		echo "\nRemoving default tape devices."
		rm_defaults "$DRIVER"
		edit_def "NONE"
	} 
	echo "\n${DESCR}r and associated devices have been removed."
	return $OK
}
	
# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines
rmmini () {
	# Check for the presence of the link kit. Install if it not present.
	permschk && linkchk
	confchk "$DRIVER" || {
		echo "
The ${DESCR}r is not currently configured.\n"
		return $FAIL
	}
	confrm || cleanup $FAIL
	rm_nodes "$DRIVER"
	is_default && {
		echo "\nRemoving default tape devices."
		rm_defaults "$DRIVER"
		edit_def "NONE"
	} 
	echo "\n${DESCR}r and associated devices have been removed."
	rm -f /etc/conf/rc.d/$DRIVER
	return $OK
}

# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines
rmqic40 () {
	# Check for the presence of the link kit. Install if it not present.
	permschk && linkchk
	confchk "$DRIVER" || {
		echo "
The ${DESCR}r is not currently configured.\n"
		return $FAIL
	}
	confrm || cleanup $FAIL
	rm_nodes "$DRIVER"
	is_default && {
		echo "\nRemoving default tape devices."
		rm_defaults "$DRIVER"
		edit_def "NONE"
	} 
	echo "\n${DESCR}r and associated devices have been removed."
	return $OK
}

# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines; 
# 	$SCSIpos: find_SCSIpos() 
rmscsi() {
	confchk "$DRIVER" || {
		echo "
The ${DESCR}r is not currently configured.\n"
		return $FAIL
	}
	find_SCSIpos ; oSCSIpos=$SCSIpos
	if [ $oSCSIpos -lt 0 ] 
	then
		getyn "
There are currently no SCSI Tape Drives configured in the /etc/conf/cf.d/mscsi
file. Do you wish to continue."	|| return $FAIL
		# Pretend we have 4 so we can remove any nodes created and
		# remove scsi driver from kernel.
		oSCSIpos=3
	else
		# Edit /etc/conf/cf.d/mscsi
		/bin/sh /usr/lib/mkdev/.scsi -r -t -n || return $FAIL
	fi
	find_SCSIpos ; nSCSIpos=$SCSIpos
	differ=`expr $oSCSIpos - $nSCSIpos`
	case $differ in
 	0) 	
		echo "
The number of SCSI Tape Drives has not been changed."
		return $FAIL
		;;
	[1-4]) 	:	# OK
		;;
	*) 	error "$differ not valid."
			return $FAIL
		;;
	esac
	change=YES

	SCSIpos=$oSCSIpos
	while [ $SCSIpos -gt $nSCSIpos ]
	do
		rm_nodes "$DRIVER"
		is_default && { 
			echo "\nRemoving default tape devices."
			rm_defaults "$DRIVER"
			edit_def "NONE"
		} 
		SCSIpos=`expr $SCSIpos - 1`
	done

	[ $SCSIpos -eq -1 ] && { 
		permschk && linkchk
		confrm || cleanup $FAIL
	}
	echo "
The $DESCR specified and associated devices have been removed."
	return $OK
}

# ----- Change Default Tape ------	These routines implement a change
#					in the default tape drive.

#  Qic-02 Cartridge Tape.
# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines; 
changeqic02()  {
	confchk "$DRIVER" || {
		echo "\nThe ${DESCR}r is not currently installed."
		return $FAIL
	}
	# QIC-02 is always linked to the default devices. Just edit $DEFAULT
	edit_def "$DRIVER"
	return $OK
}

#  Irwin mini tape.
# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines; 
changemini()  {
	confchk "$DRIVER" || {
		echo "\nThe ${DESCR}r is not currently installed."
		return $FAIL
	}
	lnk_defaults "$DRIVER"
	edit_def "$DRIVER"
	return $OK
}

#  Qic-40 mini tape.
# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines; 
changeqic40()  {
	confchk "$DRIVER" || {
		echo "\nThe ${DESCR}r is not currently installed."
		return $FAIL
	}
	lnk_defaults "$DRIVER"
	edit_def "$DRIVER"
	return $OK
}

# Global variables used and where set:
# 	$DRIVER, $DESCR: menu routines; 
# 	$SCSIpos: find_SCSIpos() or askSCSI_def
changescsi()  {
	confchk "$DRIVER" || {
		echo "\nThe ${DESCR}r is not currently installed."
		return $FAIL
	}
	# If ct exists, we want to let it keep it's default status.
	confchk "ct" && {
		echo "
The presence of the Cartridge Tape Driver has been detected. The 
Cartridge Tape Drive must use the default devices to function 
properly. Therefore, to use a SCSI Drive as the default, you 
must first remove the Cartridge Tape."
		return $FAIL
	}
	# This will return the number of SCSI tape drives.
	find_SCSIpos 
	if [ $SCSIpos -gt 0 ]; then 
		# This routine will reset SCSIpos to the one they want.
		askSCSI_def || return $OK
		lnk_defaults "$DRIVER"
	else
		lnk_defaults "$DRIVER"
	fi
	edit_def "$DRIVER"
	return $OK
}

# Function "changebootstr()"
# Modify /etc/default/boot's "${DRIVER}=" string, because when the
# tape drive is changed, or a tape drive is added or removed,
# the tape device boot string may be changed.
# Give the user an opportunity (prompt for it).

changebootstr() {
	# What is the boot string currently?
	bootstr=`sed -n '/DEFBOOTSTR=/s/.* '${DRIVER}'=\([^(]*([^,]*,[^,]*,[^)]*)\).*/\1/p' /etc/default/boot`
	if [ "x$bootstr" = "x" ] ; then
		echo "\nIn /etc/default/boot:\nNo current boot string."
	else
		echo "\nIn /etc/default/boot:\nCurrent boot string is \"$bootstr\"."
	fi

	mesg="Enter new string, \"rm\" to remove string,\n"
	quit="leave current string as is"

	prompt || return	# leave it.

	if [ "x$bootstr" = "x" -a "$cmd" != "rm" ] ; then
		sed /DEFBOOTSTR=/s/\$/\ ${DRIVER}=$cmd/ /etc/default/boot > /tmp/boot$$
	elif [ "$cmd" = "rm" ] ; then
		sed "s/ ${DRIVER}=$bootstr//g" /etc/default/boot > /tmp/boot$$
	else
		sed "s/ ${DRIVER}=$bootstr/ ${DRIVER}=$cmd/g" /etc/default/boot > /tmp/boot$$
	fi

	# Back up boot and move the modified version onto it.
	cp /etc/default/boot /etc/default/boot.bak
	mv /tmp/boot$$ /etc/default/boot

	return $OK
}

# -------  MENU ROUTINES  ------- 	These routines present a menu,
#					prompt the user, set global variables
#					and execute appropriate routines.

#install menu for SCSI type tapes
installsmenu () {
quit="return to the main menu"
mesg="
SCSI Tape Drive Installation Menu

	1. Install SCSI Cartridge Tape Drive
	2. Install SCSI Exabyte Tape Drive
	3. Install SCSI 9-Track Tape Drive
	4. Install SCSI DAT Drive
	5. Install $CPQS_DESCR

	Select an option "

	while :
	do prompt || return
		itape=$cmd
		case $itape in
		1) 	DESCR="SCSI Cartridge Tape Drive"	DRIVER=Stp
			Stptype=ct
	   		addscsi	|| return				
			changebootstr
			;;
		2) 	DESCR="SCSI Exabyte Tape Drive"		DRIVER=Stp
			Stptype=ex
	   		addscsi	|| return				
			changebootstr
			;;
		3)	DESCR="SCSI 9-Track Tape Drive"		DRIVER=Stp
			Stptype=nt
			addscsi || return
			changebootstr
			;;
		4) 	DESCR="SCSI DAT Drive" 			DRIVER=Stp
			Stptype=dat
	   		addscsi	|| return				
			changebootstr
			;;
		5) 	DESCR=$CPQS_DESCR 		DRIVER=$CPQS_DRIVER
	   		add$CPQS_DRIVER || return				
			changebootstr
			;;
		*) error "Please enter 1,2,3,4,5 or q to quit"	
	   	continue				;;
		esac
		break
	done
}

# find out what they want to install
installmenu () {
quit="return to the main menu"
mesg="
Tape Drive Installation Menu

	1. Install Cartridge Tape Drive
	2. Install Mini-Cartridge Tape Drive
	3. Install Qic-40 or Qic-80 Tape Drive
	4. Install SCSI Tape Drive

	Select an option "

	while :
	do prompt || return
		itape=$cmd
		case $itape in
		1) 	DESCR="Cartridge Tape Drive" 		DRIVER=ct
	   		addqic02 || return		
			changebootstr
			;;
		2) 	DESCR="Mini-Cartridge Tape Drive" 	DRIVER=mc
	   		addmini || return 				
			changebootstr
			;;
		3) 	DESCR="Qic-40 or Qic-80 Tape Drive" 	DRIVER=ft
	   		addqic40 || return				
			changebootstr
			;;
		4)	installsmenu
			;;
		*) error "Please enter 1,2,3,4, or q to quit"	
	   	continue				;;
		esac
		break
	done
}

# remove menu for SCSI type tapes
removesmenu () {
	quit="return to the main menu"
	mesg="
SCSI Tape Drive Removal Menu

	1. Remove SCSI Tape Drive (Cartridge, Exabyte, 9-Track, DAT)
	2. Remove $CPQS_DESCR

	Select an option "

	while :
	do prompt || return
		rtape=$cmd
		case $rtape in
		1) 	DESCR="SCSI Tape Drive" 		DRIVER=Stp
	   		rmscsi	|| return
			changebootstr
			;;
		2) 	DESCR=$CPQS_DESCR 		DRIVER=$CPQS_DRIVER
	   		rm$CPQS_DRIVER	|| return				
			changebootstr
			;;
		*) error "Please enter 1,2, or q to quit"	
	   	continue				;;
		esac
		break
	done
}

# find out what they want to remove
removemenu () {
	quit="return to the main menu"
	mesg="
Tape Drive Removal Menu

	1. Remove Cartridge Tape Drive
	2. Remove Mini-Cartridge Tape Drive
	3. Remove Qic-40 or Qic-80 Tape Drive
	4. Remove SCSI Tape Drive

	Select an option "

	while :
	do prompt || return
		rtape=$cmd
		case $rtape in
		1) 	DESCR="Cartridge Tape Drive" 		DRIVER=ct
	   		rmqic02 || return		
			changebootstr
			;;
		2) 	DESCR="Mini-Cartridge Tape Drive" 	DRIVER=mc
	   		rmmini || return 				
			changebootstr
			;;
		3) 	DESCR="Qic-40 or Qic-80 Tape Drive" 	DRIVER=ft
	   		rmqic40 || return				
			changebootstr
			;;
		4) 	removesmenu	
			;;
		*) error "Please enter 1,2,3,4,5, or q to quit"	
	   	continue				;;
		esac
		break
	done
}

#change menu for SCSI type tapes
changesmenu () {
	quit="return to the main menu"
	mesg="
Default SCSI Tape Drive Update Menu

	1. SCSI Tape Drive (Cartridge, Exabyte, 9-Track, DAT)
	2. $CPQS_DESCR

	Please select which tape drive you would like to have linked to 
	default devices "

	while :
	do prompt || return
		ctape=$cmd
		case $ctape in
		1) 	DESCR="SCSI Tape Drive" 		DRIVER=Stp
	   		changescsi	|| return
			changebootstr
			;;
		2) 	DESCR=$CPQS_DESCR		DRIVER=$CPQS_DRIVER
	   		change$CPQS_DRIVER	|| return
			changebootstr
			;;
		*) error "Please enter 1,2, or q to quit"	
	   	continue				;;
		esac
		break
	done
}

changemenu() {
	quit="return to the main menu"
	mesg="
Default Tape Drive Update Menu

	1. Cartridge Tape Drive
	2. Mini-Cartridge Tape Drive
	3. Qic-40 or Qic-80 Tape Drive
	4. SCSI Tape Drive

	Please select which tape drive you would like to have linked to 
	default devices "

	while :
	do prompt || return
		ctape=$cmd
		case $ctape in
		1) 	DESCR="Cartridge Tape Drive" 		DRIVER=ct
	   		changeqic02 	|| return
			changebootstr
			;;
		2) 	DESCR="Mini-Cartridge Tape Drive" 	DRIVER=mc
	   		changemini 	|| return
			changebootstr
			;;
		3) 	DESCR="Qic-40 or Qic-80 Tape Drive" 	DRIVER=ft
	   		changeqic40 	|| return
			changebootstr
			;;
		4) 	changesmenu
			;;	
		*) error "Please enter 1,2,3,4,5, or q to quit"	
	   	continue				;;
		esac
		break
	done
}

#
# lnk_rmt()
# 
# link the default device to an rmt node
# useage : lnk_rmt device rmt_device
#
lnk_rmt()
{
	driver=$1 # default device
	rmt=$2    # rmt device
	ln /dev/$driver /dev/rmt/$rmt
}	

# main()
#########################

set_trap

#pick-up compaq functionality
if [ -f $CPQS_SCRIPT ] 
then
	. $CPQS_SCRIPT
else
	CPQS_DESCR="Compaq SCSI Tape Drive"
	CPQS_DRIVER=cpqs
fi

cd /
clearscr
while mesg="\n\nTape Drive Configuration Program \n
	1. Install a Tape Drive
	2. Remove a Tape Drive
	3. Change default Tape Drive 

	Select an option "
	quit="quit"
do prompt || break
# reset these flags prior to each pass through menu
major=
IPL=
IV=
select=$cmd
case $select in
	1) installmenu		;;
	2) removemenu		;;
	3) changemenu		;;
	*) echo "\n	Please select either 1, 2 or 3"
	   continue		;;
esac
done

if [ "$change" = "YES" ] 
then

	if [ "$_RELINK" -o "$_NOPROMPT" ]
	then
		klink
	else
		asklink && klink  
	fi
fi

cleanup $OK
