#!/bin/sh
# $Header: vmconf.sh,v 1.16 98/02/11 14:15:01 rjp Stab $
#bcpyrght
#***************************************************************************
#* Copyright 1993 - 1998 VERITAS Software Corporation, All Rights Reserved *
#***************************************************************************
#ecpyrght
#
#
# vmconf.sh -- a quickie way to avoid MKDEV, tpconfig/xdevadm, & vmadm/xvmadm
#
#   NOTE:  main portion of this script is at the end of this file
#

VMADD=/usr/openv/volmgr/bin/vmadd
VMDELETE=/usr/openv/volmgr/bin/vmdelete
VMQUERY=/usr/openv/volmgr/bin/vmquery
VMPS=/usr/openv/volmgr/bin/vmps
VMSGSCAN=/usr/openv/volmgr/bin/sgscan
VMADM_XVMADM="/usr/openv/volmgr/bin/xvmadm or vmadm"
TPCONFIG_XDEVADM="/usr/openv/volmgr/bin/xdevadm or tpconfig"
EXTERNAL_ROBOTICS_FILE=/usr/openv/volmgr/database/external_robotics

##
# GENERAL script functions
##

# -----------------------------------------------------------------------------
# Confirm an action with yes as the default
#
#	confirm prompt_string
#	Returns 0 for yes and 1 for no.


confirm ()
{
	Valid=2
	while [ $Valid = 2 ]
	do
		$ECHO "\n$1 (y/n)  [y]\c "
		read ans
		: ${ans:=y}
		case $ans in
			Y*|y*)	Valid=0 ;;
			N*|n*)	Valid=1 ;;
			*)	$ECHO "You have entered an invalid option." ;;
		esac
	done
	$ECHO
	return $Valid
}
# -----------------------------------------------------------------------------
# Confirm an action with a no for default
#
#	confirm_no prompt_string
#	Returns 0 for yes and 1 for no.

confirm_no ()
{
	Valid=2
	while [ $Valid = 2 ]
	do
		$ECHO "\n$1 (y/n)  [n]\c "
		read ans
		: ${ans:=n}
		case $ans in
			Y*|y*)	Valid=0 ;;
			N*|n*)	Valid=1 ;;
			*)	$ECHO "You have entered an invalid option." ;;
		esac
	done
	$ECHO
	return $Valid
}
# -----------------------------------------------------------------------------
askifquit ()
{
	$ECHO "\t -- enter <RETURN> to continue, \"e\" to exit.\c "
	read Quit
	if [ "$Quit"xit = "exit" -o "$Quit"xit = "Exit" ] ; then
		exit 0
	fi
}
# -----------------------------------------------------------------------------
clean_and_exit()
{
	if [ "$HOSTTYPE" = "solaris" ] ; then
		rm -f $sgscan_out_file $sgscan_err_file
	fi
	exit $1
}
# -----------------------------------------------------------------------------
re_run ()
{
	$ECHO "Please address the reported errors and re-run this script."
	clean_and_exit $1
}
# -----------------------------------------------------------------------------
re_run_failure ()
{
	$ECHO "
$1 failed with status $2
Use vmadm or xvmadm to complete the configuration."
	clean_and_exit 1
}
# -----------------------------------------------------------------------------
re_run_tpconfig ()
{
	if [ $# = 2 ] ; then
		$ECHO "
$TPCONFIG failed adding $1 with status $2."
	else
		$ECHO "
$TPCONFIG failed getting first $1 number."
	fi
	$ECHO "
Use xdevadm or tpconfig to complete the configuration"
	clean_and_exit 1
}
# -----------------------------------------------------------------------------
re_run_slot ()
{

	$ECHO "The number of retries has been exhausted.

Please correct the configuration if the expected device
was not displayed in the list of devices, then re-run
this script.  Otherwise, re-run and provide a valid slot.
"
	rm -f $spscan_out_file
	exit 1
}
# -----------------------------------------------------------------------------
#
#	get_hex_digits_no_range prompt_string
#
#	Entered value is returned in the VALUE variable (as lower case hex digits)

get_hex_digits_no_range()
{
        $ECHO "\n$1 \c"
        valid=0
        until [ $valid != 0 ]
        do
                read dummy
		numchars=`$ECHO $dummy | awk '{ print length($1) }'` 
		if [ $numchars -eq "0" ]
		then
			$ECHO "No input received, try again: \c"
			break
		fi
		charvalid=1
		while [ $numchars -gt "0" -a $charvalid = 1 ] ; do
			charvalid=0
			thechar=`$ECHO $dummy | cut "-c$numchars" | tr '[A-Z]' '[a-z]' `
			if valid_hex $thechar
			then
				charvalid=1
			else
				$ECHO "Must be hexadecimal digits (each in the range 0 - f), try again: \c"
			fi
			numchars=`expr $numchars - 1`
		done

		if [ $charvalid = 1 ]
		then
			VALUE=`$ECHO $dummy | tr '[A-Z]' '[a-z]' `
			valid=1
		fi
        done
        $ECHO
}
# -----------------------------------------------------------------------------
# Get a numeric value from the user.
#
#	get_number prompt_string low_value high_value
#
#	Entered value is returned in the VALUE variable

get_number()
{
	$ECHO "\n$1 [$2-$3] \c"
	valid=0
	until [ $valid != 0 ]
	do
		read VALUE
		VALUE=${VALUE:=-9999}
		expr $VALUE + 1  > /dev/null 2>/dev/null
		if [ $? -ne 0 ] ; then
			$ECHO "Must be an integer in the range $2 - $3, try again: \c"
		elif [ $VALUE -ge $2 -a $VALUE -le $3 ] ; then
			valid=1
		else
			$ECHO "Must be an integer in the range $2 - $3, try again: \c"
		fi
	done
	$ECHO
}

# -----------------------------------------------------------------------------
# Get a numeric value from the user.
#
#	get_number_no_range prompt_string
#
#	Entered value is returned in the VALUE variable

get_number_no_range ()
{
	$ECHO "\n$1 \c"
	valid=0
	until [ $valid != 0 ]
	do
		read VALUE
		VALUE=${VALUE:=-9999}
		expr $VALUE + 1  > /dev/null 2>/dev/null
		if [ $? -ne 0 ] ; then
			$ECHO "Must be a non-negative integer, try again: \c"
		elif [ $VALUE -ge 0 ] ; then
			valid=1
		else
			$ECHO "Must be a non-negative integer, try again: \c"
		fi
	done
	$ECHO
}
# -----------------------------------------------------------------------------
# Get a alphabetic value from the user.
#
#	get_letter prompt_string low_value high_value
#
#	Entered value is returned in the VALUE variable

get_letter()
{
	$ECHO "\n$1 [$2-$3] \c"
	valid=0
	until [ $valid != 0 ]
	do
		read dummy
		VALUE=`echo $dummy | cut -c1-1 | tr '[a-z]' '[A-Z]' `
		if valid_face $VALUE
		then
			valid=1
		else
			$ECHO "Must be in the range $2 - $3, try again: \c"
		fi
	done
	$ECHO
}

##
# PRINT functions
##

# -----------------------------------------------------------------------------
gen_assumptions_for_make_devs()
{
	$ECHO  "
This script makes the following assumptions when creating device
files and configuration entries for the robotic devices:
   -all drives and robotic control are attached using SCSI
   -all drives robotic control are on the same SCSI bus/adapter
   -all drives will be added to the configuration as UP (available) drives
   -the TL4/TC4 drive(s) are HP DAT drives, optionally with compression
   -the TS8 or TL8 drive(s) are either Exabyte 8500, 8500C, 8505 or 8900 drives
   -the TL8 contains 1-6 drives
   -the ODL contains 1-6 drives
   -the TL4 contains 1-2 drives
   -the TS8 contains 1-2 drives
   -the TLD contains 1-10 drives
   -the TSD contains 1 drive
   -the TSH contains 1 drive
   -the TC8 and TC4 contain two drives (A and B)
   -all drives in the robot are of the same drive type except for TLD,
	which asks what Media Manager drive type should be used.  This
	allows TLD robots with mixed drive types to be configured.
"
}
# -----------------------------------------------------------------------------
print_intro()
{
$ECHO "

This script is intended to be used as a convenient method to complete
the following Media Manager configuration tasks:
    --  make the device file (/dev) entries, if necessary
    --  add the robotic peripheral to the configuration
    --  add the drives in the robotic peripheral to the device configuration
    --  ensure the correct /etc/services entries exist
    --  initiate the appropriate Media Manager daemon processes

This script is not intended to be used for complex configurations where
multiple hosts or multiple SCSI bus/adapter connections are involved.
Robotic configurations assume that all drives within a robot are connected to
the same host and SCSI bus/adapter.  This script assumes the Media Manager
volume database will be on the same host as the drives.

-Any complex configurations or modifications to existing configurations
 should be done using the appropriate utility (tpconfig/xdevadm, vmadm/xvmadm)"
if [ $HARDWARE = SUN4 ] ; then
	$ECHO "-On Sun servers running SunOS 4.1.3, it is assumed that the running kernel
 matches the name found in /etc/motd."
fi
$ECHO "-This script should be run only once for each robot.
"
askifquit
}
# -----------------------------------------------------------------------------
use_tpconfig()
{
	$ECHO "
Use ${TPCONFIG_XDEVADM} to add
robot(s) & drive(s) to the device configuration.
"
}

# -----------------------------------------------------------------------------
use_vmadm()
{
	$ECHO "
Use ${VMADM_XVMADM} to add
media to the volume configuration.
"
}

# -----------------------------------------------------------------------------
get_4mm_drive_type ()
{
	$ECHO "



	4mm(DAT) Drive Types
	--------------------
	1.  HP DAT (4mm)
	2.  HP DAT (4mm) with compression"
	get_number "\tEnter Choice for the $1" 1 2
	case $VALUE in
		1) DRIVETYPE=4mm ;;
		2) DRIVETYPE=4mm_compress ;;
	esac
}
# -----------------------------------------------------------------------------
get_exabyte_drive_type ()
{
	$ECHO "



	Exabyte Drive Types
	-------------------
	1.  Exabyte 8200 (2.3 GB)
	2.  Exabyte 8500 (5 GB)
	3.  Exabyte 8505, 8500c or 8900 (compression)"
	get_number "\tEnter Choice for the $1" 1 3
	case $VALUE in
		1) DRIVETYPE=8200 ;;
		2) DRIVETYPE=8500 ;;
		3) DRIVETYPE=8505 ;;
	esac
}
# -----------------------------------------------------------------------------
get_robot_type ()
{

	robot_out_file=/tmp/vmconf.robots.$$

	# for now, no vmconf support for ACS, TLH, and TLM robot types
	egrep -v "^#|ACS|TLH|TLM" $EXTERNAL_ROBOTICS_FILE | awk 'BEGIN { FS="\"" } { print $2 }' > $robot_out_file

	robot_count=`cat $robot_out_file | wc -l`
	if [ "$robot_count" -eq "0" ]
	then
		$ECHO "Cannot obtain peripheral types from $EXTERNAL_ROBOTICS_FILE"
		rm -f $robot_out_file
		exit 1
	fi

	$ECHO ""
	$ECHO "\tPeripheral Types"
	$ECHO "\t----------------"

	cat $robot_out_file | awk 'BEGIN { i=1 } { if (i<10) print "\t " i ".  " $0 ; else print "\t" i ".  " $0 ; i++ }'

	help_index=`expr $robot_count + 1`
	if [ "$help_index" -lt "10" ]
	then
		$ECHO "\t $help_index.  Tutorial/Help"
	else
		$ECHO "\t$help_index.  Tutorial/Help"
	fi
	exit_index=`expr $help_index + 1`
	if [ "$exit_index" -lt "10" ]
	then
		$ECHO "\n\t $exit_index.  Exit"
	else
		$ECHO "\n\t$exit_index.  Exit"
	fi

	get_number "\tEnter Choice" 1 $exit_index

	if [ "$VALUE" -le "$robot_count" ] ; then
		robotype=`cat $robot_out_file | sed -n "$VALUE p" | awk '{ print $1 }'`
	elif [ "$VALUE" -eq "$help_index" ] ; then
		robotype="HELP_CHOSEN"
	elif [ "$VALUE" -eq "$exit_index" ] ; then
		robotype="EXIT_CHOSEN"
	else
		robotype="UNKNOWN"
	fi

	rm -f $robot_out_file
	
	GOODCHOICE=""
	case $robotype in
		NONE)	ROBTYPE="Standalone Drive"
			get_NON_ROBOTIC
			;;
		ODL)	ROBTYPE=ODL
			if [ "$HOSTTYPE" = ALPHA ] ; then
				GOODCHOICE=O
			elif [ $AUSPEX_SP -eq 1 ] ; then
				GOODCHOICE=A
			fi
			;;
		TC8)	ROBTYPE=TC8
			if [ $AUSPEX_SP -eq 1 ] ; then
				GOODCHOICE=A
			fi
			;;
		TL4)	ROBTYPE=TL4
			if [ $AUSPEX_SP -eq 1 ] ; then
				GOODCHOICE=A
			fi
			;;
		TL8)	ROBTYPE=TL8
			if [ $AUSPEX_SP -eq 1 ] ; then
				GOODCHOICE=A
			fi
			;;
		TS8)	ROBTYPE=TS8
			if [ $AUSPEX_SP -eq 1 ] ; then
				GOODCHOICE=A
			fi
			;;
		TLD)	ROBTYPE=TLD
			;;
		TC4)	ROBTYPE=TC4
			if [ $AUSPEX_SP -eq 1 ] ; then
				GOODCHOICE=A
			fi
			;;
		TSD)	ROBTYPE=TSD
			;;
		TSH)	ROBTYPE=TSH
			if [ "$HOSTTYPE" != RS6000 -a "$HOSTTYPE" != solaris -a "$HOSTTYPE" != SGI ] ; then
				GOODCHOICE=O
			fi
			;;
		ACS|TLH|TLM)
			$ECHO "$ROBTYPE devices are not supported by this utility."
			exit 1
			;;
		HELP_CHOSEN)
			print_intro
			gen_assumptions_for_make_devs
			askifquit
			get_robot_type
			;;
		EXIT_CHOSEN)	exit 0
			;;
		*)
			$ECHO "$robotype devices are not supported by this utility."
			exit 1
			;;
	esac
	if [ N${GOODCHOICE} = NA ] ; then
		$ECHO "
$ROBTYPE devices are not supported on the Auspex Storage Processor.
"
		exit 1
	elif [ N${GOODCHOICE} = NO ] ; then
		$ECHO "
$ROBTYPE devices are not supported on this platform.
"
		exit 1
	fi
}
# -----------------------------------------------------------------------------
# Obtain the slot number from the user
#
#	get_slot_numbers robtype "robotic devices"
#  OR	get_slot_numbers #drives "tape drives"
#
# For robotic devices:
# 	- entered value is returned in the VALUE variable
# For tape devices:
# 	- entered value is returned in the VALUE1,VALUE2,...,VALUEn variables
#
# This routine is used for devices connected to the Auspex Storage Processor.
#

get_slot_numbers()
{
	devices="$2"

	if [ "$2" = "robotic devices" ] ; then
		robot_type=$1
		robot_devices=1
		devtype="type 8h"
	else
		num_drives=$1
		robot_devices=0
		devtype="type 1h"
	fi

	if [ $AUSPEX_SP -ne 1 ] ; then
		VALUE=?
		VALUE1=?
		return
	fi

	$ECHO "
Scanning for $devices on the Auspex Storage Processor ...
"
	spscan_out_file=/tmp/vmconf.spscan.$$
	$SPSCAN > $spscan_out_file
	X=$?
	if [ $X -eq 1 ] ; then
		$ECHO "Could not scan for $devices using $SPSCAN"
		rm -f $spscan_out_file
		exit 1
	fi
	dev_count=`cat $spscan_out_file | grep "$devtype" | wc -l`
	if [ $dev_count -eq 0 ] ; then
		$ECHO "Could not find any $devices on the Auspex Storage Processor."
		rm -f $spscan_out_file
		exit 1
	fi
	$ECHO " "
	$ECHO "Available $devices:"
	$ECHO " "
	$ECHO "Slot     Description"
	$ECHO "----     -----------"
	cat $spscan_out_file | grep "$devtype" | cut -c 9- | \
	  awk '{ FS=":"; printf "%4d    %s\n", $1, $2 }' | sort -n
	$ECHO " "

	if [ $robot_devices -eq 1 ] ; then
		done=0
		retries=0
		while [ $done -ne 1 ]
		do
			get_number_no_range "Which slot number is the $robot_type SCSI robotic control connected to?"
			found=`cat $spscan_out_file | grep "$devtype" | grep "asc$VALUE:" | wc -l`
			if [ $found -eq 1 ] ; then
				done=1
			else
				retries=`expr $retries + 1`
				if [ $retries -eq 3 ] ; then
					re_run_slot
				fi
				$ECHO "Could not validate the slot number provided.  Please select again."
			fi
		done

		#
		# For robotic devices, do nothing with "VALUE" as it
		# was obtained from get_number_no_range(). Just leave it
		# as-is for the caller.
		#

	elif [ $num_drives -eq 1 ] ; then
		done=0
		retries=0
		while [ $done -ne 1 ]
		do
			get_number_no_range "Which slot number is the tape drive connected to?"
			found=`cat $spscan_out_file | grep "$devtype" | grep "asc$VALUE:" | wc -l`
			if [ $found -eq 1 ] ; then
				done=1
			else
				retries=`expr $retries + 1`
				if [ $retries -eq 3 ] ; then
					re_run_slot
				fi
				$ECHO "Could not validate the slot number provided.  Please select again."
			fi
		done

		#
		# Save the slot number in a variable "VALUE1",
		# representing drive number 1.
		#

		tmpvar=VALUE1
		eval $tmpvar=$VALUE

	elif [ $num_drives -gt 1 ] ; then
		i=1
		while [ $i -le $num_drives ]
		do
			done=0
			retries=0
			while [ $done -ne 1 ]
			do
				get_number_no_range "Which slot number is drive $i connected to?"
				found=`cat $spscan_out_file | grep "$devtype" | grep "asc$VALUE:" | wc -l`
				if [ $found -eq 1 ] ; then
					done=1
				else
					retries=`expr $retries + 1`
					if [ $retries -eq 3 ] ; then
						re_run_slot
					fi
					$ECHO "Could not validate the slot number provided.  Please select again."
				fi
			done

			#
			# Save the slot number in a variable "VALUEn",
			# where "n" is the drive number.
			#

			tmpvar=VALUE$i
			eval $tmpvar=$VALUE

			i=`expr $i + 1`
		done
	else
		# should not occur
		VALUE=0
		$ECHO "Could not obtain the slot number provided."
	fi

	rm -f $spscan_out_file
}

# -----------------------------------------------------------------------------
# Obtain the SCSI adapter number from the user
#
#	get_scsi_adapter robtype "robotic devices"
#  OR   get_scsi_adapter "drive" "tape drives"
#
#
#	Entered value is returned in the VALUE variable

get_scsi_adapter()
{
	robot_name=$1
	case "$HOSTTYPE" in
	    HP700)
		if confirm "Is the $robot_name attached to the standard (Core I/0) SCSI bus"
		then
			VALUE=core
		else
			get_number "Which EISA adapter is the $robot_name connected to?" 1 4
		fi
		;;
	    sun)
		get_number "Which SCSI adapter is the $1 connected to?" 0 4
		;;
	    RS6000)
		$ECHO " "
		$ECHO "Available SCSI adapters:"
		/usr/sbin/lsdev -C -S a -c adapter -t hscsi
		/usr/sbin/lsdev -C -S a -c adapter -t pscsi
		/usr/sbin/lsdev -C -S a -t vscsi
		/usr/sbin/lsdev -C -S a -c adapter -t 8efc	# Wide SCSI
		$ECHO " "
		echo "Which SCSI adapter is the $1 connected to? (ex. for \"scsi1\" enter scsi1) \c"
		read VALUE
		tmp_str=`/usr/sbin/lsdev -C -l ${VALUE}`
		while [ "X" = "X${tmp_str}" ]
		do
			$ECHO "\t\"${VALUE}\" is NOT a valid SCSI bus"
			$ECHO "Which SCSI adapter is the $1 connected to? \c"
			read VALUE
			tmp_str=`/usr/sbin/lsdev -C -l ${VALUE}`
		done
		;;
	    ALPHA)
		$ECHO "Possible $2 to select from:"
		$ECHO ""
		if [ "$2" = "robotic devices" ] ; then
			/usr/openv/volmgr/bin/lsdev changer
		else
			/usr/openv/volmgr/bin/lsdev tape
		fi
		get_number_no_range "Which SCSI bus is the $1 connected to?"
		;;
	    *)
		get_number "Which SCSI adapter is the $1 connected to?" 0 7
		;;
	esac
}
# -----------------------------------------------------------------------------
# Obtain the SCSI ID (target) number from the user
#
#	get_scsi_id promptstring ["tape"|"sctl"]
#
#	Entered value is returned in the VALUE variable

get_scsi_id()
{
	promptstring="$1"
	devtype=$2
	case "$HOSTTYPE" in
	    sun|HP700|RS6000)
		get_number "What is the SCSI ID for the $promptstring" 0 6
		;;
	    HP800)
		if [ "${devtype}" = "sctl" ] ; then
			ioscan sctl
		fi
		get_number_no_range  "What is the Logical Unit number for the $promptstring?"
		;;
	    HPUX10)
		if [ "${devtype}" = "sctl" ] ; then
			HW_PATH=0
			$ECHO "Looking for SCSI robotic control devices (using the sctl pass-through driver) ..."
			$ECHO " "
			# get the hw id
			/bin/rm -f /tmp/vmconf.awk
			cat >> /tmp/vmconf.awk <<__EOF__
BEGIN { FS = ":" }
{	path = \$11
	LENGTH = length(path)
	if ( LENGTH >= 5 ) {
		dota = substr(path, LENGTH - 1, 1)
		lun = substr(path, LENGTH - 2, 1)
		dotb = substr(path, LENGTH - 3, 1)
		sid = substr(path, LENGTH - 4, 1)

		if ( dota == "." && dotb == "." ) {
			# has scsi id an lun
			OFS = ":"
			# print HW path, bus instance, SCSI ID, LUN, description
			print path, \$19, sid, lun, \$18
		}
	}
}
__EOF__
			# check if on an HP700
			/bin/hp9000s700
			not_hp700=$?

			UNKNOWNS=`$IOSCAN -F | grep UNKNOWN | awk -f /tmp/vmconf.awk`
			if [ "${UNKNOWNS}X" = "X" ] ; then
				/bin/rm -f /tmp/vmconf.awk
				$ECHO "Could not find any SCSI robotic control devices (using sctl) with ioscan."
				if [ $not_hp700 -eq 1 ] ; then
					# this is not a 700; (assume it's an 800)
					ioscan sctl
					get_number_no_range  "What is the Instance number (I) for the $promptstring?"
					return
				else
					# this is a 700
					use_tpconfig
					exit 1
				fi
			fi

			#
			# "UNKNOWNS" does not contain newlines, so get the list again
			#

			$ECHO "Found the following devices that are possibly robotic control devices:"
			$ECHO " "
			$IOSCAN -F | grep UNKNOWN | awk -f /tmp/vmconf.awk | awk 'BEGIN { FS = ":" } { print "Hardware Path: ", $1, "Description: ", $5 }'
			$ECHO " "
			/bin/rm -f /tmp/vmconf.awk
			if [ $not_hp700 -eq 1 ] ; then
				$ECHO "To use the built-in SCSI (c7XX) driver, provide the hardware path of the robotic"
				$ECHO "control device you want to use.  To use the spt driver, enter a carriage return."
				$ECHO " "
				$ECHO "Enter Hardware Path or <RETURN>: \c"
				read VALUE
				if [ "$VALUE" ] ; then
					HW_PATH=1
				else
					$ECHO " "
					ioscan sctl
					get_number_no_range  "What is the Instance number (I) for the $promptstring?"
					return
				fi
			else
				$ECHO "Enter the Hardware Path of the robotic control device: \c"
				read VALUE
				HW_PATH=1
			fi
		else
			get_number_no_range  "What is the Instance number (I) for the $promptstring?"
		fi
		;;
	    SGI)
		get_number "What is the SCSI ID for the $promptstring" 1 7
		;;
	    solaris|ALPHA)
		get_number "What is the SCSI ID for the $promptstring" 0 6
		;;
	esac
}

# -----------------------------------------------------------------------------
ioscan()
{
	if [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
		return 0
	fi
	case "$1" in
	sctl)
		/bin/hp9000s700
		if [ $? -eq 1 ] ; then
			# this is an 800
			$ECHO "Looking for spt devices configured in this system ...\n"
			$IOSCAN -f -C spt 2>/dev/null
			if [ $? != 0 ] ; then
				$ECHO "No spt devices found with ioscan on this system."
			fi
		# else this is a 700 this is taken care of in get_scsi_id
		fi
		;;
	tape_drive|tape)
		if [ "$HOSTTYPE" = HPUX10 ] ; then
			str="tape"
		else
			str="tape_drive"
		fi
		$ECHO "Looking for $str devices configured in this system ...\n"
		$IOSCAN -f -C $str 2>/dev/null
		if [ $? != 0 ] ; then
			$ECHO "No $str devices found with ioscan on this system."
		fi
		;;
	disk)
		$ECHO "Looking for $1 devices configured in this system ...\n"
		$IOSCAN -f -C $1 2>/dev/null
		if [ $? != 0 ] ; then
			$ECHO "No $1 devices found with ioscan on this system."
		fi
		;;
	esac
	$ECHO ""
}
# -----------------------------------------------------------------------------
print_alpha_drive_choices()
{
	if [ "$HOSTTYPE" != ALPHA ] ; then
		return 0
	fi

	$ECHO "Possible tape drives to select from on bus ${ADAPTER}:"
	$ECHO ""
	/usr/openv/volmgr/bin/lsdev tape bus ${ADAPTER}
}
# -----------------------------------------------------------------------------
print_alpha_optical_choices()
{
	if [ "$HOSTTYPE" != ALPHA ] ; then
		return 0
	fi

	$ECHO "Possible optical drives to select from on bus ${ADAPTER}:"
	$ECHO ""
	/usr/openv/volmgr/bin/lsdev disk bus ${ADAPTER}
}
# -----------------------------------------------------------------------------
valid_face()
{
	case $1 in
		[A-La-l])
			return 0 ;;
		*)
			return 1 ;;
	esac
}
# -----------------------------------------------------------------------------
valid_hex()
{
	case $1 in
		[0-9a-fA-F])
			return 0 ;;
		*)
			return 1 ;;
	esac
}
# -----------------------------------------------------------------------------
get_sun_dev_info()
{
	bus=$1
	target=$2
	dtype=$3

	X=`cat /etc/motd | grep SunOS | head -1 | cut -f4 -d" " | cut -f2 -d"(" | cut -f1 -d")"`
	configfile=/sys/`uname -m`/conf/$X

	scsiout=`grep "scsibus$bus target $target" $configfile | grep -v "^#" | grep $dtype | head -1`

	# see if this adapter/ID combo is config'd in the kernel
	if test Y"$scsiout" = Y
	then
		$ECHO "Kernel $X is not configured for any $dtype device at scsibus $bus target ${target}."
		$ECHO "Please reconfigure/rebuild the kernel using $configfile, and re-run this script."
		exit 3
	fi

	devtype=`echo $scsiout | cut -f1 -d" "`
	devname=`echo $scsiout | cut -f2 -d" "`

	# see if this adapter/ID combo has correct type config'd in the kernel
	if test "$devtype" != "$dtype"
	then
		$ECHO "Kernel $X is configured for $devtype device at scsibus $bus target $target,"
		$ECHO "instead of $dtype device."
		$ECHO "Please reconfigure/rebuild the kernel using $configfile, and re-run this script."
		exit 3
	fi

	# see if this adapter/ID combo as config'd in the kernel has dev files
	if test "$dtype" = tape
	then
		devpath=/dev/r${devname}
		if [ ! -r "$devpath" ] ; then
			$ECHO Making device files for $devname ...
			make_dev $devname
		fi
	else
		# optical disk

		devpath=/dev/${devname}a
		if [ ! -r "$devpath" ] ; then
			$ECHO Making device files for $devname ...
			make_dev $devname
		fi
	fi
}

##
# MAKE_DEV funcions
##

# -----------------------------------------------------------------------------
make_dev()
{
	CURRENT=`/bin/pwd`
	cd /dev
	case $HOSTTYPE in
	    sun)
		$ECHO ./MAKEDEV $1
		./MAKEDEV $1 > /dev/null
		;;
	    SGI)
		/usr/openv/volmgr/bin/stopltid > /dev/null 2>&1
		$ECHO ./MAKEDEV $1
		./MAKEDEV $1 > /dev/null
		;;
	    HP700|HP800|HPUX10)
		$ECHO /etc/mknod $1 $2 $3 $4
		/etc/mknod $1 $2 $3 $4
		;;
	    ALPHA)
		tmpdev=`expr $1 \* 8 + $2`
		$ECHO ./MAKEDEV tz${tmpdev}
		./MAKEDEV tz${tmpdev}
		;;
	    *)
		$ECHO /etc/mknod $1 $2 $3 $4
		/etc/mknod $1 $2 $3 $4
		;;
	esac
	cd $CURRENT
}

# -----------------------------------------------------------------------------
make_dev_files()
{

	if [ "$HOSTTYPE" = "solaris" ] ; then
		installed_sg=0
		# check if sg is installed and /dev/sg is there, if not install it
		sg_check=`/usr/sbin/modinfo | grep "SCSA Generic"`
		if [ "X${sg_check}" = "X" -o  ! -d /dev/sg ] ; then
			$ECHO "Installing the SCSA Generic device driver"
			/usr/openv/volmgr/bin/driver/sg.install
			installed_sg=1
		fi
		# set a flag to indicate that sgscan has not been executed yet
		sgscan_done=0
		sgscan_out_file=/tmp/vmconf.sgscan.$$.out
		sgscan_err_file=/tmp/vmconf.sgscan.$$.err
	fi

	case $ROBTYPE in
		TL4) make_TL4_devs ;;
		TS8) make_TS8_devs ;;
		TSH) make_TSH_devs ;;
		TC8) make_TC8_devs ;;
		TC4) make_TC4_devs ;;
		TL8) make_TL8_devs ;;
		TLD) make_TLD_devs ;;
		ODL) make_ODL_devs ;;
		TSD) make_TSD_devs ;;
		"Standalone Drive") make_NON_ROBOTIC_devs ;;
	esac
}
# -----------------------------------------------------------------------------
pick_auspex_processor()
{

	if [ "$HOSTTYPE" != sun ] ; then
		return
	elif [ "$ARCHTYPE" != auspex ] ; then
		return
	else
	$ECHO "
	Choose the processor to which the robot and drives are connected.

	Auspex Processor
	----------------
	1.  Host Processor
	2.  Storage Processor"
	get_number "\tEnter processor choice" 1 2
	case $VALUE in
		1) AUSPEX_SP=0 ;;
		2) AUSPEX_SP=1 ;;
	esac
fi
}
#----------------------------------------------------------------------------
#
#
get_hp_tape_driver()
{

	if [ -f /etc/conf/dfile ] ; then
		newdriver=`grep scsitape /etc/conf/dfile`
		olddriver=`grep s2tape /etc/conf/dfile`
	fi

	if test Y"$newdriver" != Y
	then
		majorNum=121
	else
		if test Y"$olddriver" != Y
		then
			majorNum=54
		else
			$ECHO "With HP-UX 9.0, you can use either of two SCSI tape drivers:"
			$ECHO "    s2tape   -- same driver as with HP-UX 8.0, major number 54"
			$ECHO "    scsitape -- new driver with HP-UX 9.0, major number 121"
			if confirm_no "are you using the old (HP-UX 8.0) SCSI tape driver"
			then
				majorNum=54
			else
				majorNum=121
			fi
		fi
	fi

	TAPE_DRIVER=$majorNum
}

# -----------------------------------------------------------------------------
check_drive_path()
{
	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	if [ $2 ] ; then
		$ECHO You will be using $2 for the drive $1 rewind device name.
		if [ ! -r "$2" ] ; then
			missingpath=1
			$ECHO "Drive $1 rewind-device path $2 does NOT exist."
		fi
	else
		$ECHO "Nothing was defined for the drive $1 rewind-device path."
	fi

	if [ $3 ] ; then
		$ECHO You will be using $3 for the drive $1 non-rewind device name.
		if [ ! -r "$3" ] ; then
			missingpath=1
			$ECHO "Drive $1 non-rewind-device path $3 does NOT exist."
		fi
	else
		$ECHO "Nothing was defined for the drive $1 non-rewind device path."
	fi
}
# -----------------------------------------------------------------------------
check_robot_path()
{
	ROB_PATH=$1

	if [ $1 ] ; then
		$ECHO You will be using ${ROB_PATH} for the robotics control.
		if [ ! -r "$ROB_PATH" ] ; then
			missingpath=1
			$ECHO "Robotics control path ${ROB_PATH} does NOT exist."
		fi
	else
		$ECHO "Nothing was defined for the robotics control path."
	fi
}

# -----------------------------------------------------------------------------
#  $1 - Drive number
#  $2 - Drive Type
#  $3 - Drive ID  (Slot number for Auspex SP, Logical device for Solaris
#                  eg. on Solaris it is "0" for tapes at /dev/rmt/0,                 
#                  or "c1t0d0" for "/dev/rdsk/c1t0d0s6")
#  $4 - Adapter	(unused for solaris)
make_drive_devs()
{
	if [ $2 = OPTICAL ] ; then

		case "$HOSTTYPE" in
		   sun)
			if [ $AUSPEX_SP -eq 1 ] ; then
				$ECHO "Optical disk not supported on the Auspex Storage Processor."
				exit 1
			else
				make_sun_odl_drive_devs $1 $3
			fi
			;;
		   HP700)
			make_odl_drive_hp $4 $3 $1
			;;
		   HP800)
			make_odl_drive_hp800 $1 $3 $4
			;;
		   HPUX10)
			make_odl_drive_hp10 $1 $3 $4
			;;
		   SGI)
			make_sgi_odl_drive_devs $1 $3 $4
			;;
		   solaris)
			make_solaris_odl_drive_devs $1 $3
			;;
		   RS6000)
			make_rs6000_odl_drive_devs $1 $3 $4
			;;
		   ALPHA)
			$ECHO "Optical disk not supported on DEC Alpha."
			exit 1
			;;
		esac
	else
		case "$HOSTTYPE" in
		   sun)
			make_sun_drive_devs $1 $3 $2
			;;
		   HP700)
			make_hp_drive_devs $1 $2 $4 $3
			;;
		   HP800)
			make_hp800_drive_devs $1 $2 $3 $4
			;;
		   HPUX10)
			make_hp10_drive_devs $1 $2 $3 $4
			;;
		   SGI)
			make_sgi_drive_devs $1 $2 $3 $4
			;;
		   solaris)
			make_solaris_drive_devs $1 $2 $3
			;;
		   RS6000)
			make_rs6000_drive_devs $1 $2 $3 $4
			;;
		   ALPHA)
			make_alpha_drive_devs $1 $2 $3 $4
			;;
		esac
	fi
}

# -----------------------------------------------------------------------------
#
#
make_hp10_drive_devs ()
{
	drive_number=$1
	DRIVE_TYPE=$2
	adapter=$4
	s_id=$3

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	case $DRIVE_TYPE in
	    8200)
		denstr=BEST
		;;
	    8500)
		denstr=BEST
		;;
	    4mm)
		denstr=BEST
		;;
	    8505)
		denstr=BEST
		;;
	    dlt|dlt2|hcart|hcart2|dtf)
		denstr=BEST
		;;
	    4mm_compress)
		denstr=BEST
		;;
	    *)
		$ECHO "Unknown drive density $dens"
		exit 1
		;;
	esac

	# get the tape drive HW path from the instance #(s_id)
	io_scan_info=`$IOSCAN -F -C tape -I ${s_id}`
	hw_path=`$ECHO ${io_scan_info} | awk 'BEGIN { FS = ":" } { print $11 }'`
	if [ "${hw_path}X" = "X" ] ; then
		$ECHO "Tape drive with instance ${s_id} is not configured."
		return 1
	fi

	cntrl=`$ECHO ${io_scan_info} | awk 'BEGIN { FS = ":" } { print $19 }'`
	id=`$ECHO ${hw_path} | awk 'BEGIN { FS = "." } { field=NF - 1 } {print $field }'`
	lun=`$ECHO ${hw_path} | awk 'BEGIN { FS = "." } { field=NF } {print $field}'`
	rewdevfile=/dev/rmt/c${cntrl}t${id}d${lun}${denstr}b
	nrewdevfile=/dev/rmt/c${cntrl}t${id}d${lun}${denstr}nb

	if [ ! -r "$rewdevfile" -o  ! -r "$nrewdevfile" ] ; then
		# make the device files
		$ECHO "/usr/sbin/mksf -H ${hw_path} -C tape -b ${denstr} -u"
		/usr/sbin/mksf -H ${hw_path} -C tape -b ${denstr} -u
		$ECHO "/usr/sbin/mksf -H ${hw_path} -C tape -b ${denstr} -u -n"
		/usr/sbin/mksf -H ${hw_path} -C tape -b ${denstr} -u -n
	fi

	case $drive_number in
	     1) DRIVE1_STR="$rewdevfile"
		DRIVE1_STR_NR="$nrewdevfile"
		;;
	     2) DRIVE2_STR="$rewdevfile"
		DRIVE2_STR_NR="$nrewdevfile"
		;;
	     3) DRIVE3_STR="$rewdevfile"
		DRIVE3_STR_NR="$nrewdevfile"
		;;
	     4)	DRIVE4_STR="$rewdevfile"
		DRIVE4_STR_NR="$nrewdevfile"
		;;
	     5) DRIVE5_STR="$rewdevfile"
		DRIVE5_STR_NR="$nrewdevfile"
		;;
	     6) DRIVE6_STR="$rewdevfile"
		DRIVE6_STR_NR="$nrewdevfile"
		;;
	     7) DRIVE7_STR="$rewdevfile"
		DRIVE7_STR_NR="$nrewdevfile"
		;;
	     8) DRIVE8_STR="$rewdevfile"
		DRIVE8_STR_NR="$nrewdevfile"
		;;
	     9) DRIVE9_STR="$rewdevfile"
		DRIVE9_STR_NR="$nrewdevfile"
		;;
	    10) DRIVE10_STR="$rewdevfile"
		DRIVE10_STR_NR="$nrewdevfile"
		;;
	esac


}
# -----------------------------------------------------------------------------
#
#
make_hp800_drive_devs ()
{
	drive_number=$1
	DRIVE_TYPE=$2
	adapter=$4
	s_id=$3

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	case $DRIVE_TYPE in

	    8200)
		rew_denstr=_8mm8200b
		nrew_denstr=_8mm8200nb
		rew_bits=1048578	# 0x100002
		nrew_bits=1572866	# 0x180002
		;;
	    8500)
		rew_denstr=_8mm8500b
		nrew_denstr=_8mm8500nb
		rew_bits=1048579	# 0x100003
		nrew_bits=1572867	# 0x180003
		;;
	    4mm)
		rew_denstr=mb
		nrew_denstr=mnb
		rew_bits=1179648	# 0x120000
		nrew_bits=1703936	# 0x1a0000
		;;
	    8505)
		rew_denstr=_8mm8500cb
		nrew_denstr=_8mm8500ncb
		rew_bits=1114115	# 0x110003
		nrew_bits=1638403	# 0x190003
		;;
	    dlt|dlt2|hcart|hcart2|dtf)
		rew_denstr=hcb
		nrew_denstr=hncb
		rew_bits=1376256	# 0x150000
		nrew_bits=1900544	# 0x1d0000
		;;
	    4mm_compress)
		rew_denstr=hcb
		nrew_denstr=hncb
		rew_bits=1376256	# 0x150000
		nrew_bits=1900544	# 0x1d0000
		;;
	    *)
		$ECHO "Unknown drive density $dens"
		exit 1
		;;
	esac

	rewdevfile=/dev/rmt/${s_id}${rew_denstr}
	nrewdevfile=/dev/rmt/${s_id}${nrew_denstr}

	# make the device files

	if [ ! -r "$rewdevfile" -o  ! -r "$nrewdevfile" ] ; then
		minor1=`expr ${rew_bits} + 256 \* ${s_id} `
		minor2=`expr ${nrew_bits} + 256 \* ${s_id} `
		make_dev $rewdevfile c 5 ${minor1}
		make_dev $nrewdevfile c 5 ${minor2}
	fi

	case $drive_number in
	     1) DRIVE1_STR="$rewdevfile"
		DRIVE1_STR_NR="$nrewdevfile"
		;;
	     2) DRIVE2_STR="$rewdevfile"
		DRIVE2_STR_NR="$nrewdevfile"
		;;
	     3) DRIVE3_STR="$rewdevfile"
		DRIVE3_STR_NR="$nrewdevfile"
		;;
	     4)	DRIVE4_STR="$rewdevfile"
		DRIVE4_STR_NR="$nrewdevfile"
		;;
	     5) DRIVE5_STR="$rewdevfile"
		DRIVE5_STR_NR="$nrewdevfile"
		;;
	     6) DRIVE6_STR="$rewdevfile"
		DRIVE6_STR_NR="$nrewdevfile"
		;;
	     7) DRIVE7_STR="$rewdevfile"
		DRIVE7_STR_NR="$nrewdevfile"
		;;
	     8) DRIVE8_STR="$rewdevfile"
		DRIVE8_STR_NR="$nrewdevfile"
		;;
	     9) DRIVE9_STR="$rewdevfile"
		DRIVE9_STR_NR="$nrewdevfile"
		;;
	    10) DRIVE10_STR="$rewdevfile"
		DRIVE10_STR_NR="$nrewdevfile"
		;;
	esac


}

# -----------------------------------------------------------------------------
#
#
make_hp_drive_devs ()
{
	drive_number=$1
	DRIVE_TYPE=$2
	adapter=$3
	s_id=$4

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	if test "$adapter" = core
	then
		bus_adapter=201
	else
		bus_adapter=4${adapter}0
	fi

	# assume that the tape driver is majornumber 121
	TAPE_DRIVER=121

	case $DRIVE_TYPE in

	    8200|8500|4mm)
		rew_denstr=mb
		nrew_denstr=mnb
		if [ "$TAPE_DRIVER" = 54 ] ; then
			rew_bits=42
			nrew_bits=43
		else
			rew_bits=06
			nrew_bits=07
		fi
		;;
	    8505|4mm_compress|dlt|dlt2|hcart|hcart2|dtf)
		rew_denstr=cb
		nrew_denstr=cnb
		if [ "$TAPE_DRIVER" = 54 ] ; then
			rew_bits=c2
			nrew_bits=c3
		else
			rew_bits=0e
			nrew_bits=0f
		fi
		;;
	    *)
		$ECHO "unknown drive density $dens"
		exit 1
		;;
	esac

	rewdevfile=/dev/rmt/c${bus_adapter}d${s_id}${rew_denstr}
	nrewdevfile=/dev/rmt/c${bus_adapter}d${s_id}${nrew_denstr}

	# make the device files

	if [ ! -r "$rewdevfile" -o  ! -r "$nrewdevfile" ] ; then
		make_dev $rewdevfile c $TAPE_DRIVER 0x${bus_adapter}${s_id}${rew_bits}
		make_dev $nrewdevfile c $TAPE_DRIVER 0x${bus_adapter}${s_id}${nrew_bits}
	fi

	case $drive_number in
	     1) DRIVE1_STR="$rewdevfile"
		DRIVE1_STR_NR="$nrewdevfile"
		;;
	     2) DRIVE2_STR="$rewdevfile"
		DRIVE2_STR_NR="$nrewdevfile"
		;;
	     3) DRIVE3_STR="$rewdevfile"
		DRIVE3_STR_NR="$nrewdevfile"
		;;
	     4)	DRIVE4_STR="$rewdevfile"
		DRIVE4_STR_NR="$nrewdevfile"
		;;
	     5) DRIVE5_STR="$rewdevfile"
		DRIVE5_STR_NR="$nrewdevfile"
		;;
	     6) DRIVE6_STR="$rewdevfile"
		DRIVE6_STR_NR="$nrewdevfile"
		;;
	     7) DRIVE7_STR="$rewdevfile"
		DRIVE7_STR_NR="$nrewdevfile"
		;;
	     8) DRIVE8_STR="$rewdevfile"
		DRIVE8_STR_NR="$nrewdevfile"
		;;
	     9) DRIVE9_STR="$rewdevfile"
		DRIVE9_STR_NR="$nrewdevfile"
		;;
	    10) DRIVE10_STR="$rewdevfile"
		DRIVE10_STR_NR="$nrewdevfile"
		;;
	esac
}

# -----------------------------------------------------------------------------
#  $1 - Drive number
#  $2 - Drive Type
#  $3 - Drive ID
#  $4 - Adapter
make_sgi_drive_devs()
{

	case $2 in
		8500) MKDEV_sufix=".8500";;
		8505) MKDEV_sufix=".8500c";;
		dlt|dlt2|hcart|hcart2|ibm3590) MKDEV_sufix="c";;
		dtf) MKDEV_sufix="c";;
		*) MKDEV_sufix="";;
	esac

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	case $1 in
	    1)	DRIVE1_STR=/dev/rmt/tps${ADAPTER}d${DRIVE1}v${MKDEV_sufix}
		DRIVE1_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE1}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE1_STR" -o  ! -r "$DRIVE1_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	    2)	DRIVE2_STR=/dev/rmt/tps${ADAPTER}d${DRIVE2}v${MKDEV_sufix}
		DRIVE2_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE2}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE2_STR" -o  ! -r "$DRIVE2_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	    3)	DRIVE3_STR=/dev/rmt/tps${ADAPTER}d${DRIVE3}v${MKDEV_sufix}
		DRIVE3_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE3}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE3_STR" -o  ! -r "$DRIVE3_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	    4)	DRIVE4_STR=/dev/rmt/tps${ADAPTER}d${DRIVE4}v${MKDEV_sufix}
		DRIVE4_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE4}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE4_STR" -o  ! -r "$DRIVE4_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	    5)	DRIVE5_STR=/dev/rmt/tps${ADAPTER}d${DRIVE5}v${MKDEV_sufix}
		DRIVE5_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE5}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE5_STR" -o  ! -r "$DRIVE5_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	    6)	DRIVE6_STR=/dev/rmt/tps${ADAPTER}d${DRIVE6}v${MKDEV_sufix}
		DRIVE6_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE6}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE6_STR" -o  ! -r "$DRIVE6_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	    7)	DRIVE7_STR=/dev/rmt/tps${ADAPTER}d${DRIVE7}v${MKDEV_sufix}
		DRIVE7_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE7}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE7_STR" -o  ! -r "$DRIVE7_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	    8)	DRIVE8_STR=/dev/rmt/tps${ADAPTER}d${DRIVE8}v${MKDEV_sufix}
		DRIVE8_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE8}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE8_STR" -o  ! -r "$DRIVE8_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	    9)	DRIVE9_STR=/dev/rmt/tps${ADAPTER}d${DRIVE9}v${MKDEV_sufix}
		DRIVE9_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE9}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE9_STR" -o  ! -r "$DRIVE9_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	   10)	DRIVE10_STR=/dev/rmt/tps${ADAPTER}d${DRIVE10}v${MKDEV_sufix}
		DRIVE10_STR_NR=/dev/rmt/tps${ADAPTER}d${DRIVE10}nrv${MKDEV_sufix}
		if [ ! -r "$DRIVE10_STR" -o  ! -r "$DRIVE10_STR_NR" ] ; then
			$STOPLTID >/dev/null 2>/dev/null
			make_dev tps
			$LTID >/dev/null 2>/dev/null &
		fi
		;;
	esac
}

# -----------------------------------------------------------------------------
#	make_solaris_drive_devs()
#
#  $1 - Drive number
#  $2 - Drive Type
#  $3 - Drive's Logical Index, eg. "0" for "/dev/rmt/0"
make_solaris_drive_devs()
{
	drive_number=$1
	DRIVE_TYPE=$2
	logical_id=$3

	device_path_prefix=/dev/rmt/

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	case $DRIVE_TYPE in
		8200)
			rew_denstr=lb
			nrew_denstr=lbn
			;;
		8505|4mm_compress|dlt|dlt2|hcart|hcart2|ibm3590|dtf)
		# 8900 was set earlier to be 8505
			rew_denstr=cb
			nrew_denstr=cbn
			;;
		8500|4mm|*)
			rew_denstr=mb
			nrew_denstr=mbn
			;;
	esac

	rewdevfile=${device_path_prefix}${logical_id}${rew_denstr}
	nrewdevfile=${device_path_prefix}${logical_id}${nrew_denstr}

	if [ ! -h $rewdevfile -o ! -h $nrewdevfile ] ; then
		$ECHO "Could not find both tape device file links $rewdevfile and $nrewdevfile"
		re_run 1
	fi

	case $drive_number in
	     1) DRIVE1_STR="$rewdevfile"
		DRIVE1_STR_NR="$nrewdevfile"
		;;
	     2) DRIVE2_STR="$rewdevfile"
		DRIVE2_STR_NR="$nrewdevfile"
		;;
	     3) DRIVE3_STR="$rewdevfile"
		DRIVE3_STR_NR="$nrewdevfile"
		;;
	     4) DRIVE4_STR="$rewdevfile"
		DRIVE4_STR_NR="$nrewdevfile"
		;;
	     5) DRIVE5_STR="$rewdevfile"
		DRIVE5_STR_NR="$nrewdevfile"
		;;
	     6) DRIVE6_STR="$rewdevfile"
		DRIVE6_STR_NR="$nrewdevfile"
		;;
	     7) DRIVE7_STR="$rewdevfile"
		DRIVE7_STR_NR="$nrewdevfile"
		;;
	     8) DRIVE8_STR="$rewdevfile"
		DRIVE8_STR_NR="$nrewdevfile"
		;;
	     9) DRIVE9_STR="$rewdevfile"
		DRIVE9_STR_NR="$nrewdevfile"
		;;
	    10) DRIVE10_STR="$rewdevfile"
		DRIVE10_STR_NR="$nrewdevfile"
		;;
	esac
}
# -----------------------------------------------------------------------------
#	make_rs6000_drive_devs()
#
#  $1 - Drive number
#  $2 - Drive Type
#  $3 - Drive ID
#  $4 - Adapter
make_rs6000_drive_devs()
{
	drive_number=$1
	DRIVE_TYPE=$2
	s_id=$3
	adapter=$4

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	if [ $common_device_file -eq 1 ] ; then
		# like IBM 3590 B11 stacker
		# don't need to make drive device file, since it's the same one
		# that was used for the robot.

		DRIVE1_STR_NR=$ROBCTRL_PATH
		DRIVE1_STR=`$ECHO $ROBCTRL_PATH | awk 'BEGIN { FS="."} { print $1 }'`
		return
	fi

	case $DRIVE_TYPE in
		8200)	type="8mm"
			;;
		8500|8505|4mm|4mm_compress|dtf|dlt|*)
			type="ost"
			;;
	esac

	# scan lsdev output for the physical location of the scsi bus
	bus_addr=`/etc/lsdev -C -l ${adapter} | cut -f3 -d' ' `

	if [ "X" = "${bus_addr}X" ] ; then
		# adapter is not a valid scsi bus
		$ECHO "scsi${adapter} is not a valid SCSI bus, or is not available."
		re_run 1
	fi


	# pad adapter string if needed
	tmp_var=`$ECHO ${bus_addr} | cut -c 6-8`
	if [ "${tmp_var}X" = "X" ] ; then
		bus_addr="${bus_addr}-00"
	fi

	# find the device name
	if [ $aixversion -eq 3 ] ; then
		device_str=`/usr/sbin/lsdev -C -S a -s scsi -c tape | grep "${bus_addr}-${s_id}0"`
	else
		device_str=`/usr/sbin/lsdev -C -S a -s scsi -c tape | grep "${bus_addr}-${s_id},0"`
	fi

	dev_name=`$ECHO "${device_str}" | cut -f1 -d' '`
	dev_status=`$ECHO "${device_str}" | cut -f2 -d' '`

	if [ "X" = "${dev_name}X" ] ; then
		# no device was found, must create device
		if [ $aixversion -eq 3 ] ; then
			$ECHO "/usr/sbin/mkdev -c tape -s scsi -t ${type} -p ${adapter} -w ${s_id}0"
			tmp_dev=`/usr/sbin/mkdev -c tape -s scsi -t ${type} -p ${adapter} -w ${s_id}0 `
		else
			$ECHO "/usr/sbin/mkdev -c tape -s scsi -t ${type} -p ${adapter} -w ${s_id},0"
			tmp_dev=`/usr/sbin/mkdev -c tape -s scsi -t ${type} -p ${adapter} -w ${s_id},0 `
		fi

		if [ $? != 0 ] ; then
			# mkdev failed
			$ECHO "$tmp_dev"
			$ECHO "Could not create tape device on SCSI bus ${adapter} at id ${s_id}"
			re_run 1
		fi

		dev_name=`$ECHO "$tmp_dev" | cut -f1 -d' '`

		# set the block size to 0 (variable length
		$ECHO "/usr/sbin/chdev -l ${dev_name} -a block_size=0"
		/usr/sbin/chdev -l ${dev_name} -a block_size=0
	else
		# check to see if the tape drive is available
		if [ "${dev_status}" != "Available" ] ; then
			$ECHO "/usr/sbin/mkdev -l ${dev_name}"
			/usr/sbin/mkdev -l ${dev_name}
		fi
	fi

	rewdevfile=/dev/${dev_name}
	nrewdevfile=/dev/${dev_name}.1

	if [ ! -r "$rewdevfile" -o  ! -r "$nrewdevfile" ] ; then
		if [ $aixversion -eq 3 ] ; then
			$ECHO "/usr/sbin/mkdev -c tape -s scsi -t ${type} -p ${adapter} -w ${s_id}0"
			/usr/sbin/mkdev -c tape -s scsi -t ${type} -p ${adapter} -w ${s_id}0
		else
			$ECHO "/usr/sbin/mkdev -c tape -s scsi -t ${type} -p ${adapter} -w ${s_id},0"
			/usr/sbin/mkdev -c tape -s scsi -t ${type} -p ${adapter} -w ${s_id},0
		fi

		if [ $? != 0 ] ; then
			# mkdev failed
			$ECHO "Could not create tape device on SCSI bus ${adapter} at id ${s_id}"
			re_run 1
		fi

	fi

	case $drive_number in
	     1) DRIVE1_STR="$rewdevfile"
		DRIVE1_STR_NR="$nrewdevfile"
		;;
	     2) DRIVE2_STR="$rewdevfile"
		DRIVE2_STR_NR="$nrewdevfile"
		;;
	     3) DRIVE3_STR="$rewdevfile"
		DRIVE3_STR_NR="$nrewdevfile"
		;;
	     4) DRIVE4_STR="$rewdevfile"
		DRIVE4_STR_NR="$nrewdevfile"
		;;
	     5) DRIVE5_STR="$rewdevfile"
		DRIVE5_STR_NR="$nrewdevfile"
		;;
	     6) DRIVE6_STR="$rewdevfile"
		DRIVE6_STR_NR="$nrewdevfile"
		;;
	     7) DRIVE7_STR="$rewdevfile"
		DRIVE7_STR_NR="$nrewdevfile"
		;;
	     8) DRIVE8_STR="$rewdevfile"
		DRIVE8_STR_NR="$nrewdevfile"
		;;
	     9) DRIVE9_STR="$rewdevfile"
		DRIVE9_STR_NR="$nrewdevfile"
		;;
	    10) DRIVE10_STR="$rewdevfile"
		DRIVE10_STR_NR="$nrewdevfile"
		;;
	esac

}
# -----------------------------------------------------------------------------
make_sun_drive_devs()
{
	SUN_DT=$3

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	if [ $AUSPEX_SP -eq 1 ] ; then
		case $1 in
		    1)	DRIVE1_STR=/dev/rast$2
			DRIVE1_STR_NR=/dev/nrast$2
			;;
		    2)	DRIVE2_STR=/dev/rast$2
			DRIVE2_STR_NR=/dev/nrast$2
			;;
		    3)	DRIVE3_STR=/dev/rast$2
			DRIVE3_STR_NR=/dev/nrast$2
			;;
		    4)	DRIVE4_STR=/dev/rast$2
			DRIVE4_STR_NR=/dev/nrast$2
			;;
		    5)	DRIVE5_STR=/dev/rast$2
			DRIVE5_STR_NR=/dev/nrast$2
			;;
		    6)	DRIVE6_STR=/dev/rast$2
			DRIVE6_STR_NR=/dev/nrast$2
			;;
		    7)	DRIVE7_STR=/dev/rast$2
			DRIVE7_STR_NR=/dev/nrast$2
			;;
		    8)	DRIVE8_STR=/dev/rast$2
			DRIVE8_STR_NR=/dev/nrast$2
			;;
		    9)	DRIVE9_STR=/dev/rast$2
			DRIVE9_STR_NR=/dev/nrast$2
			;;
		   10)	DRIVE10_STR=/dev/rast$2
			DRIVE10_STR_NR=/dev/nrast$2
			;;
		esac
	else
		get_sun_dev_info ${ADAPTER} $2 tape
		stnum=`echo $devname | cut -c3-`

		if [ "${SUN_DT}" = 8500 ] ; then
			stnum=`expr $stnum + 8`
		else
			if [ "${SUN_DT}" = 8505 -o "${SUN_DT}" = dlt ] ; then
				stnum=`expr $stnum + 16`
			fi
			if [ "${SUN_DT}" = hcart -o "${SUN_DT}" = dtf ] ; then
				stnum=`expr $stnum + 16`
			fi
			if [ "${SUN_DT}" = dlt2 -o "${SUN_DT}" = hcart2 ] ; then
				stnum=`expr $stnum + 16`
			fi
		fi

		case $1 in
		    1)	DRIVE1_STR=/dev/rst$stnum
			DRIVE1_STR_NR=/dev/nrst$stnum
			;;
		    2)	DRIVE2_STR=/dev/rst$stnum
			DRIVE2_STR_NR=/dev/nrst$stnum
			;;
		    3)	DRIVE3_STR=/dev/rst$stnum
			DRIVE3_STR_NR=/dev/nrst$stnum
			;;
		    4)	DRIVE4_STR=/dev/rst$stnum
			DRIVE4_STR_NR=/dev/nrst$stnum
			;;
		    5)	DRIVE5_STR=/dev/rst$stnum
			DRIVE5_STR_NR=/dev/nrst$stnum
			;;
		    6)	DRIVE6_STR=/dev/rst$stnum
			DRIVE6_STR_NR=/dev/nrst$stnum
			;;
		    7)	DRIVE7_STR=/dev/rst$stnum
			DRIVE7_STR_NR=/dev/nrst$stnum
			;;
		    8)	DRIVE8_STR=/dev/rst$stnum
			DRIVE8_STR_NR=/dev/nrst$stnum
			;;
		    9)	DRIVE9_STR=/dev/rst$stnum
			DRIVE9_STR_NR=/dev/nrst$stnum
			;;
		   10)	DRIVE10_STR=/dev/rst$stnum
			DRIVE10_STR_NR=/dev/nrst$stnum
			;;
		esac
	fi
}

# -----------------------------------------------------------------------------
#
#
make_alpha_drive_devs ()
{
	drive_number=$1
	DRIVE_TYPE=$2
	adapter=$4
	s_id=$3

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	case $DRIVE_TYPE in

	    8200|4mm)
		rew_denstr=l
		nrew_denstr=l
		;;
	    8505|4mm_compress|dlt|dlt2|hcart|hcart2|dtf|*)
		rew_denstr=h
		nrew_denstr=h
		;;
	esac

	logical_dev=`/usr/openv/volmgr/bin/lsdev phys_to_logical ${adapter} ${s_id}`
	if [ "X" = "${logical_dev}X" ] ; then
		make_dev ${adapter} ${s_id}
		logical_dev=`/usr/openv/volmgr/bin/lsdev phys_to_logical ${adapter} ${s_id}`
	fi

	rewdevfile=/dev/${logical_dev}${rew_denstr}
	nrewdevfile=/dev/n${logical_dev}${nrew_denstr}

	case $drive_number in
	     1) DRIVE1_STR="$rewdevfile"
		DRIVE1_STR_NR="$nrewdevfile"
		;;
	     2) DRIVE2_STR="$rewdevfile"
		DRIVE2_STR_NR="$nrewdevfile"
		;;
	     3) DRIVE3_STR="$rewdevfile"
		DRIVE3_STR_NR="$nrewdevfile"
		;;
	     4)	DRIVE4_STR="$rewdevfile"
		DRIVE4_STR_NR="$nrewdevfile"
		;;
	     5) DRIVE5_STR="$rewdevfile"
		DRIVE5_STR_NR="$nrewdevfile"
		;;
	     6) DRIVE6_STR="$rewdevfile"
		DRIVE6_STR_NR="$nrewdevfile"
		;;
	     7) DRIVE7_STR="$rewdevfile"
		DRIVE7_STR_NR="$nrewdevfile"
		;;
	     8) DRIVE8_STR="$rewdevfile"
		DRIVE8_STR_NR="$nrewdevfile"
		;;
	     9) DRIVE9_STR="$rewdevfile"
		DRIVE9_STR_NR="$nrewdevfile"
		;;
	    10) DRIVE10_STR="$rewdevfile"
		DRIVE10_STR_NR="$nrewdevfile"
		;;
	esac
}
# -----------------------------------------------------------------------------
#	make_robot_devs()
#
#	A generic function to create robot device files given the args
#	$1 SCSI ID / LUN(hp800) / Slot(Auspex SP) / SG path (Solaris)
#	$2 SCSI Adapter	(not used for Solaris)
#	$3 Robot type   (not used for Solaris)
make_robot_devs()
{

	case "$HOSTTYPE" in
	    sun)	make_sun_robot_devs $1 $2 $3 ;;
	    HP700)	make_hp700_robot_devs $1 $2 $3 ;;
	    HP800)	make_hp800_robot_devs $1 $2 $3 ;;
	    HPUX10)	make_hp10_robot_devs $1 $2 $3 ;;
	    SGI)	make_sgi_robot_devs $1 $2 $3 ;;
	    solaris)	make_solaris_robot_devs $1 ;;
	    RS6000)	make_rs6000_robot_devs $1 $2 $3 ;;
	    ALPHA)	make_alpha_robot_devs $1 $2 $3 ;;
	esac
}

# -----------------------------------------------------------------------------
make_rs6000_robot_devs()
{
	tmpid=$1
	tmpbus=$2
	tmplun=0

	if [ $lunone_changer -eq 1 ] ; then
		tmplun=1
	fi

	# scan lsdev output for the physical location of the scsi bus
	bus_addr=`/usr/sbin/lsdev -C -S a -l ${tmpbus} | cut -f3 -d' ' `

	if  [ "X" = "${bus_addr}X" ] ; then
		# tmpbus is not a valid scsi bus
		return 1
	fi

	if [ $common_device_file -ne 1 ] ; then
		# make sure the ovpass driver has been installed if not install it
		$ECHO "Checking if the ovpass driver is installed ..."
		/usr/openv/volmgr/bin/driver/install_ovpass

		t_opt="-t ovpass"
		# find the ovpass device at ${bus_addr}-${tmpid}${tmplun}
		# eg:
		#	ovpass0 Available 00-02-3,0 OpenVision Media Changer
		#
		if [ $aixversion -eq 3 ] ; then
			device_str=`/usr/sbin/lsdev -C -s scsi ${t_opt} | grep ${bus_addr}-${tmpid}${tmplun}`
		else
			device_str=`/usr/sbin/lsdev -C -s scsi ${t_opt} | grep ${bus_addr}-${tmpid},${tmplun}`
		fi
	else
		# don't need ovpass driver
		t_opt="-t ost"
		# find the device at ${bus_addr}, then ${tmpid}[,]${tmplun}
		# eg.
		#	rmt4 Available 00-04-01-5,0 Other SCSI Tape Drive
		#
		if [ $aixversion -eq 3 ] ; then
			device_str=`/usr/sbin/lsdev -C -s scsi ${t_opt} | grep ${bus_addr} | grep ${tmpid},${tmplun}`
		fi
	fi

	dev_name=`$ECHO "${device_str}" | cut -f1 -d' '`
	dev_status=`$ECHO "${device_str}" | cut -f2 -d' '`

	if [ "X" = "${dev_name}X" ] ; then
		if [ $common_device_file -ne 1 ] ; then
		  # no device was found, must create device
		  if [ $aixversion -eq 3 ] ; then
			$ECHO "/usr/sbin/mkdev -c media_changer -s scsi ${t_opt} -p ${tmpbus} -w ${tmpid}${tmplun}"
			tmp_dev=`/usr/sbin/mkdev -c media_changer -s scsi ${t_opt} -p ${tmpbus} -w ${tmpid}${tmplun} `
		  else
			$ECHO "/usr/sbin/mkdev -c media_changer -s scsi ${t_opt} -p ${tmpbus} -w ${tmpid},${tmplun}"
			tmp_dev=`/usr/sbin/mkdev -c media_changer -s scsi ${t_opt} -p ${tmpbus} -w ${tmpid},${tmplun} `
		  fi

		  if [ $? != 0 ] ; then
			# mkdev failed
			$ECHO "$tmp_dev"
			return 1
		  fi

		  dev_name=`$ECHO "$tmp_dev" | cut -f1 -d' '`
		else
		  # Assume IBM 3590 B11 stacker not using ovpass, but Atape instead.
		  # We can't use 'media_changer'. (haven't found any mkdev command that will work...)

		  $ECHO "Could not extract device name from:"
		  $ECHO "     ${device_str}"
		  $ECHO "Please verify physical connection and use 'smit' or 'cfgmgr' to create the device file."
		  return 1
		fi
	else
		# check to see if the [ovpass driver|device] is available
		if [ "${dev_status}" != "Available" ] ; then
			$ECHO "/usr/sbin/mkdev -l ${dev_name}"
			/usr/sbin/mkdev -l ${dev_name}
		fi
	fi

	if [ $common_device_file -ne 1 ] ; then
		ROBCTRL_PATH=/dev/${dev_name}
	else
		ROBCTRL_PATH=/dev/${dev_name}.1		# use non-rewind device name if common device file
	fi
	if [ ! -r "$ROBCTRL_PATH" ] ; then
		if [ $common_device_file -ne 1 ] ; then
		  if [ $aixversion -eq 3 ] ; then
			$ECHO "/usr/sbin/mkdev -c media_changer -s scsi ${t_opt} -p ${tmpbus} -w ${tmpid}${tmplun}"
			/usr/sbin/mkdev -c media_changer -s scsi ${t_opt} -p ${tmpbus} -w ${tmpid}${tmplun}
		  else
			$ECHO "/usr/sbin/mkdev -c media_changer -s scsi ${t_opt} -p ${tmpbus} -w ${tmpid},${tmplun}"
			/usr/sbin/mkdev -c media_changer -s scsi ${t_opt} -p ${tmpbus} -w ${tmpid},${tmplun}
		  fi
		else
		  $ECHO "Robotic device file ${ROBCTRL_PATH} is not established."
		  $ECHO "Please verify physical connection and use 'smit' or 'cfgmgr' to create the device file."
		  return 1
		fi
	fi
}

# -----------------------------------------------------------------------------
make_hp700_robot_devs()
{
	tmpid=$1
	tmpbus=$2
	tmpstring=$3
	tmplun=0

	if [ $lunone_changer -eq 1 ] ; then
		tmplun=1
	fi

	if [ "${tmpbus}" = core ] ; then
		adapter_str=201
	else
		adapter_str=4${tmpbus}0
	fi

	if [ $tmplun -eq 1 ] ; then
		ROBCTRL_PATH=/dev/rmt/${tmpstring}c${adapter_str}t${tmpid}l1
		if [ ! -r "$ROBCTRL_PATH" ] ; then
			make_dev $ROBCTRL_PATH c 105 0x${adapter_str}${tmpid}10
		fi
	else
		ROBCTRL_PATH=/dev/rmt/${tmpstring}c${adapter_str}t${tmpid}
		if [ ! -r "$ROBCTRL_PATH" ] ; then
			make_dev $ROBCTRL_PATH c 105 0x${adapter_str}${tmpid}00
		fi
	fi
}
# -----------------------------------------------------------------------------
make_hp10_robot_devs()
{
	tmpid=$1
	tmpbus=$2
	tmplun=0

	if [ $lunone_changer -eq 1 ] ; then
		tmplun=1
	fi

	# check if on an HP700
	/bin/hp9000s700
	not_hp700=$?
	if [ $not_hp700 -eq 1 ] ; then
		# is an hp800
		if [ $HW_PATH -eq 1 ] ; then
			dname="sctl"
		else
			dname="spt"
		fi
	else
		# assume it is an hp700
		dname="sctl"
	fi
	major=`lsdev -d ${dname} -h | awk '{print $1}'`
	if [ $HW_PATH -eq 1 ] ; then
		# tmpid is the HW path
		hw_path=$tmpid
		io_scan_info=`$IOSCAN -F -H ${tmpid}`
	else
		io_scan_info=`$IOSCAN -F -d ${dname} -I ${tmpid}`
		hw_path=`$ECHO ${io_scan_info} | awk 'BEGIN { FS = ":" } { print $11 }'`
		if [ "${hw_path}X" = "X" ] ; then
			$ECHO "${dname} device with instance ${tmpid} is not configured."
			return
		fi
	fi

	if [ $not_hp700 -eq 1 ] ; then
		# is NOT an hp700
		tmpbus=`$ECHO ${io_scan_info} | awk 'BEGIN { FS = ":" } { print $19 }'`
	else
		# is an hp700
		if [ $HW_PATH -eq 1 ] ; then
			#
			# For UNCLAIMED/UNKNOWN devices, ioscan -F column 19 (card instance)
			# is not accurate for hp700 running 10.0. So, obtain the real bus
			# by performing an ioscan on part of the HW path (up to the '.'),
			# then read the valid record associated with the ext_bus (first
			# entry returned). We could grep for ext_bus, but taking the first
			# entry is deemed safer at this time.
			#

			# format of H/W path is like: 2/0/1.5.0
			hw_prefix=`$ECHO ${hw_path} | awk 'BEGIN { FS = "." } { print $1 }'`
			tmpbus=`$IOSCAN -F -H ${hw_prefix} | head -1 | awk 'BEGIN { FS = ":" } { print $19 }'`
		else
			tmpbus=`$ECHO ${io_scan_info} | awk 'BEGIN { FS = ":" } { print $19 }'`
		fi
	fi
	tmpid=`$ECHO ${hw_path} | awk 'BEGIN { FS = "." } { field=NF - 1 } {print $field }'`
	tmplun=`$ECHO ${hw_path} | awk 'BEGIN { FS = "." } { field=NF } {print $field}'`

	# The bus number in the minor number must be hex.  For example,
	# if tmpbus is 10, minor number must have 0x0atl00.

	first=`expr $tmpbus / 16`

	if [ $first -eq 10 ] ; then
		first=a
	elif [ $first -eq 11 ] ; then
		first=b
	elif [ $first -eq 12 ] ; then
		first=c
	elif [ $first -eq 13 ] ; then
		first=d
	elif [ $first -eq 14 ] ; then
		first=e
	elif [ $first -eq 15 ] ; then
		first=f
	fi

	rem=`expr $tmpbus % 16`

	if [ $rem -lt 10 ] ; then
		adapter_str=${first}${rem}
	elif [ $rem -eq 10 ] ; then
		adapter_str="${first}a"
	elif [ $rem -eq 11 ] ; then
		adapter_str="${first}b"
	elif [ $rem -eq 12 ] ; then
		adapter_str="${first}c"
	elif [ $rem -eq 13 ] ; then
		adapter_str="${first}d"
	elif [ $rem -eq 14 ] ; then
		adapter_str="${first}e"
	elif [ $rem -eq 15 ] ; then
		adapter_str="${first}f"
	fi

	minor="0x${adapter_str}${tmpid}${tmplun}00"

	ROBCTRL_PATH=/dev/${dname}/c${tmpbus}t${tmpid}d${tmplun}

	if [ ! -r "$ROBCTRL_PATH" ] ; then
		if [ ! -d /dev/${dname} ] ; then
			mkdir /dev/${dname}
		fi

		make_dev $ROBCTRL_PATH c $major $minor
	fi
}

# -----------------------------------------------------------------------------
make_hp800_robot_devs()
{
	tmpid=$1
	tmpbus=$2

	ROBCTRL_PATH=/dev/rdrv${tmpid}
	if [ ! -r "$ROBCTRL_PATH" ] ; then
		minor=`expr $tmpid \* 256`
		make_dev /dev/rdrv${tmpid} c 105 $minor
	fi
}

# -----------------------------------------------------------------------------
make_sgi_robot_devs()
{
	tmpid=$1
	tmpbus=$2
	tmplun=0

	if [ $lunone_changer -eq 1 ] ; then
		tmplun=1
	fi

	ROBCTRL_PATH=/dev/scsi/sc${tmpbus}d${tmpid}l${tmplun}
	if [ ! -r "$ROBCTRL_PATH" ] ; then
		make_dev scsi
	fi

	if [ ! -r "$ROBCTRL_PATH" -a $tmplun -eq 1 ] ; then
		tmpminor=`expr 128 \* ${tmpbus} + 16 \* ${tmplun} + ${tmpid} `
		/sbin/mknod $ROBCTRL_PATH c 195 $tmpminor
		chmod 600 $ROBCTRL_PATH
	fi
}

# -----------------------------------------------------------------------------
make_solaris_robot_devs()
{
	ROBCTRL_PATH=$1
	# no need to create device file sg will create
}

# -----------------------------------------------------------------------------
make_sun_robot_devs()
{
	if [ $AUSPEX_SP -eq 1 ] ; then
		slotnum=$1

		ROBCTRL_PATH=/dev/asc${slotnum}
		# no need to create device file; sp will create

		if [ $lunone_changer -eq 1 ] ; then
			touch /dev/asc${slotnum}.1
		fi
	else
		tmpid=$1
		tmpbus=$2
		tmplun=0

		if [ $lunone_changer -eq 1 ] ; then
			tmplun=1
		fi

		ROBCTRL_PATH=/dev/sg/c${tmpbus}t${tmpid}d${tmplun}s0
		# no need to create device file sg will create
	fi
}

# -----------------------------------------------------------------------------
make_alpha_robot_devs()
{
	tmpid=$1
	tmpbus=$2
	tmpstr=$3
	tmplun=0

	if [ $lunone_changer -eq 1 ] ; then
		tmplun=1
	fi

	ROBCTRL_PATH=/dev/${tmpstr}c${tmpbus}t${tmpid}l${tmplun}

	if [ ! -r "$ROBCTRL_PATH" ] ; then
		tmpminor=`expr 256 \* ${tmpbus} + 16 \* ${tmpid} + ${tmplun} `
		$ECHO "/sbin/mknod $ROBCTRL_PATH c 38 $tmpminor"
		/sbin/mknod $ROBCTRL_PATH c 38 $tmpminor
		chmod 600 $ROBCTRL_PATH
	fi
}

# -----------------------------------------------------------------------------
get_drive_id()
{
	drv_num=$2
	if [ $NUMDRIVES -lt $2 ] ; then
		return
	fi

	if [ "$HOSTTYPE" = "solaris" ] ; then
		if [ "${ROBTYPE}" = ODL -o "${DRIVETYPE}X" = "OPTICALX" ] ; then
			get_solaris_logical_disk_id $drv_num
		else
			get_solaris_logical_drive_id $drv_num
		fi
		case $drv_num in
			0) DRIVE1=$VALUE ;;	# 0 means standalone; sets DRIVE1
			1) DRIVE1=$VALUE ;;
			2) DRIVE2=$VALUE ;;
			3) DRIVE3=$VALUE ;;
			4) DRIVE4=$VALUE ;;
			5) DRIVE5=$VALUE ;;
			6) DRIVE6=$VALUE ;;
			7) DRIVE7=$VALUE ;;
			8) DRIVE8=$VALUE ;;
			9) DRIVE9=$VALUE ;;
		       10) DRIVE10=$VALUE ;;
		esac

		if [ "$1" = "TLD drive" ] ; then
			get_tld_drive_type $2 $DRIVECLASS
			case $drv_num in
			    1) DRIVE1_TYPE=$medtype ;;
			    2) DRIVE2_TYPE=$medtype ;;
			    3) DRIVE3_TYPE=$medtype ;;
			    4) DRIVE4_TYPE=$medtype ;;
			    5) DRIVE5_TYPE=$medtype ;;
			    6) DRIVE6_TYPE=$medtype ;;
			    7) DRIVE7_TYPE=$medtype ;;
			    8) DRIVE8_TYPE=$medtype ;;
			    9) DRIVE9_TYPE=$medtype ;;
			   10) DRIVE10_TYPE=$medtype ;;
			esac
		fi
	else
		get_scsi_id "$1 $2" tape
		case $drv_num in
			1) DRIVE1=$VALUE ;;
			2) DRIVE2=$VALUE ;;
			3) DRIVE3=$VALUE ;;
			4) DRIVE4=$VALUE ;;
			5) DRIVE5=$VALUE ;;
			6) DRIVE6=$VALUE ;;
			7) DRIVE7=$VALUE ;;
			8) DRIVE8=$VALUE ;;
			9) DRIVE9=$VALUE ;;
		       10) DRIVE10=$VALUE ;;
		esac

		if [ "$1" = "TLD drive" ] ; then
			get_tld_drive_type $2 ALL
			case $drv_num in
			    1) DRIVE1_TYPE=$medtype ;;
			    2) DRIVE2_TYPE=$medtype ;;
			    3) DRIVE3_TYPE=$medtype ;;
			    4) DRIVE4_TYPE=$medtype ;;
			    5) DRIVE5_TYPE=$medtype ;;
			    6) DRIVE6_TYPE=$medtype ;;
			    7) DRIVE7_TYPE=$medtype ;;
			    8) DRIVE8_TYPE=$medtype ;;
			    9) DRIVE9_TYPE=$medtype ;;
			   10) DRIVE10_TYPE=$medtype ;;
			esac
		fi
	fi

}

# -----------------------------------------------------------------------------
get_NON_ROBOTIC()
{
	$ECHO "
	Drive Types
	-----------
	 1.  Exabyte 8200 tape drive
	 2.  Exabyte 8500 tape drive
	 3.  Exabyte 8500C, 8505 or 8900 (compression) tape drive
	 4.  HP optical disk drive
	 5.  4mm (DAT) tape drive
	 6.  4mm (DAT) compression tape drive
	 7.  DLT tape drive
	 8.  DTF tape drive
	 9.  Half-inch cartridge tape drive

	10.  Exit"
	get_number "\tEnter Choice" 1 10
	save_value=$VALUE

	GOODCHOICE=""
	case $save_value in
	     1) DRIVETYPE=8200
		if [ $AUSPEX_SP -eq 1 ] ; then
			GOODCHOICE="8mm devices"
		fi
		;;
	     2) DRIVETYPE=8500
		if [ $AUSPEX_SP -eq 1 ] ; then
			GOODCHOICE="8mm devices"
		fi
		;;
	     3) DRIVETYPE=8505
		if [ $AUSPEX_SP -eq 1 ] ; then
			GOODCHOICE="8mm devices"
		fi
		;;
	     4) DRIVETYPE=OPTICAL
		if [ "$HOSTTYPE" = ALPHA ] ; then
			$ECHO "
Optical disks are not supported on DEC Alpha.
"
			exit 1
		elif [ $AUSPEX_SP -eq 1 ] ; then
			GOODCHOICE="Optical disks"
		fi
		;;
	     5) DRIVETYPE=4mm
		if [ $AUSPEX_SP -eq 1 ] ; then
			GOODCHOICE="4mm devices"
		fi
		;;
	     6) DRIVETYPE=4mm_compress
		if [ $AUSPEX_SP -eq 1 ] ; then
			GOODCHOICE="4mm devices"
		fi
		;;
	     7) DRIVETYPE=dlt
		;;
	     8) DRIVETYPE=dtf
		if [ $AUSPEX_SP -eq 1 ] ; then
			GOODCHOICE="dtf devices"
		fi
		;;
	     9) DRIVETYPE=hcart
		if [ $AUSPEX_SP -eq 1 ] ; then
			GOODCHOICE="Half-inch cartridge devices"
		fi
		;;
	     10) exit 1
		;;
	esac
	if [ "N${GOODCHOICE}" != "N" ] ; then
		$ECHO "
$GOODCHOICE are not supported on the Auspex Storage Processor.
"
		exit 1
	fi
}
# -----------------------------------------------------------------------------
#	get_solaris_logical_disk_id()
#
#  $1 - robot drive number (0 for standalone drive)
#
get_solaris_logical_disk_id()
{
	robotdrvnum=$1

	if [ $sgscan_done -eq 0 ] ; then
		$ECHO "Scanning for disks connected to this system ..."
		$ECHO "(This could take a few minutes.)"
		$ECHO ""

		# ensure we only get LUN 0's even if sgscan was modified
		$VMSGSCAN all 2>$sgscan_err_file | grep "l0:" > $sgscan_out_file
		sgscan_done=1
	fi
	# check to see if previous sgscan output has been deleted or moved
	if [ ! -f $sgscan_out_file ] ; then
		$ECHO "Scanning for disks connected to this system ..."
		$ECHO "(This could take a few minutes.)"
		$ECHO ""

		# ensure we only get LUN 0's even if sgscan was modified
		$VMSGSCAN all 2>$sgscan_err_file | grep "l0:" > $sgscan_out_file
	fi

	disk_list="`cat $sgscan_out_file | grep Disk`"
	if [ -z "$disk_list" ] ; then
		disk_count=0
	else
		disk_count=`$ECHO "$disk_list" | wc -l`
	fi
	if [ $disk_count -eq 0 ] ; then
		$ECHO "
No SCSI-attached disk devices could be detected.
Please attach all peripherals, reconfigure the system, and re-run this script."
		clean_and_exit 1
	fi
	exit_choice=`expr $disk_count + 1`

	if [ "$robotdrvnum" -eq 0 ] ; then
		$ECHO "
Please select the disk device to be configured as a standalone optical drive."
	else
		$ECHO "
Please select the disk device to be configured as $ROBTYPE robot drive number $robotdrvnum."
	fi

	$ECHO "
\tSCSI-attached Disk Devices:

\t     Vendor  Model             SCSI Disk Path    SCSI Control (SG) Path
\t     ------- ----------------  ----------------  ----------------------"
	#
	# disk list format is:
	# /dev/sg/c1t0l0: Disk (/dev/rdsk/c1t0d0): "SONY    SMO-F541"
	#
	# Note: the substring within awk is to separate out the "/dev/rdsk/c1t0d0" part
	# of field 2
	#

	$ECHO "$disk_list" | awk 'BEGIN { FS = ":" } { printf "\t%2d.%-28s%-12s  (%s)\n", NR, $3, substr($2,8,length($2)-8), $1 }'
	$ECHO ""	
	if [ $exit_choice -gt 9 ] ; then
		$ECHO "\t${exit_choice}. None of the above"
		get_number "\tEnter Choice" 1 $exit_choice
	else
		$ECHO "\t ${exit_choice}. None of the above"
		get_number "\t Enter Choice" 1 $exit_choice
	fi

	if [ $VALUE -eq "$exit_choice" ] ; then
		$ECHO "
If your SCSI-attached disk device was not detected, please verify the peripheral's
SCSI-attachment, reconfigure the system, and re-run this script."
		clean_and_exit 1
	fi

	#
	# Now, get "c1t0d0" component of the line corresponding to the choice.
	# (We go all the way back to tmp file because the sed filter won't work
	# with the newlines embedded in the "disk list" shell variable.)
	#

	VALUE=`cat $sgscan_out_file | grep Disk | sed -n "$VALUE p" | nawk 'BEGIN { FS = "[()]" } { print $2 }' | nawk 'BEGIN { FS = "/" } { print $4 }'`
}
# -----------------------------------------------------------------------------
#	get_solaris_logical_drive_id()
#
#  $1 - robot drive number (0 for standalone drive)
#  $2 - (optional) key (LUN1_PARTNER or LUN0_ROBOTIC_SHARED)
#  $3 - robotic (SG) path, if key is LUN1_PARTNER or LUN0_ROBOTIC_SHARED
#
get_solaris_logical_drive_id()
{
	robotdrvnum=$1
	key=$2		# optionally field: LUN1_PARTNER or LUN0_ROBOTIC_SHARED
	if [ "${key}X" = LUN1_PARTNERX ] ; then
		lun1_sg_path=$3	# robotic (SG) path if key = LUN1_PARTNER
	elif [ "${key}X" = LUN0_ROBOTIC_SHAREDX ] ; then
		lun0_sg_path=$3	# robotic (SG) path if key = LUN0_ROBOTIC_SHARED
	fi

	if [ $sgscan_done -eq 0 ] ; then
		$ECHO "Scanning for tape devices connected to this system ..."
		$ECHO "(This could take a few minutes.)"
		$ECHO ""

		# ensure we only get LUN 0's even if sgscan was modified
		$VMSGSCAN all 2>$sgscan_err_file | grep "l0:" > $sgscan_out_file
		sgscan_done=1
	fi
	# check to see if previous sgscan output has been deleted or moved
	if [ ! -f $sgscan_out_file ] ; then
		$ECHO "Scanning for tape devices connected to this system ..."
		$ECHO "(This could take a few minutes.)"
		$ECHO ""

		# ensure we only get LUN 0's even if sgscan was modified
		$VMSGSCAN all 2>$sgscan_err_file | grep "l0:" > $sgscan_out_file
	fi

	tape_list="`cat $sgscan_out_file | grep Tape`"
	if [ -z "$tape_list" ] ; then
		tape_count=0
	else
		tape_count=`$ECHO "$tape_list" | wc -l`
	fi
	if [ $tape_count -eq 0 ] ; then
		$ECHO "
No SCSI-attached tape devices could be detected.
Please attach all peripherals, reconfigure the system, and re-run this script."
		clean_and_exit 1
	fi
	exit_choice=`expr $tape_count + 1`

	if [ "${key}X" = LUN1_PARTNERX ] ; then
		if [ "${lun1_sg_path}X" = "X" ] ; then
			$ECHO "
Cannot determine drive path for this device with a non-zero logical unit number.
Please ensure that Media Manager (and this script) supports your device, and
contact support if necessary."
			clean_and_exit 1
		fi
		# change the LUN to 0 (eg. /dev/sg/c1t3l1 into /dev/sg/c1t3l0)
		lun0_sg_path=`echo ${lun1_sg_path} | awk '{ print substr($1,1,length($1)-1) 0 }'`
	elif [ "${ROBTYPE}" = TSH ] ; then
		if [ "${lun0_sg_path}X" = "X" ] ; then
			$ECHO "
Cannot determine drive path for this device with shared SCSI ID between the
robotic and drive functions.  Please ensure that Media Manager (and this script)
supports your device, and contact support if necessary."
			clean_and_exit 1
		fi
	elif [ "${ROBTYPE}" = TC4 -o "${ROBTYPE}" = TC8 ] ; then
		if [ $robotdrvnum -eq 1 ] ; then
			driveletter=A
		else
			driveletter=B
		fi
		$ECHO "
Please select the tape device to be configured as $ROBTYPE robot drive $driveletter."
	elif [ "$robotdrvnum" -eq 0 ] ; then
		$ECHO "
Please select the tape device to be configured as a standalone tape drive."
	else
		$ECHO "
Please select the tape device to be configured as $ROBTYPE robot drive number $robotdrvnum."
	fi

	if [ "${key}X" = LUN1_PARTNERX ] ; then
		# for obtaining the drive path given the LUN 1 robotics path 
		VALUE=`cat $sgscan_out_file | grep Tape | grep ${lun0_sg_path} | nawk 'BEGIN { FS = "[()]" } { print $2 }' | nawk 'BEGIN { FS = "/" } { print $4 }'`
		if [ "${ROBTYPE}" = TL4 ] ; then
			DRIVECLASS=4MM
		elif [ "${ROBTYPE}" = TSD ] ; then
			DRIVECLASS=DLT
		else
			DRIVECLASS=DLT	# default
		fi
	elif [ "${key}X" = LUN0_ROBOTIC_SHAREDX ] ; then
		# for obtaining the drive path given the LUN 0 robotic path
		VALUE=`cat $sgscan_out_file | grep Tape | grep ${lun0_sg_path} | nawk 'BEGIN { FS = "[()]" } { print $2 }' | nawk 'BEGIN { FS = "/" } { print $4 }'`
		DRIVECLASS=HCART	# assume TSH
	else
		$ECHO "
\tSCSI-attached Tape Devices:

\t     Vendor  Model             SCSI Tape Path  SCSI Control (SG) Path
\t     ------- ----------------  --------------  ----------------------"
		#
		# tape list format is:
		# /dev/sg/c2t5l0: Tape (/dev/rmt/11): "QUANTUM DLT7000" 
		#
		# Note: the substring within awk is to separate out the "/dev/rmt/11" part
		# of field 2
		#

		$ECHO "$tape_list" | awk 'BEGIN { FS = ":" } { printf "\t%2d.%-28s%-12s    (%s)\n", NR, $3, substr($2,8,length($2)-8), $1 }'
		$ECHO ""	
		if [ $exit_choice -gt 9 ] ; then
			$ECHO "\t${exit_choice}. None of the above"
			get_number "\tEnter Choice" 1 $exit_choice
		else
			$ECHO "\t ${exit_choice}. None of the above"
			get_number "\t Enter Choice" 1 $exit_choice
		fi
		the_choice=$VALUE

		if [ $the_choice -eq "$exit_choice" ] ; then
			$ECHO "
If your SCSI-attached tape device was not detected, please verify that the
device is supported by Media Manager.  Then, verify the peripheral SCSI-
attachment, reconfigure the system, and re-run this script."
			clean_and_exit 1
		fi

		#
		# Now, get logical ID of the line corresponding to the choice.
		# (We go all the way back to tmp file because the sed filter won't work
		# with the newlines embedded in the "tape_list" shell variable.)
		# yes, we need nawk(1) here for the multi-character field separator
		#

		VALUE=`cat $sgscan_out_file | grep Tape | sed -n "$the_choice p" | nawk 'BEGIN { FS = "[()]" } { print $2 }' | nawk 'BEGIN { FS = "/" } { print $4 }'`

		#
		# Set DRIVECLASS based on SCSI inquiry string, to aid in displaying choices
		#

		DRIVECLASS=`cat $sgscan_out_file | grep Tape | sed -n "$the_choice p" | awk 'BEGIN { FS = ":" } { if ($3 ~ /DLT/) print "DLT" ; else if ($3 ~ /(IBM     03570|IBM     03590|STK     4890|STK     9490|STK     4781|STK     4791|STK     SD-3)/) print "HCART" ; else if ($3 ~ /SONY    GY-2120/) print "DTF" ; else if ($3 ~ /(EXB|IBM-85XL|SDX-300C)/) print "8MM" ; else if ($3 ~ /(HP354|C1537A|C1557A|SDT-5000)/) print "4MM" ; else print "ALL" }'`

	fi

	if [ -z "$VALUE" ] ; then
		$ECHO "
Cannot determine the drive path for this device.  It is possible that the
system was last reconfigured without the tape drive present or powered on.
Please verify that the system has been reconfigured to entirely recognize this
peripheral. Then, verify that this device is supported by Media Manager before
contacting support."
		clean_and_exit 1
	fi
}
# -----------------------------------------------------------------------------
get_solaris_robot_path()
#
#	$1 lun_mode - NO_LUN_1 or ALLOW_LUN_1
#	             (if ALLOW_LUN_1, we try to add lun1 media changer paths
#		      for specific devices like HP's C1537A)
{
	lun_mode=$1	# either NO_LUN_1 or ALLOW_LUN_1

	if [ $sgscan_done -eq 0 ] ; then
		$ECHO "Scanning for media changers connected to this system ..."
		$ECHO "(This could take a few minutes.)"
		$ECHO ""
		# ensure we only get LUN 0's even if sgscan was modified
		$VMSGSCAN all 2>$sgscan_err_file | grep "l0:" > $sgscan_out_file
		sgscan_done=1
	fi

	if [ "${lun_mode}X" = "ALLOW_LUN_1X" ] ; then
		#
		# Robotics using LUN 1
		#
		changer_list="`cat $sgscan_out_file | egrep \"(\
HP      C1537|\
HP      C1553|\
DEC     TZ885|\
DEC     TZ887|\
DEC     DLT2700|\
Quantum DLT2500|\
Quantum DLT2700|\
Quantum DLT4500|\
Quantum DLT4700|\
QUANTUM DLT2140|\
Changer)\"	| sed 's/0: Tape (.*)/1: Changer/'`"
	elif [ "${ROBTYPE}" = TSH ] ; then
		#
		# TSH Robotics using tape path at LUN 0
		#
		changer_list="`cat $sgscan_out_file | grep IBM | grep 03590B11 | sed 's/0: Tape (.*)/0: Changer/'`"
	else
		changer_list="`cat $sgscan_out_file | grep Changer`"
	fi
	if [ -z "$changer_list" ] ; then
		changer_count=0
	else
		changer_count=`$ECHO "$changer_list" | wc -l`
	fi
	if [ "$changer_count" -eq 0 ] ; then
		if [ "${ROBTYPE}" = TSH ] ; then
			$ECHO "No SCSI-attached media changers supported by TSH robotics could be detected."
			$ECHO "Please attach the IBM 3590 B11 Stacker, reconfigure the system, and re-run"
			$ECHO "this script."
		else
			$ECHO "No SCSI-attached media changers could be detected."
			$ECHO "Please attach all peripherals, reconfigure the system, and re-run this script."
		fi
		clean_and_exit 1
	fi
	exit_choice=`expr $changer_count + 1`

	$ECHO "
Please select the media changer to be controlled using $ROBTYPE robotics.

\tSCSI-attached Media Changers:

\t     Vendor  Model             SCSI Control (SG) Path
\t     ------- ----------------  ----------------------"
	# format is:
	# /dev/sg/c2t6l0: Changer: "BHTi    QSx70"
	$ECHO "$changer_list" | awk 'BEGIN { FS = ":" } { printf "\t%2d.%-27s %-20s\n", NR, $3, $1 }'
	$ECHO ""	
	if [ $exit_choice -gt 9 ] ; then
		$ECHO "\t${exit_choice}. None of the above"
		get_number "\tEnter Choice" 1 $exit_choice
	else
		$ECHO "\t ${exit_choice}. None of the above"
		get_number "\t Enter Choice" 1 $exit_choice
	fi

	if [ $VALUE -eq "$exit_choice" ] ; then
		$ECHO "
If your SCSI-attached media changer was not detected, please verify that the
device is supported by Media Manager.  Then, verify the peripheral attachment,
reconfigure the system, and re-run this script."
		clean_and_exit 1
	fi

	if [ "${lun_mode}X" = "ALLOW_LUN_1X" ] ; then
		# do we need to go back to the tmp file and re-filter it?
		VALUE=`$ECHO "$changer_list" | sed -n "$VALUE p" | awk 'BEGIN { FS = ":" } { print $1 }'`
	elif [ "${ROBTYPE}" = TSH ] ; then
		VALUE=`cat $sgscan_out_file | grep IBM | grep 03590B11 | sed 's/0: Tape (.*)/0: Changer/' | sed -n "$VALUE p" | awk 'BEGIN { FS = ":" } { print $1 }'`
	else
		VALUE=`cat $sgscan_out_file | grep Changer | sed -n "$VALUE p" | awk 'BEGIN { FS = ":" } { print $1 }'`
	fi
}
# -----------------------------------------------------------------------------
make_NON_ROBOTIC_devs()
{

	NUMDRIVES=1
	ADAPTER=0

	get_drive_info

	make_drive_devs 1 $DRIVETYPE $DRIVE1 $ADAPTER

	missingpath=0

	if [ $DRIVETYPE = OPTICAL ] ; then
		check_odl_drive_path 1 $DRIVE1_CDEV_STR $DRIVE1_BDEV_STR $DRIVE1_VOLHDR_STR
	else
		check_drive_path 1 $DRIVE1_STR $DRIVE1_STR_NR
	fi

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}

# -----------------------------------------------------------------------------
get_drive_info()
{
	if [ "$HOSTTYPE" = "solaris" ] ; then
		if [ "${DRIVETYPE}" = OPTICAL ] ; then
			get_solaris_logical_disk_id 0
		else
			get_solaris_logical_drive_id 0
		fi
		DRIVE1=$VALUE
	elif [ $AUSPEX_SP -eq 1 ] ; then
		get_slot_numbers 1 "tape drives"
		DRIVE1=$VALUE1
	else
		if [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
			get_scsi_adapter "drive" "tape drives"
			ADAPTER=$VALUE
		else
			if [ $DRIVETYPE = OPTICAL ] ; then
				ioscan disk
			else
				ioscan tape_drive
			fi
		fi

		get_scsi_id "drive" tape_drive
		DRIVE1=$VALUE
	fi
}
# -----------------------------------------------------------------------------
make_TC4_devs()
{

	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_solaris_robot_path NO_LUN_1
		SCSI2_ROBOT=$VALUE	# it's an sg path, not a SCSI ID
		ADAPTER=0	# unused
	elif [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
		get_scsi_adapter "TC4" "robotic devices"
		ADAPTER=$VALUE
		get_scsi_id "TC4 SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	else
		ADAPTER=0
		get_scsi_id "TC4 SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	fi

	if [ "$HOSTTYPE" = HP800 -o "$HOSTTYPE" = HPUX10 ] ; then
		ioscan tape_drive
	fi

	print_alpha_drive_choices

	NUMDRIVES=2
	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_drive_id "TC4 drive A" 1
		get_drive_id "TC4 drive B" 2
	else
		get_scsi_id "TC4 drive A" tape_drive
		DRIVE1=$VALUE
		get_scsi_id "TC4 drive B" tape_drive
		DRIVE2=$VALUE
	fi

	# check for and make device files
	make_robot_devs $SCSI2_ROBOT $ADAPTER "tc4"

	get_4mm_drive_type "TC4 drive"

	make_drive_devs 1 $DRIVETYPE $DRIVE1 $ADAPTER
	make_drive_devs 2 $DRIVETYPE $DRIVE2 $ADAPTER

	missingpath=0

	check_robot_path ${ROBCTRL_PATH}
	check_drive_path 1 $DRIVE1_STR $DRIVE1_STR_NR
	check_drive_path 2 $DRIVE2_STR $DRIVE2_STR_NR

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}
# -----------------------------------------------------------------------------
make_TC8_devs()
{

	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_solaris_robot_path NO_LUN_1
		SCSI2_ROBOT=$VALUE	# it's an sg path, not a SCSI ID
		ADAPTER=0	# unused
	elif [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
		get_scsi_adapter "TC8" "robotic devices"
		ADAPTER=$VALUE
		get_scsi_id "TC8 SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	else
		ADAPTER=0
		get_scsi_id "TC8 SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	fi

	if [ "$HOSTTYPE" = HP800 -o "$HOSTTYPE" = HPUX10 ] ; then
		ioscan tape_drive
	fi

	NUMDRIVES=2
	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_drive_id "TC8 Exabyte drive A" 1
		get_drive_id "TC8 Exabyte drive B" 2
	else
		print_alpha_drive_choices

		get_scsi_id "TC8 Exabyte drive A" tape_drive
		DRIVE1=$VALUE
		get_scsi_id "TC8 Exabyte drive B" tape_drive
		DRIVE2=$VALUE
	fi

	# check for and make device files
	make_robot_devs $SCSI2_ROBOT $ADAPTER "tc8"

	get_exabyte_drive_type "TC8 drives"

	make_drive_devs 1 $DRIVETYPE $DRIVE1 $ADAPTER
	make_drive_devs 2 $DRIVETYPE $DRIVE2 $ADAPTER

	missingpath=0

	check_robot_path ${ROBCTRL_PATH}
	check_drive_path 1 $DRIVE1_STR $DRIVE1_STR_NR
	check_drive_path 2 $DRIVE2_STR $DRIVE2_STR_NR

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}
# -----------------------------------------------------------------------------
make_ODL_devs()
{

	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_solaris_robot_path NO_LUN_1
		SCSI2_ROBOT=$VALUE	# it's an sg path, not a SCSI ID
		ADAPTER=0	# unused
	elif [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
		get_scsi_adapter "ODL" "robotic devices"
		ADAPTER=$VALUE
		get_scsi_id "ODL SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	else
		ADAPTER=0
		get_scsi_id "ODL SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	fi

	get_number "Enter the number of drives in the ODL" 1 6
	NUMDRIVES=$VALUE

	if [ "$HOSTTYPE" = HP800 -o "$HOSTTYPE" = HPUX10 ] ; then
		ioscan disk
	fi

	print_alpha_optical_choices

	get_drive_id "ODL drive" 1
	get_drive_id "ODL drive" 2
	get_drive_id "ODL drive" 3
	get_drive_id "ODL drive" 4
	get_drive_id "ODL drive" 5
	get_drive_id "ODL drive" 6

	make_robot_devs $SCSI2_ROBOT $ADAPTER "odl"

	make_drive_devs 1 "OPTICAL" $DRIVE1 $ADAPTER
	make_drive_devs 2 "OPTICAL" $DRIVE2 $ADAPTER
	make_drive_devs 3 "OPTICAL" $DRIVE3 $ADAPTER
	make_drive_devs 4 "OPTICAL" $DRIVE4 $ADAPTER
	make_drive_devs 5 "OPTICAL" $DRIVE5 $ADAPTER
	make_drive_devs 6 "OPTICAL" $DRIVE6 $ADAPTER

	missingpath=0

	$ECHO You will be using ${ROBCTRL_PATH} for the robotics control.
	if [ ! -r "$ROBCTRL_PATH" ] ; then
		missingpath=1
		$ECHO "Robotics control path ${ROBCTRL_PATH} does NOT exist."
	fi

	check_odl_drive_path 1 $DRIVE1_CDEV_STR $DRIVE1_BDEV_STR $DRIVE1_VOLHDR_STR
	check_odl_drive_path 2 $DRIVE2_CDEV_STR $DRIVE2_BDEV_STR $DRIVE2_VOLHDR_STR
	check_odl_drive_path 3 $DRIVE3_CDEV_STR $DRIVE3_BDEV_STR $DRIVE3_VOLHDR_STR
	check_odl_drive_path 4 $DRIVE4_CDEV_STR $DRIVE4_BDEV_STR $DRIVE4_VOLHDR_STR
	check_odl_drive_path 5 $DRIVE5_CDEV_STR $DRIVE5_BDEV_STR $DRIVE5_VOLHDR_STR
	check_odl_drive_path 6 $DRIVE6_CDEV_STR $DRIVE6_BDEV_STR $DRIVE6_VOLHDR_STR

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}
# -----------------------------------------------------------------------------
make_sgi_odl_drive_devs()
{
	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	case $1 in
	     1) DRIVE1_CDEV_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE1}s7
		DRIVE1_BDEV_STR=/dev/dsk/dks${ADAPTER}d${DRIVE1}s7
		DRIVE1_VOLHDR_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE1}vh
		if [ ! -r "$DRIVE1_CDEV_STR" -o  ! -r "$DRIVE1_BDEV_STR" -o ! -r "$DRIVE1_VOLHDR_STR" ]
		then
			make_dev dks
		fi
		;;
	     2) DRIVE2_CDEV_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE2}s7
		DRIVE2_BDEV_STR=/dev/dsk/dks${ADAPTER}d${DRIVE2}s7
		DRIVE2_VOLHDR_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE2}vh
		if [ ! -r "$DRIVE2_CDEV_STR" -o  ! -r "$DRIVE2_BDEV_STR" -o ! -r "$DRIVE2_VOLHDR_STR" ]
		then
			make_dev dks
		fi
		;;
	     3) DRIVE3_CDEV_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE3}s7
		DRIVE3_BDEV_STR=/dev/dsk/dks${ADAPTER}d${DRIVE3}s7
		DRIVE3_VOLHDR_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE3}vh
		if [ ! -r "$DRIVE3_CDEV_STR" -o  ! -r "$DRIVE3_BDEV_STR" -o ! -r "$DRIVE3_VOLHDR_STR" ]
		then
			make_dev dks
		fi
		;;
	     4) DRIVE4_CDEV_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE4}s7
		DRIVE4_BDEV_STR=/dev/dsk/dks${ADAPTER}d${DRIVE4}s7
		DRIVE4_VOLHDR_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE4}vh
		if [ ! -r "$DRIVE4_CDEV_STR" -o  ! -r "$DRIVE4_BDEV_STR" -o ! -r "$DRIVE4_VOLHDR_STR" ]
		then
			make_dev dks
		fi
		;;
	     5) DRIVE5_CDEV_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE5}s7
		DRIVE5_BDEV_STR=/dev/dsk/dks${ADAPTER}d${DRIVE5}s7
		DRIVE5_VOLHDR_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE5}vh
		if [ ! -r "$DRIVE5_CDEV_STR" -o  ! -r "$DRIVE5_BDEV_STR" -o ! -r "$DRIVE5_VOLHDR_STR" ]
		then
			make_dev dks
		fi
		;;
	     6) DRIVE6_CDEV_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE6}s7
		DRIVE6_BDEV_STR=/dev/dsk/dks${ADAPTER}d${DRIVE6}s7
		DRIVE6_VOLHDR_STR=/dev/rdsk/dks${ADAPTER}d${DRIVE6}vh
		if [ ! -r "$DRIVE6_CDEV_STR" -o  ! -r "$DRIVE6_BDEV_STR" -o ! -r "$DRIVE6_VOLHDR_STR" ]
		then
			make_dev dks
		fi
		;;
	esac
}

# -----------------------------------------------------------------------------
#
#
make_odl_drive_hp10 ()
{
	drive_number=$1
	s_id=$2
	adapter=$3

	if [ $NUMDRIVES -lt $drive_number ] ; then
		return
	fi

	io_scan_info=`$IOSCAN -F -C disk -I ${s_id}`
	hw_path=`$ECHO ${io_scan_info} | awk 'BEGIN { FS = ":" } { print $11 }'`
	if [ "${hw_path}X" = "X" ] ; then
		$ECHO "Disk drive with instance number ${s_id} is not configured."
		return 1
	fi

	cntrl=`$ECHO ${io_scan_info} | awk 'BEGIN { FS = ":" } { print $19 }'`

	id=`$ECHO ${hw_path} | awk 'BEGIN { FS = "." } { field=NF - 1 } {print $field }'`
	lun=`$ECHO ${hw_path} | awk 'BEGIN { FS = "." } { field=NF } {print $field}'`

	blk_devfile=/dev/dsk/c${cntrl}t${id}d${lun}
	chr_devfile=/dev/rdsk/c${cntrl}t${id}d${lun}
	vh_devfile=/dev/rdsk/c${cntrl}t${id}d${lun}

	# make the device files

	if [ ! -r "$blk_devfile" -o  ! -r "$chr_devfile" ] ; then
		/usr/sbin/mksf -C disk -H ${hw_path}
		/usr/sbin/mksf -C disk -H ${hw_path} -r
	fi

	case $drive_number in
	     1)	DRIVE1_CDEV_STR="$chr_devfile"
		DRIVE1_BDEV_STR="$blk_devfile"
		DRIVE1_VOLHDR_STR="$vh_devfile"
		;;
	     2)	DRIVE2_CDEV_STR="$chr_devfile"
		DRIVE2_BDEV_STR="$blk_devfile"
		DRIVE2_VOLHDR_STR="$vh_devfile"
		;;
	     3)	DRIVE3_CDEV_STR="$chr_devfile"
		DRIVE3_BDEV_STR="$blk_devfile"
		DRIVE3_VOLHDR_STR="$vh_devfile"
		;;
	     4)	DRIVE4_CDEV_STR="$chr_devfile"
		DRIVE4_BDEV_STR="$blk_devfile"
		DRIVE4_VOLHDR_STR="$vh_devfile"
		;;
	     5)	DRIVE5_CDEV_STR="$chr_devfile"
		DRIVE5_BDEV_STR="$blk_devfile"
		DRIVE5_VOLHDR_STR="$vh_devfile"
		;;
	     6)	DRIVE6_CDEV_STR="$chr_devfile"
		DRIVE6_BDEV_STR="$blk_devfile"
		DRIVE6_VOLHDR_STR="$vh_devfile"
		;;
	esac


}

# -----------------------------------------------------------------------------
#
#
make_odl_drive_hp800 ()
{
	drive_number=$1
	s_id=$2
	adapter=$3

	if [ $NUMDRIVES -lt $drive_number ] ; then
		return
	fi

	blk_devfile=/dev/dsk/c${s_id}d0s2
	chr_devfile=/dev/rdsk/c${s_id}d0s2
	vh_devfile=/dev/rdsk/c${s_id}d0s2

	# make the device files

	if [ ! -r "$blk_devfile" -o  ! -r "$chr_devfile" ] ; then
		minor1=`expr 12 + 256 \* ${s_id} `
		minor2=`expr 6 + 256 \* ${s_id} `

		make_dev $blk_devfile b 7 $minor1
		make_dev $chr_devfile c 13 $minor1
		make_dev $vh_devfile c 13 $minor2
	fi

	case $drive_number in
	     1) DRIVE1_CDEV_STR="$chr_devfile"
		DRIVE1_BDEV_STR="$blk_devfile"
		DRIVE1_VOLHDR_STR="$vh_devfile"
		;;
	     2) DRIVE2_CDEV_STR="$chr_devfile"
		DRIVE2_BDEV_STR="$blk_devfile"
		DRIVE2_VOLHDR_STR="$vh_devfile"
		;;
	     3) DRIVE3_CDEV_STR="$chr_devfile"
		DRIVE3_BDEV_STR="$blk_devfile"
		DRIVE3_VOLHDR_STR="$vh_devfile"
		;;
	     4) DRIVE4_CDEV_STR="$chr_devfile"
		DRIVE4_BDEV_STR="$blk_devfile"
		DRIVE4_VOLHDR_STR="$vh_devfile"
		;;
	     5) DRIVE5_CDEV_STR="$chr_devfile"
		DRIVE5_BDEV_STR="$blk_devfile"
		DRIVE5_VOLHDR_STR="$vh_devfile"
		;;
	     6) DRIVE6_CDEV_STR="$chr_devfile"
		DRIVE6_BDEV_STR="$blk_devfile"
		DRIVE6_VOLHDR_STR="$vh_devfile"
		;;
	esac


}

# -----------------------------------------------------------------------------
make_sun_odl_drive_devs()
{
	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	get_sun_dev_info ${ADAPTER} $2 disk
	sdnum=`echo $devname | cut -c3-`

	case $1 in
	     1) DRIVE1_CDEV_STR=/dev/rsd${sdnum}g
		DRIVE1_BDEV_STR=/dev/sd${sdnum}g
		DRIVE1_VOLHDR_STR=/dev/rsd${sdnum}a
		;;
	     2) DRIVE2_CDEV_STR=/dev/rsd${sdnum}g
		DRIVE2_BDEV_STR=/dev/sd${sdnum}g
		DRIVE2_VOLHDR_STR=/dev/rsd${sdnum}a
		;;
	     3) DRIVE3_CDEV_STR=/dev/rsd${sdnum}g
		DRIVE3_BDEV_STR=/dev/sd${sdnum}g
		DRIVE3_VOLHDR_STR=/dev/rsd${sdnum}a
		;;
	     4) DRIVE4_CDEV_STR=/dev/rsd${sdnum}g
		DRIVE4_BDEV_STR=/dev/sd${sdnum}g
		DRIVE4_VOLHDR_STR=/dev/rsd${sdnum}a
		;;
	     5) DRIVE5_CDEV_STR=/dev/rsd${sdnum}g
		DRIVE5_BDEV_STR=/dev/sd${sdnum}g
		DRIVE5_VOLHDR_STR=/dev/rsd${sdnum}a
		;;
	     6) DRIVE6_CDEV_STR=/dev/rsd${sdnum}g
		DRIVE6_BDEV_STR=/dev/sd${sdnum}g
		DRIVE6_VOLHDR_STR=/dev/rsd${sdnum}a
		;;
	esac
}
# -----------------------------------------------------------------------------
#	make_solaris_odl_drive_devs()
# 
#  $1 - Drive Number
#  $2 - Drive's Logical (SG) Name, eg. "c0t1d0"
#
make_solaris_odl_drive_devs()
{
	drive_number=$1
	logical_id=$2

	if [ $NUMDRIVES -lt $drive_number ] ; then
		return
	fi

	blk_devfile=/dev/dsk/${logical_id}s6
	chr_devfile=/dev/rdsk/${logical_id}s6
	vh_devfile=/dev/rdsk/${logical_id}s0

	case $drive_number in
	     1) DRIVE1_CDEV_STR="$chr_devfile"
		DRIVE1_BDEV_STR="$blk_devfile"
		DRIVE1_VOLHDR_STR="$vh_devfile"
		;;
	     2) DRIVE2_CDEV_STR="$chr_devfile"
		DRIVE2_BDEV_STR="$blk_devfile"
		DRIVE2_VOLHDR_STR="$vh_devfile"
		;;
	     3) DRIVE3_CDEV_STR="$chr_devfile"
		DRIVE3_BDEV_STR="$blk_devfile"
		DRIVE3_VOLHDR_STR="$vh_devfile"
		;;
	     4) DRIVE4_CDEV_STR="$chr_devfile"
		DRIVE4_BDEV_STR="$blk_devfile"
		DRIVE4_VOLHDR_STR="$vh_devfile"
		;;
	     5) DRIVE5_CDEV_STR="$chr_devfile"
		DRIVE5_BDEV_STR="$blk_devfile"
		DRIVE5_VOLHDR_STR="$vh_devfile"
		;;
	     6) DRIVE6_CDEV_STR="$chr_devfile"
		DRIVE6_BDEV_STR="$blk_devfile"
		DRIVE6_VOLHDR_STR="$vh_devfile"
		;;
	esac
}
# -----------------------------------------------------------------------------
#
#
make_rs6000_odl_drive_devs()
{
	drive_number=$1
	s_id=$2
	adapter=$3

	if [ $NUMDRIVES -lt $drive_number ] ; then
		return
	fi

	# scan lsdev output for the physical location of the scsi bus
	bus_addr=`/usr/sbin/lsdev -C -S a -l ${adapter} | cut -f3 -d' ' `

	if  [ "X" = "${bus_addr}X" ] ; then
		# adapter is not a valid scsi bus
		$ECHO "${adapter} is not a valid SCSI bus, or is not available."
		re_run 1
	fi

	if [ $aixversion -eq 3 ] ; then
		device_str=`/usr/sbin/lsdev -C -s scsi -c disk -t osdisk | grep "${bus_addr}-00-${s_id}0"`
	else
		device_str=`/usr/sbin/lsdev -C -s scsi -c disk -t osdisk | grep "${bus_addr}-00-${s_id},0"`
	fi

	dev_name=`$ECHO "${device_str}" | cut -f1 -d' '`
	dev_status=`$ECHO "${device_str}" | cut -f2 -d' '`

	if [ "X" = "${dev_name}X" ] ; then
		# no device was found, must create device
		if [ $aixversion -eq 3 ] ; then
			$ECHO "/usr/sbin/mkdev -c disk -s scsi -t osdisk -p ${adapter} -w ${s_id}0"
			tmp_dev=`/usr/sbin/mkdev -c disk -s scsi -t osdisk -p ${adapter} -w ${s_id}0 `
		else
	  		$ECHO "/usr/sbin/mkdev -c disk -s scsi -t osdisk -p ${adapter} -w ${s_id},0"
			tmp_dev=`/usr/sbin/mkdev -c disk -s scsi -t osdisk -p ${adapter} -w ${s_id},0 `
		fi

		if [ $? != 0 ] ; then
			# mkdev failed
			$ECHO "$tmp_dev"
			$ECHO "Could not create disk device on SCSI bus ${adapter} at id ${s_id}"
			re_run 1
		fi

		dev_name=`$ECHO "$tmp_dev" | cut -f1 -d' '`
	else
		# check to see if the tape drive is available
		if [ "${dev_status}" != "Available" ] ; then
			$ECHO "/usr/sbin/mkdev -l ${dev_name}"
			/usr/sbin/mkdev -l ${dev_name}
		fi
	fi

	blk_devfile=/dev/${dev_name}
	chr_devfile=/dev/r${dev_name}
	vh_devfile=/dev/r${dev_name}

	if [ ! -r "$blk_devfile" -o  ! -r "$chr_devfile" ] ; then
		if [ $aixversion -eq 3 ] ; then
			$ECHO "/usr/sbin/mkdev -c disk -s scsi -p ${adapter} -t osdisk -w ${s_id}0"
			/usr/sbin/mkdev -c disk -s scsi -p ${adapter} -t osdisk -w ${s_id}0
		else
			$ECHO "/usr/sbin/mkdev -c disk -s scsi -p ${adapter} -t osdisk -w ${s_id},0"
			/usr/sbin/mkdev -c disk -s scsi -p ${adapter} -t osdisk -w ${s_id},0
		fi

		if [ $? != 0 ] ; then
			$ECHO "Could not create disk device on SCSI bus ${adapter} at id ${s_id}"
			re_run 1
		fi

	fi

	case $drive_number in
	     1)	DRIVE1_CDEV_STR="$chr_devfile"
		DRIVE1_BDEV_STR="$blk_devfile"
		DRIVE1_VOLHDR_STR="$vh_devfile"
		;;
	     2)	DRIVE2_CDEV_STR="$chr_devfile"
		DRIVE2_BDEV_STR="$blk_devfile"
		DRIVE2_VOLHDR_STR="$vh_devfile"
		;;
	     3)	DRIVE3_CDEV_STR="$chr_devfile"
		DRIVE3_BDEV_STR="$blk_devfile"
		DRIVE3_VOLHDR_STR="$vh_devfile"
		;;
	     4)	DRIVE4_CDEV_STR="$chr_devfile"
		DRIVE4_BDEV_STR="$blk_devfile"
		DRIVE4_VOLHDR_STR="$vh_devfile"
		;;
	     5)	DRIVE5_CDEV_STR="$chr_devfile"
		DRIVE5_BDEV_STR="$blk_devfile"
		DRIVE5_VOLHDR_STR="$vh_devfile"
		;;
	     6)	DRIVE6_CDEV_STR="$chr_devfile"
		DRIVE6_BDEV_STR="$blk_devfile"
		DRIVE6_VOLHDR_STR="$vh_devfile"
		;;
	esac


}
# -----------------------------------------------------------------------------
#
#
make_odl_drive_hp ()
{
	adapter=$1
	s_id=$2
	drive_number=$3

	if test "$adapter" = core
	then
		bus_adapter=201
	else
		bus_adapter=4${adapter}0
	fi

	blk_devfile=/dev/dsk/c${bus_adapter}d${s_id}s0
	chr_devfile=/dev/rdsk/c${bus_adapter}d${s_id}s0

	# make the device files

	if [ ! -r "$blk_devfile" -o  ! -r "$chr_devfile" ] ; then
		make_dev $blk_devfile b 7 0x${bus_adapter}${s_id}00
		make_dev $chr_devfile c 47 0x${bus_adapter}${s_id}00
	fi

	case $drive_number in
	     1)	DRIVE1_CDEV_STR="$chr_devfile"
		DRIVE1_BDEV_STR="$blk_devfile"
		DRIVE1_VOLHDR_STR="$chr_devfile"
		;;
	     2)	DRIVE2_CDEV_STR="$chr_devfile"
		DRIVE2_BDEV_STR="$blk_devfile"
		DRIVE2_VOLHDR_STR="$chr_devfile"
		;;
	     3)	DRIVE3_CDEV_STR="$chr_devfile"
		DRIVE3_BDEV_STR="$blk_devfile"
		DRIVE3_VOLHDR_STR="$chr_devfile"
		;;
	     4)	DRIVE4_CDEV_STR="$chr_devfile"
		DRIVE4_BDEV_STR="$blk_devfile"
		DRIVE4_VOLHDR_STR="$chr_devfile"
		;;
	     5)	DRIVE5_CDEV_STR="$chr_devfile"
		DRIVE5_BDEV_STR="$blk_devfile"
		DRIVE5_VOLHDR_STR="$chr_devfile"
		;;
	     6)	DRIVE6_CDEV_STR="$chr_devfile"
		DRIVE6_BDEV_STR="$blk_devfile"
		DRIVE6_VOLHDR_STR="$chr_devfile"
		;;
	esac


}
# -----------------------------------------------------------------------------
check_odl_drive_path()
{
	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	$ECHO You will be using $2 for the drive $1 character device name.
	if [ ! -r "$2" ] ; then
		missingpath=1
		$ECHO "Drive $1 character device path $2 does NOT exist."
	fi
	$ECHO You will be using $3 for the drive $1 block device name.
	if [ ! -r "$3" ] ; then
		missingpath=1
		$ECHO "Drive $1 block device path $3 does NOT exist."
	fi
	if [ "$HOSTTYPE" != HP700 -a "$HOSTTYPE" != HPUX10 -a "$HOSTTYPE" != RS6000 -a "$HOSTTYPE" != HP800 ]
	then
		$ECHO You will be using $4 for the drive $1 volume header device name.
		if [ ! -r "$4" ] ; then
			missingpath=1
			$ECHO "Drive $1 volume header device path $4 does NOT exist."
		fi
	fi
}
# -----------------------------------------------------------------------------
make_TL8_devs()
{

	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_solaris_robot_path NO_LUN_1
		SCSI2_ROBOT=$VALUE	# it's an sg path, not a SCSI ID
		ADAPTER=0	# unused
	elif [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
		get_scsi_adapter "TL8" "robotic devices"
		ADAPTER=$VALUE
		get_scsi_id "TL8 SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	else
		ADAPTER=0
		get_scsi_id "TL8 SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	fi

	get_number "Enter the number of drives in the TL8" 1 6
	NUMDRIVES=$VALUE

	if [ "$HOSTTYPE" = HP800 -o "$HOSTTYPE" = HPUX10 ] ; then
		ioscan tape_drive
	fi

	print_alpha_drive_choices

	get_drive_id "TL8 drive" 1
	get_drive_id "TL8 drive" 2
	get_drive_id "TL8 drive" 3
	get_drive_id "TL8 drive" 4
	get_drive_id "TL8 drive" 5
	get_drive_id "TL8 drive" 6

	get_exabyte_drive_type "TL8 drives"

	make_robot_devs $SCSI2_ROBOT $ADAPTER "tl8"

	make_drive_devs 1 $DRIVETYPE $DRIVE1 $ADAPTER
	make_drive_devs 2 $DRIVETYPE $DRIVE2 $ADAPTER
	make_drive_devs 3 $DRIVETYPE $DRIVE3 $ADAPTER
	make_drive_devs 4 $DRIVETYPE $DRIVE4 $ADAPTER
	make_drive_devs 5 $DRIVETYPE $DRIVE5 $ADAPTER
	make_drive_devs 6 $DRIVETYPE $DRIVE6 $ADAPTER

	missingpath=0

	check_robot_path ${ROBCTRL_PATH}

	check_drive_path 1 $DRIVE1_STR $DRIVE1_STR_NR
	check_drive_path 2 $DRIVE2_STR $DRIVE2_STR_NR
	check_drive_path 3 $DRIVE3_STR $DRIVE3_STR_NR
	check_drive_path 4 $DRIVE4_STR $DRIVE4_STR_NR
	check_drive_path 5 $DRIVE5_STR $DRIVE5_STR_NR
	check_drive_path 6 $DRIVE6_STR $DRIVE6_STR_NR

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}
# -----------------------------------------------------------------------------
make_TLD_devs()
{

	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_solaris_robot_path NO_LUN_1
		SCSI2_ROBOT=$VALUE	# it's an sg path, not a SCSI ID
		ADAPTER=0	# unused
	elif [ $AUSPEX_SP -eq 1 ] ; then
		# only SCSI robotic control on Auspex Storage Processor (SP)
		get_slot_numbers "TLD" "robotic devices"
		SCSI2_ROBOT=$VALUE
	else
		if [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
			get_scsi_adapter "TLD" "robotic devices"
			ADAPTER=$VALUE
		else
			ADAPTER=0
		fi
		get_scsi_id "TLD SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	fi

	get_number "Enter the number of drives in the TLD" 1 10
	NUMDRIVES=$VALUE

	if [ "$HOSTTYPE" = HP800 -o "$HOSTTYPE" = HPUX10 ] ; then
		ioscan tape_drive
	fi

	print_alpha_drive_choices

	if [ $AUSPEX_SP -eq 1 ] ; then
		get_slot_numbers $NUMDRIVES "tape drives"
		DRIVE1=$VALUE1
		DRIVE2=$VALUE2
		DRIVE3=$VALUE3
		DRIVE4=$VALUE4
		DRIVE5=$VALUE5
		DRIVE6=$VALUE6
		DRIVE7=$VALUE7
		DRIVE8=$VALUE8
		DRIVE9=$VALUE9
		DRIVE10=$VALUE10
		# Only support dlt on Auspex SP
		DRIVE1_TYPE=dlt
		DRIVE2_TYPE=dlt
		DRIVE3_TYPE=dlt
		DRIVE4_TYPE=dlt
		DRIVE5_TYPE=dlt
		DRIVE6_TYPE=dlt
		DRIVE7_TYPE=dlt
		DRIVE8_TYPE=dlt
		DRIVE9_TYPE=dlt
		DRIVE10_TYPE=dlt
	else
		get_drive_id "TLD drive" 1
		get_drive_id "TLD drive" 2
		get_drive_id "TLD drive" 3
		get_drive_id "TLD drive" 4
		get_drive_id "TLD drive" 5
		get_drive_id "TLD drive" 6
		get_drive_id "TLD drive" 7
		get_drive_id "TLD drive" 8
		get_drive_id "TLD drive" 9
		get_drive_id "TLD drive" 10
	fi

	# check for and make device files
	make_robot_devs $SCSI2_ROBOT $ADAPTER "tld"

	make_drive_devs 1 $DRIVE1_TYPE $DRIVE1 $ADAPTER
	make_drive_devs 2 $DRIVE2_TYPE $DRIVE2 $ADAPTER
	make_drive_devs 3 $DRIVE3_TYPE $DRIVE3 $ADAPTER
	make_drive_devs 4 $DRIVE4_TYPE $DRIVE4 $ADAPTER
	make_drive_devs 5 $DRIVE5_TYPE $DRIVE5 $ADAPTER
	make_drive_devs 6 $DRIVE6_TYPE $DRIVE6 $ADAPTER
	make_drive_devs 7 $DRIVE7_TYPE $DRIVE7 $ADAPTER
	make_drive_devs 8 $DRIVE8_TYPE $DRIVE8 $ADAPTER
	make_drive_devs 9 $DRIVE9_TYPE $DRIVE9 $ADAPTER
	make_drive_devs 10 $DRIVE10_TYPE $DRIVE10 $ADAPTER

	missingpath=0

	check_robot_path ${ROBCTRL_PATH}

	check_drive_path 1 $DRIVE1_STR $DRIVE1_STR_NR
	check_drive_path 2 $DRIVE2_STR $DRIVE2_STR_NR
	check_drive_path 3 $DRIVE3_STR $DRIVE3_STR_NR
	check_drive_path 4 $DRIVE4_STR $DRIVE4_STR_NR
	check_drive_path 5 $DRIVE5_STR $DRIVE5_STR_NR
	check_drive_path 6 $DRIVE6_STR $DRIVE6_STR_NR
	check_drive_path 7 $DRIVE7_STR $DRIVE7_STR_NR
	check_drive_path 8 $DRIVE8_STR $DRIVE8_STR_NR
	check_drive_path 9 $DRIVE9_STR $DRIVE9_STR_NR
	check_drive_path 10 $DRIVE10_STR $DRIVE10_STR_NR

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}
# -----------------------------------------------------------------------------
make_TSD_devs()
{

	$ECHO "
 TSD software supports the ADIC VLS DLT, HP DLT Autoloader 418,
 Sun StorEdge L280 and Quantum DLT2700/DLT4500/DLT4700 stackers.
"
	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_solaris_robot_path ALLOW_LUN_1
		SCSI2_ROBOT=$VALUE	# it's an sg path, not a SCSI ID
		if [ "`$ECHO $SCSI2_ROBOT | awk '{ print substr($1,length($1),1) }'" = "1" ] ; then
			lunone_changer=1
		else
			lunone_changer=0
		fi
		ADAPTER=0	# unused
		NUMDRIVES=1
		if [ $lunone_changer -eq 1 ] ; then
			get_solaris_logical_drive_id 1 LUN1_PARTNER $SCSI2_ROBOT
			DRIVE1=$VALUE
		else
			get_drive_id "TSD DLT drive" 1
		fi
	else
		$ECHO "
	TSD Library Types
	---------------------
	1.  ADIC VLS DLT or HP DLT Autoloader 418 or Sun StorEdge L280
	2.  Quantum DLT2700/DLT4500/DLT4700"
		get_number "\tEnter library type" 1 2
		case $VALUE in
			1) lunone_changer=0 ;;
			2) lunone_changer=1 ;;
		esac

		if [ $AUSPEX_SP -eq 1 ] ; then
			# only SCSI robotic control on Auspex Storage Processor (SP)
			get_slot_numbers "TSD" "robotic devices"
			SCSI2_ROBOT=$VALUE
		elif [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
			get_scsi_adapter "TSD" "robotic devices"
			ADAPTER=$VALUE
		else
			ADAPTER=0
		fi

		NUMDRIVES=1

		if [ $AUSPEX_SP -eq 1 ] ; then
			if [ $lunone_changer -eq 1 ] ; then
				DRIVE1=$SCSI2_ROBOT
			else
				get_slot_numbers $NUMDRIVES "tape drives"
				DRIVE1=$VALUE1
			fi
		elif [ $lunone_changer -eq 1 -a "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
			get_scsi_id "TSD SCSI robotic control and drive" sctl
			SCSI2_ROBOT=$VALUE
			DRIVE1=$SCSI2_ROBOT
		else
			get_scsi_id "TSD SCSI robotic control" sctl
			SCSI2_ROBOT=$VALUE

			if [ "$HOSTTYPE" = HP800 -o "$HOSTTYPE" = HPUX10 ] ; then
				ioscan tape_drive
			fi

			print_alpha_drive_choices

			get_drive_id "TSD DLT drive" 1
		fi
	fi

	# check for and make device files
	make_robot_devs $SCSI2_ROBOT $ADAPTER "tsd"

	make_drive_devs 1 dlt $DRIVE1 $ADAPTER

	missingpath=0

	check_robot_path ${ROBCTRL_PATH}

	check_drive_path 1 $DRIVE1_STR $DRIVE1_STR_NR

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}
# -----------------------------------------------------------------------------
make_TL4_devs()
{

	$ECHO "
TL4 software supports the ADIC VLS Autochanger and HP C1560B DAT Stacker.
"
	if [ "$HOSTTYPE" = "solaris" ] ; then
		# TODO - search for LUN 1 changers
		get_solaris_robot_path ALLOW_LUN_1
		SCSI2_ROBOT=$VALUE	# it's an sg path, not a SCSI ID
		if [ "`$ECHO $SCSI2_ROBOT | awk '{ print substr($1,length($1),1) }'" = "1" ] ; then
			lunone_changer=1
		else
			lunone_changer=0
		fi
		ADAPTER=0	# unused
		if [ $lunone_changer -eq 1 ] ; then
			NUMDRIVES=1
			get_solaris_logical_drive_id 1 LUN1_PARTNER $SCSI2_ROBOT
			DRIVE1=$VALUE
		else
			get_number "Enter the number of drives in the TL4" 1 2
			NUMDRIVES=$VALUE
			get_drive_id "TL4 DAT drive" 1
			get_drive_id "TL4 DAT drive" 2
		fi
	else
		$ECHO "
	TL4 Library Types
	---------------------
	1.  ADIC VLS
	2.  HP C1560B"
		get_number "\tEnter library type" 1 2
		case $VALUE in
			1) lunone_changer=0 ;;
			2) lunone_changer=1 ;;
		esac

		if [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
			get_scsi_adapter "TL4" "robotic devices"
			ADAPTER=$VALUE
		else
			ADAPTER=0
		fi

		if [ $lunone_changer -eq 1 -a "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
			get_scsi_id "TL4 SCSI robotic control and drive" sctl
			SCSI2_ROBOT=$VALUE
			NUMDRIVES=1
			DRIVE1=$SCSI2_ROBOT
		else
			get_scsi_id "TL4 SCSI robotic control" sctl
			SCSI2_ROBOT=$VALUE
			if [ $lunone_changer -eq 1 ] ; then
				NUMDRIVES=1;
			else
				get_number "Enter the number of drives in the TL4" 1 2
				NUMDRIVES=$VALUE
			fi
			if [ "$HOSTTYPE" = HP800 -o "$HOSTTYPE" = HPUX10 ] ; then
				ioscan tape_drive
			fi

			print_alpha_drive_choices

			get_drive_id "TL4 DAT drive" 1
			get_drive_id "TL4 DAT drive" 2
		fi
	fi

	get_4mm_drive_type "TL4 drive"

	# check for and make device files
	make_robot_devs $SCSI2_ROBOT $ADAPTER "tl4"

	make_drive_devs 1 $DRIVETYPE $DRIVE1 $ADAPTER
	make_drive_devs 2 $DRIVETYPE $DRIVE2 $ADAPTER

	missingpath=0

	check_robot_path ${ROBCTRL_PATH}

	check_drive_path 1 $DRIVE1_STR $DRIVE1_STR_NR
	check_drive_path 2 $DRIVE2_STR $DRIVE2_STR_NR

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}
# -----------------------------------------------------------------------------
make_TS8_devs()
{

	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_solaris_robot_path NO_LUN_1
		SCSI2_ROBOT=$VALUE	# it's an sg path, not a SCSI ID
		ADAPTER=0
	elif [ "$HOSTTYPE" != HP800 -a "$HOSTTYPE" != HPUX10 ] ; then
		get_scsi_adapter "TS8" "robotic devices"
		ADAPTER=$VALUE
		get_scsi_id "TS8 SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	else
		ADAPTER=0
		get_scsi_id "TS8 SCSI robotic control" sctl
		SCSI2_ROBOT=$VALUE
	fi

	get_number "Enter the number of drives in the TS8" 1 2
	NUMDRIVES=$VALUE

	if [ "$HOSTTYPE" = HP800 -o "$HOSTTYPE" = HPUX10 ] ; then
		ioscan tape_drive
	fi

	print_alpha_drive_choices

	get_drive_id "TS8 Exabyte drive" 1
	get_drive_id "TS8 Exabyte drive" 2
	get_drive_id "TS8 Exabyte drive" 3
	get_drive_id "TS8 Exabyte drive" 4

	get_exabyte_drive_type "TS8 drive"

	# check for and make device files
	make_robot_devs $SCSI2_ROBOT $ADAPTER "ts8"

	make_drive_devs 1 $DRIVETYPE $DRIVE1 $ADAPTER
	make_drive_devs 2 $DRIVETYPE $DRIVE2 $ADAPTER
	make_drive_devs 3 $DRIVETYPE $DRIVE3 $ADAPTER
	make_drive_devs 4 $DRIVETYPE $DRIVE4 $ADAPTER

	missingpath=0

	check_robot_path ${ROBCTRL_PATH}

	check_drive_path 1 $DRIVE1_STR $DRIVE1_STR_NR
	check_drive_path 2 $DRIVE2_STR $DRIVE2_STR_NR
	check_drive_path 3 $DRIVE3_STR $DRIVE3_STR_NR
	check_drive_path 4 $DRIVE4_STR $DRIVE4_STR_NR

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}
# -----------------------------------------------------------------------------
make_TSH_devs()
{

	$ECHO "
TSH software supports the IBM 3590 B11 Stacker.
"
	common_device_file=1

	NUMDRIVES=1
	if [ "$HOSTTYPE" = "solaris" ] ; then
		get_solaris_robot_path NO_LUN_1
		SCSI2_ROBOT=$VALUE	# it's an sg path, not a SCSI ID
		ADAPTER=0	# unused
		get_solaris_logical_drive_id 1 LUN0_ROBOTIC_SHARED $SCSI2_ROBOT
		DRIVE1=$VALUE
	else
		get_scsi_adapter "TSH" "robotic devices"
		ADAPTER=$VALUE
		get_scsi_id "TSH SCSI robotic control and drive" sctl
		SCSI2_ROBOT=$VALUE
		DRIVE1=$SCSI2_ROBOT
	fi

	# check for and make device files
	make_robot_devs $SCSI2_ROBOT $ADAPTER "tsh"

	make_drive_devs 1 ibm3590 $DRIVE1 $ADAPTER

	missingpath=0

	check_robot_path ${ROBCTRL_PATH}

	check_drive_path 1 $DRIVE1_STR $DRIVE1_STR_NR

	if [ $missingpath -eq 1 ] ; then
		re_run 2
	fi
}
# -----------------------------------------------------------------------------
get_tsh_drive_type()
{

	$ECHO " "
	$ECHO "\tEnter Media Manager Drive Type for TSH drive"
	$ECHO "\t--------------------------------------------"

	$ECHO "\t1. Half-inch Cartridge (hcart)"
	$ECHO "\t2. Half-inch Cartridge Alternate (hcart2)"
	get_number "\tEnter Choice" 1 2
}
# -----------------------------------------------------------------------------
#
#	get_tld_drive_type()
#  $1 - drive number
#  $2 - drive type to show (DLT, HCART, 8MM, 4MM, DTF, or ALL)
#
get_tld_drive_type()
{

	if [ $2 != "DTF" ] ; then
		$ECHO "\tEnter Media Manager Drive Type for TLD drive $1"
		$ECHO "\t-----------------------------------------------"
	fi

	if [ $2 = "ALL" ] ; then

		$ECHO "\t1. DLT Cartridge (dlt)"
		$ECHO "\t2. Half-inch Cartridge (hcart)"
		$ECHO "\t3. DTF Cartridge (dtf)"
		$ECHO "\t4. DLT Cartridge Alternate (dlt2)"
		$ECHO "\t5. Half-inch Cartridge Alternate (hcart2)"
		get_number "\tEnter Choice" 1 5

		case $VALUE in
			1) medtype=dlt ;;
			2) medtype=hcart ;;
			3) medtype=dtf ;;
			4) medtype=dlt2 ;;
			5) medtype=hcart2 ;;
		esac

	elif [ $2 = "DLT" ] ; then

		$ECHO "\t1. DLT Cartridge (dlt)"
		$ECHO "\t2. DLT Cartridge Alternate (dlt2)"
		get_number "\tEnter Choice" 1 2

		case $VALUE in
			1) medtype=dlt ;;
			2) medtype=dlt2 ;;
		esac

	elif [ $2 = "HCART" ] ; then

		$ECHO "\t1. Half-inch Cartridge (hcart)"
		$ECHO "\t2. Half-inch Cartridge Alternate (hcart2)"
		get_number "\tEnter Choice" 1 2

		case $VALUE in
			1) medtype=hcart ;;
			2) medtype=hcart2 ;;
		esac
	elif [ $2 = "DTF" ] ; then
		medtype=dtf
	else
		# handle 4MM, 8MM, etc selections (not supported in TLD)

		$ECHO "\t1. DLT Cartridge (dlt)"
		$ECHO "\t2. Half-inch Cartridge (hcart)"
		$ECHO "\t3. DTF Cartridge (dtf)"
		$ECHO "\t4. DLT Cartridge Alternate (dlt2)"
		$ECHO "\t5. Half-inch Cartridge Alternate (hcart2)"
		get_number "\tEnter Choice" 1 5

		case $VALUE in
			1) medtype=dlt ;;
			2) medtype=hcart ;;
			3) medtype=dtf ;;
			4) medtype=dlt2 ;;
			5) medtype=hcart2 ;;
		esac
	fi
}

##
# TPCONFIG functions
##

# -----------------------------------------------------------------------------
tpconfig_robots_and_drives()
{
	case $ROBTYPE in
		TL4) tpconfig_TL4 ;;
		TS8) tpconfig_TS8 ;;
		TSH) tpconfig_TSH ;;
		TC8) tpconfig_TC8 ;;
		TC4) tpconfig_TC4 ;;
		TL8) tpconfig_TL8 ;;
		ODL) tpconfig_ODL ;;
		TLD) tpconfig_TLD ;;
		TSD) tpconfig_TSD ;;
		"Standalone Drive") tpconfig_NON_ROBOTIC ;;
	esac

	TMPF="/tmp/active_vm_processes.$$"
	if [ -f $TMPF ] ; then
		TMPF="/tmp/active_vm_processes.$$.alt"
	fi

	$VMPS > $TMPF

	$STOPLTID >/dev/null 2>/dev/null
	$ECHO "(re)initiating the Media Manager Device daemon (ltid) ..."
	sleep 5


	if [ -f $TMPF ] ; then
		ltidparams=`grep ltid $TMPF | sed 's/.*ltid//'`
	else
		ltidparams=""
	fi

	$LTID $ltidparams >/dev/null 2>/dev/null &
	/bin/rm -f $TMPF

}

# -----------------------------------------------------------------------------
tpconfig_TC4()
{
	robnum=`$TPCONFIG -noverbose -firstrn`
	if test Y"$robnum" = Y
	then
		re_run_tpconfig "robot"
	fi

	$TPCONFIG -noverbose -add_robot $robnum tc4 $ROBCTRL_PATH
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "robot $robnum" $vmstat
	fi

	DT=4mm

	devnum=`$TPCONFIG -noverbose -firstdn`
	if test Y"$devnum" = Y
	then
		re_run_tpconfig "device"
	fi

	$TPCONFIG -noverbose -add_drive $devnum $DT $DRIVE1_STR $DRIVE1_STR_NR /x A $robnum tc4
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "drive A (${devnum})" $vmstat
	fi

	devnum=`$TPCONFIG -noverbose -firstdn`
	if test Y"$devnum" = Y
	then
		re_run_tpconfig "device"
	fi

	$TPCONFIG -noverbose -add_drive $devnum $DT $DRIVE2_STR $DRIVE2_STR_NR /x B $robnum tc4
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		 re_run_tpconfig "drive B (${devnum})" $vmstat
	fi
}
# -----------------------------------------------------------------------------
tpconfig_TC8()
{
	robnum=`$TPCONFIG -noverbose -firstrn`
	if test Y"$robnum" = Y
	then
		re_run_tpconfig "robot"
	fi

	$TPCONFIG -noverbose -add_robot $robnum tc8 $ROBCTRL_PATH
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "robot $robnum" $vmstat
	fi

	devnum=`$TPCONFIG -noverbose -firstdn`
	if test Y"$devnum" = Y
	then
		re_run_tpconfig "device"
	fi

	$TPCONFIG -noverbose -add_drive $devnum 8mm $DRIVE1_STR $DRIVE1_STR_NR /x A $robnum tc8
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "drive A (${devnum})" $vmstat
	fi

	devnum=`$TPCONFIG -noverbose -firstdn`
	if test Y"$devnum" = Y
	then
		re_run_tpconfig "device"
	fi

	$TPCONFIG -noverbose -add_drive $devnum 8mm $DRIVE2_STR $DRIVE2_STR_NR /x B $robnum tc8
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		 re_run_tpconfig "drive B (${devnum})" $vmstat
	fi
}
# -----------------------------------------------------------------------------
tpconfig_TL8()
{
	robnum=`$TPCONFIG -noverbose -firstrn`
	if test Y"$robnum" = Y
	then
		re_run_tpconfig "robot"
	fi
	$TPCONFIG -noverbose -add_robot $robnum tl8 $ROBCTRL_PATH
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "robot $robnum" $vmstat
	fi

	tpconfig_drive 1 $DRIVE1_STR $DRIVE1_STR_NR $robnum "tl8" 8mm
	tpconfig_drive 2 $DRIVE2_STR $DRIVE2_STR_NR $robnum "tl8" 8mm
	tpconfig_drive 3 $DRIVE3_STR $DRIVE3_STR_NR $robnum "tl8" 8mm
	tpconfig_drive 4 $DRIVE4_STR $DRIVE4_STR_NR $robnum "tl8" 8mm
}

# -----------------------------------------------------------------------------
tpconfig_TLD()
{
	robnum=`$TPCONFIG -noverbose -firstrn`
	if test Y"$robnum" = Y
	then
		re_run_tpconfig "robot"
	fi
	$TPCONFIG -noverbose -add_robot $robnum tld $ROBCTRL_PATH
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "robot $robnum" $vmstat
	fi

	tpconfig_drive 1 $DRIVE1_STR $DRIVE1_STR_NR $robnum "tld" $DRIVE1_TYPE
	tpconfig_drive 2 $DRIVE2_STR $DRIVE2_STR_NR $robnum "tld" $DRIVE2_TYPE
	tpconfig_drive 3 $DRIVE3_STR $DRIVE3_STR_NR $robnum "tld" $DRIVE3_TYPE
	tpconfig_drive 4 $DRIVE4_STR $DRIVE4_STR_NR $robnum "tld" $DRIVE4_TYPE
	tpconfig_drive 5 $DRIVE5_STR $DRIVE5_STR_NR $robnum "tld" $DRIVE5_TYPE
	tpconfig_drive 6 $DRIVE6_STR $DRIVE6_STR_NR $robnum "tld" $DRIVE6_TYPE
	tpconfig_drive 7 $DRIVE7_STR $DRIVE7_STR_NR $robnum "tld" $DRIVE7_TYPE
	tpconfig_drive 8 $DRIVE8_STR $DRIVE8_STR_NR $robnum "tld" $DRIVE8_TYPE
	tpconfig_drive 9 $DRIVE9_STR $DRIVE9_STR_NR $robnum "tld" $DRIVE9_TYPE
	tpconfig_drive 10 $DRIVE10_STR $DRIVE10_STR_NR $robnum "tld" $DRIVE10_TYPE
}
# -----------------------------------------------------------------------------
tpconfig_drive()
{
	tmpdn=$1
	tmpdrstr=$2
	tmpnrdrstr=$3
	tmprn=$4
	tmprt=$5
	tmpdt=$6

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	$ECHO "Adding drive to the configuration ...
"

	devnum=`$TPCONFIG -noverbose -firstdn`
	if test Y"$devnum" = Y
	then
		re_run_tpconfig "device"
	fi
	$TPCONFIG -noverbose -add_drive $devnum $tmpdt $tmpdrstr $tmpnrdrstr /x $tmpdn $tmprn $tmprt
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "drive $devnum" $vmstat
	fi
}
# -----------------------------------------------------------------------------
tpconfig_NON_ROBOTIC()
{
	devnum=`$TPCONFIG -noverbose -firstdn`
	if test Y"$devnum" = Y
	then
		re_run_tpconfig "device"
	fi

	if [ $DRIVETYPE = OPTICAL ] ; then
		tpconfig_odl_drive 1 $DRIVE1_CDEV_STR $DRIVE1_BDEV_STR $DRIVE1_VOLHDR_STR 0 "none" odisk
	else
		case $DRIVETYPE in
		    4mm|4mm_compress)
			tmptype="4mm"
			;;
		    8200)
			tmptype="8mm"
			;;
		    8500)
			tmptype="8mm"
			;;
		    8505)
			tmptype="8mm"
			;;
		    dlt)
			tmptype="dlt"
			;;
		    dtf)
			tmptype="dtf"
			;;
		    hcart)
			tmptype="hcart"
			;;
		    *)
			$ECHO "${DRIVETYPE} is an unknown drive type."
			$ECHO Use xdevadm or tpconfig to complete the configuration.
			clean_and_exit 1
			;;
		esac

		$TPCONFIG -noverbose -add_drive $devnum $tmptype $DRIVE1_STR $DRIVE1_STR_NR /x 1 0 "none"
	fi

}

# -----------------------------------------------------------------------------
tpconfig_ODL()
{
	robnum=`$TPCONFIG -noverbose -firstrn`
	if test Y"$robnum" = Y
	then
		re_run_tpconfig "robot"
	fi
 	$TPCONFIG -noverbose -add_robot $robnum odl $ROBCTRL_PATH
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "robot $robnum" $vmstat
	fi

	tpconfig_odl_drive 1 $DRIVE1_CDEV_STR $DRIVE1_BDEV_STR $DRIVE1_VOLHDR_STR $robnum "odl" odisk
	tpconfig_odl_drive 2 $DRIVE2_CDEV_STR $DRIVE2_BDEV_STR $DRIVE2_VOLHDR_STR $robnum "odl" odisk
	tpconfig_odl_drive 3 $DRIVE3_CDEV_STR $DRIVE3_BDEV_STR $DRIVE3_VOLHDR_STR $robnum "odl" odisk
	tpconfig_odl_drive 4 $DRIVE4_CDEV_STR $DRIVE4_BDEV_STR $DRIVE4_VOLHDR_STR $robnum "odl" odisk
	tpconfig_odl_drive 5 $DRIVE5_CDEV_STR $DRIVE5_BDEV_STR $DRIVE5_VOLHDR_STR $robnum "odl" odisk
	tpconfig_odl_drive 6 $DRIVE6_CDEV_STR $DRIVE6_BDEV_STR $DRIVE6_VOLHDR_STR $robnum "odl" odisk
}

# -----------------------------------------------------------------------------
tpconfig_odl_drive()
{
	tmpdn=$1
	tmpcdstr=$2
	tmpbdstr=$3
	tmpvhstr=$4
	tmprn=$5
	tmprt=$6
	tmpdt=$7

	if [ $NUMDRIVES -lt $1 ] ; then
		return
	fi

	if [ "$tmprt" = "none" ] ; then
		$ECHO Adding drive to the configuration ...
	else
		$ECHO Adding $tmprt drive $tmpdn to the configuration ...
	fi

	devnum=`$TPCONFIG -noverbose -firstdn`
	if test Y"$devnum" = Y
	then
		re_run_tpconfig "device"
	fi
	if [ "$HOSTTYPE" = HP700 ] ; then
		$TPCONFIG -noverbose -add_drive $devnum $tmpdt $tmpcdstr $tmpbdstr $tmpcdstr $tmpdn $tmprn $tmprt
	else
		$TPCONFIG -noverbose -add_drive $devnum $tmpdt $tmpcdstr $tmpbdstr $tmpvhstr $tmpdn $tmprn $tmprt
	fi

	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "drive $devnum" $vmstat
	fi
}

# -----------------------------------------------------------------------------
tpconfig_TL4()
{
	robnum=`$TPCONFIG -noverbose -firstrn`
	if test Y"$robnum" = Y
	then
		re_run_tpconfig "robot"
	fi
	$TPCONFIG -noverbose -add_robot $robnum tl4 $ROBCTRL_PATH
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "robot $robnum" $vmstat
	fi

	tpconfig_drive 1 $DRIVE1_STR $DRIVE1_STR_NR $robnum "tl4" 4mm
	tpconfig_drive 2 $DRIVE2_STR $DRIVE2_STR_NR $robnum "tl4" 4mm
}

# -----------------------------------------------------------------------------
tpconfig_TS8()
{
	robnum=`$TPCONFIG -noverbose -firstrn`
	if test Y"$robnum" = Y
	then
		re_run_tpconfig "robot"
	fi
	$TPCONFIG -noverbose -add_robot $robnum ts8 $ROBCTRL_PATH
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "robot $robnum" $vmstat
	fi

	tpconfig_drive 1 $DRIVE1_STR $DRIVE1_STR_NR $robnum "ts8" "8mm"
	tpconfig_drive 2 $DRIVE2_STR $DRIVE2_STR_NR $robnum "ts8" "8mm"
}

# -----------------------------------------------------------------------------
tpconfig_TSD()
{
	robnum=`$TPCONFIG -noverbose -firstrn`
	if test Y"$robnum" = Y
	then
		re_run_tpconfig "robot"
	fi
	$TPCONFIG -noverbose -add_robot $robnum tsd $ROBCTRL_PATH
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "robot $robnum" $vmstat
	fi

	tpconfig_drive 1 $DRIVE1_STR $DRIVE1_STR_NR $robnum "tsd" dlt
}
# -----------------------------------------------------------------------------
tpconfig_TSH()
{
	robnum=`$TPCONFIG -noverbose -firstrn`
	if test Y"$robnum" = Y
	then
		re_run_tpconfig "robot"
	fi
	$TPCONFIG -noverbose -add_robot $robnum tsh $ROBCTRL_PATH
	vmstat=$?
	if [ $vmstat -ne 0 ] ; then
		re_run_tpconfig "robot $robnum" $vmstat
	fi

	get_tsh_drive_type
	case $VALUE in
		1) medtype=hcart ;;
		2) medtype=hcart2 ;;
	esac

	tpconfig_drive 1 $DRIVE1_STR $DRIVE1_STR_NR $robnum "tsh" $medtype
}

##
# INITIALIZE/INSTALL functions
##

# -----------------------------------------------------------------------------
get_port()
{
	name=$1
	number=$2
	string=$3

	if [ "${string}X" != X ] ; then
		# entry was found
		service=$string
		return
	fi

	# prompt for non default port number
	$ECHO "Adding $name to /etc/services
 The default port is $number"
	if confirm_no "Do you want to alter the default port?"
	then
		get_number_no_range "Which port number do you want to use?"
		port=$VALUE
	else
		port=$number
	fi

	# make service string
	service="${name} 	${port}/tcp 	${name}"
}
# -----------------------------------------------------------------------------
# 	returns 1 if yp has all vm services
#	0 if yp is missing 1 or more ov the vm services
#  0 also means the check_yp failed for yp reasons.
check_yp_first_time=0

check_yp()
{
	YP_SERVICES=/usr/openv/volmgr/yp_services
	rm -f $YP_SERVICES

	if [ -x /bin/ypcat ] ; then
		YPCAT=/bin/ypcat
	elif [ -x /usr/bin/ypcat ] ; then
		YPCAT=/usr/bin/ypcat
	else\
		YPCAT=NONE
	fi
	if [ $YPCAT != NONE ] ; then
		$YPCAT services >$YP_SERVICES 2> /tmp/vmconf.ypcat.$$

		if [ -s /tmp/vmconf.ypcat.$$ ] ; then
			$ECHO "WARNING: \c"
			cat /tmp/vmconf.ypcat.$$
			$ECHO
		else

			findvmd=`/bin/cat $YP_SERVICES | egrep "^vmd($| |$TAB)"`
			findacsd=`/bin/cat $YP_SERVICES | egrep "^acsd($| |$TAB)"`
			findtl8cd=`/bin/cat $YP_SERVICES | egrep "^tl8cd($| |$TAB)"`
			findtldcd=`/bin/cat $YP_SERVICES | egrep "^tldcd($| |$TAB)"`
			findts8d=`/bin/cat $YP_SERVICES | egrep "^ts8d($| |$TAB)"`
			findtc8d=`/bin/cat $YP_SERVICES | egrep "^tc8d($| |$TAB)"`
			findtc4d=`/bin/cat $YP_SERVICES | egrep "^tc4d($| |$TAB)"`
			findodld=`/bin/cat $YP_SERVICES | egrep "^odld($| |$TAB)"`
			findvtlcd=`/bin/cat $YP_SERVICES | egrep "^vtlcd($| |$TAB)"`
			findtl4d=`/bin/cat $YP_SERVICES | egrep "^tl4d($| |$TAB)"`
			findtsdd=`/bin/cat $YP_SERVICES | egrep "^tsdd($| |$TAB)"`
			findtshd=`/bin/cat $YP_SERVICES | egrep "^tshd($| |$TAB)"`
			findtlmd=`/bin/cat $YP_SERVICES | egrep "^tlmd($| |$TAB)"`
			findtlhcd=`/bin/cat $YP_SERVICES | egrep "^tlhcd($| |$TAB)"`
			rm -f $YP_SERVICES

			if [ "${findvmd}X" = X -o "${findacsd}X" = X -o "${findtl8cd}X" = X -o "${findtldcd}X" = X -o "${findodld}X" = X -o "${findvtlcd}X" = X -o "${findts8d}X" = X -o "${findtc8d}X" = X -o "${findtc4d}X" = X  -o "${findtl4d}X" = X -o "${findtsdd}X" = X -o "${findtshd}X" = X -o "${findtlmd}X" = X -o "${findtlhcd}X" = X ]
			then
				if [ $check_yp_first_time = 0 ] ; then
					$ECHO "
The Network Information Service is running and may have
to be restarted or updated before modifications to the
/etc/services file take effect.

Update the NIS services database with the following
lines before continuing.

# Media Manager services #"
					if [ " $findvmd" = " " ] ; then
						$ECHO $vmdentry
					fi
					if [ " $findacsd" = " " ] ; then
						$ECHO $acsdentry
					fi
					if [ " $findtl8cd" = " " ] ; then
						$ECHO $tl8cdentry
					fi
					if [ " $findtldcd" = " " ] ; then
						$ECHO $tldcdentry
					fi
					if [ " $findts8d" = " " ] ; then
						$ECHO $ts8dentry
					fi
					if [ " $findtc8d" = " " ] ; then
						$ECHO $tc8dentry
					fi
					if [ " $findtc4d" = " " ] ; then
						$ECHO $tc4dentry
					fi
					if [ " $findodld" = " " ] ; then
						$ECHO $odldentry
					fi
					if [ " $findvtlcd" = " " ] ; then
						$ECHO $vtlcdentry
					fi
					if [ " $findtl4d" = " " ] ; then
						$ECHO $tl4dentry
						fi
					if [ " $findtsdd" = " " ] ; then
						$ECHO $tsddentry
					fi
					if [ " $findtshd" = " " ] ; then
						$ECHO $tshdentry
					fi
					if [ " $findtlmd" = " " ] ; then
						$ECHO $tlmdentry
					fi
					if [ " $findtlhcd" = " " ] ; then
						$ECHO $tlhcdentry
					fi
					$ECHO "# End Media Manager services #"
					check_yp_first_time=1
				fi
			else
				return 1
			fi
		fi
	fi
	rm -f /tmp/vmconf.ypcat.$$
	return 0
}
# -----------------------------------------------------------------------------
#
update_services_all()
{
	$ECHO "Checking /etc/services for the needed Media Manager services ..."

	vmdport=13701
	acsdport=13702
	tl8cdport=13705
	odldport=13706
	vtlcdport=13708
	ts8dport=13709
	tc8dport=13710
	tldcdport=13711
	tc4dport=13712
	tl4dport=13713
	tsddport=13714
	tshdport=13715
	tlmdport=13716
	tlhcdport=13717

	findvmd=`egrep "^vmd($| |$TAB)" /etc/services`
	findacsd=`egrep "^acsd($| |$TAB)" /etc/services`
	findtl8cd=`egrep "^tl8cd($| |$TAB)" /etc/services`
	findtldcd=`egrep "^tldcd($| |$TAB)" /etc/services`
	findodld=`egrep "^odld($| |$TAB)" /etc/services`
	findvtlcd=`egrep "^vtlcd($| |$TAB)" /etc/services`
	findts8d=`egrep "^ts8d($| |$TAB)" /etc/services`
	findtc8d=`egrep "^tc8d($| |$TAB)" /etc/services`
	findtc4d=`egrep "^tc4d($| |$TAB)" /etc/services`
	findtl4d=`egrep "^tl4d($| |$TAB)" /etc/services`
	findtsdd=`egrep "^tsdd($| |$TAB)" /etc/services`
	findtshd=`egrep "^tshd($| |$TAB)" /etc/services`
	findtlmd=`egrep "^tlmd($| |$TAB)" /etc/services`
	findtlhcd=`egrep "^tlhcd($| |$TAB)" /etc/services`

	if [  "${findvmd}X" = X -o "${findacsd}X" = X -o "${findtl8cd}X" = X -o "${findtldcd}X" = X -o "${findodld}X" = X -o "${findvtlcd}X" = X -o "${findts8d}X" = X -o "${findtc4d}X" = X -o "${findtc8d}X" = X -o "${findtl4d}X" = X -o "${findtsdd}X" = X -o "${findtshd}X" = X -o "${findtlmd}X" = X -o "${findtlhcd}X" = X ]
	then
		$ECHO "Editing /etc/services to update Media Manager services ..."
		dt=`/bin/date +"%m-%d-%y-%T"`
		$ECHO "Copying original /etc/services file to /etc/services.${dt}
"
		cp /etc/services /etc/services.${dt}

	fi

	# prompt for port numbers for missing services
	get_port vmd $vmdport "${findvmd}"
	vmdentry=$service

	get_port acsd $acsdport "${findacsd}"
	acsdentry=$service

	get_port tl8cd $tl8cdport "${findtl8cd}"
	tl8cdentry=$service

	get_port odld $odldport "${findodld}"
	odldentry=$service

	get_port vtlcd $vtlcdport "${findvtlcd}"
	vtlcdentry=$service

	get_port ts8d $ts8dport "${findts8d}"
	ts8dentry=$service

	get_port tc8d $tc8dport "${findtc8d}"
	tc8dentry=$service

	get_port tldcd $tldcdport "${findtldcd}"
	tldcdentry=$service

	get_port tc4d $tc4dport "${findtc4d}"
	tc4dentry=$service

	get_port tl4d $tl4dport "${findtl4d}"
	tl4dentry=$service

	get_port tsdd $tsddport "${findtsdd}"
	tsddentry=$service

	get_port tshd $tshdport "${findtshd}"
	tshdentry=$service

	get_port tlmd $tlmdport "${findtlmd}"
	tlmdentry=$service

	get_port tlhcd $tlhcdport "${findtlhcd}"
	tlhcdentry=$service

	# check for any missing services
	if [  "${findvmd}X" = X -o "${findacsd}X" = X -o "${findtl8cd}X" = X -o "${findtldcd}X" = X -o "${findodld}X" = X -o "${findvtlcd}X" = X -o "${findts8d}X" = X -o "${findtc4d}X" = X -o "${findtc8d}X" = X -o "${findtl4d}X" = X -o "${findtsdd}X" = X -o "${findtshd}X" = X -o "${findtlmd}X" = X -o "${findtlhcd}X" = X ]
	then
		# remove lines
		sed -e '/.*Media Manager.*/d' -e '/.*OpenVision VolumeManager.*/d' -e '/.*OpenVision Volume Manager.*/d' -e '/vmd.*/d' -e '/acsd.*/d' -e '/tl8cd.*/d' -e '/vtlcd.*/d' -e '/odld.*/d' -e '/ts8d.*/d'  -e '/tc8d.*/d' -e '/tc4d.*/d' -e '/tldcd.*/d' -e '/tl4d.*/d' -e '/tsdd.*/d' -e '/tshd.*/d' -e '/tlmd.*/d' -e '/tlhcd.*/d' /etc/services | cat -s > /etc/services.ov_edited.$$

		cat <<- END_OV_EDIT >> /etc/services.ov_edited.$$
		# Media Manager services #
		$vmdentry
		$acsdentry
		$tl8cdentry
		$odldentry
		$vtlcdentry
		$ts8dentry
		$tc8dentry
		$tldcdentry
		$tc4dentry
		$tl4dentry
		$tsddentry
		$tshdentry
		$tlmdentry
		$tlhcdentry
		# End Media Manager services #
		END_OV_EDIT

		# done in two steps to keep permissions on file
		cp /etc/services.ov_edited.$$ /etc/services
		rm /etc/services.ov_edited.$$
		$ECHO "/etc/services has been updated to contain Media Manager services.
"
		if [ "${HARDWARE}" = "RS6000" ] ; then
			if [ -f /usr/bin/inetimp ] ; then
				/usr/bin/inetimp
			fi
		fi
	else
		$ECHO "Found the necessary Media Manager services in /etc/services.
"
	fi

	#  check if yp is running
	if [ -x /bin/ypwhich ] ; then
		YPWHICH=/bin/ypwhich
	elif [ -x /usr/bin/ypwhich ] ; then
		YPWHICH=/usr/bin/ypwhich
	else
		YPWHICH=NONE
	fi
	if [ $YPWHICH != NONE ] ; then
		$YPWHICH > /dev/null 2> /tmp/vmconf.ypwhich.$$
		if [ -s /tmp/vmconf.ypwhich.$$ ] ; then
			$ECHO "WARNING: \c"
			cat /tmp/vmconf.ypwhich.$$
			$ECHO
			check_yp
		else
			# check for the services in NIS
			if check_yp
			then
				$ECHO "\nPress return when finished. \c"
				read ans
				$ECHO ""

				if check_yp
				then
					$ECHO "One or more of the Media Manager services entries"
					$ECHO "were still not found with /usr/bin/ypcat."
					$ECHO "\nYou may run into problems later."
					askifquit
				fi
			fi
		fi
	fi
	rm -f /tmp/vmconf.ypwhich.$$
}
# -----------------------------------------------------------------------------
install_app_defaults()
{

# Create links for X application resource files.
# As of NB R3.1, all x apps use the same resource file.
if [ -d /.dt -o -d /.vue ] ; then
	XRESOURCE_EXT=.dt
else
	XRESOURCE_EXT=""
fi
XNB_VM_XRES=/usr/openv/volmgr/bin/XNB${XRESOURCE_EXT}

$ECHO " "
if [ -d /usr/lib/X11/app-defaults ] ; then
	if [ ! -f /usr/lib/X11/app-defaults/XNB -a -f ${XNB_VM_XRES} ] ; then
		$ECHO "Linking /usr/lib/X11/app-defaults/XNB --> ${XNB_VM_XRES}
"
		ln -s ${XNB_VM_XRES} /usr/lib/X11/app-defaults/XNB
	fi
elif [ -d /usr/openwin/lib/app-defaults ] ; then
	if [ ! -f /usr/openwin/lib/app-defaults/XNB -a -f ${XNB_VM_XRES} ] ; then
		$ECHO "Linking /usr/openwin/lib/app-defaults/XNB --> ${XNB_VM_XRES}
"
		ln -s ${XNB_VM_XRES} /usr/openwin/lib/app-defaults/XNB
	fi
fi
}
# -----------------------------------------------------------------------------
# -------------- "main" portion of script starts here --------------

if [ "$1" = "-install" ] ; then
	INSTALL_ONLY=1
else
	INSTALL_ONLY=0
fi

if [ -f /usr/openv/volmgr/version ] ; then
	HARDWARE=`head -1 /usr/openv/volmgr/version | cut -f2 -d" "`
else
	HARDWARE=NONE
fi

ECHO="/bin/echo"
PS='/bin/ps -ea'
AUSPEX_SP=0
ARCHTYPE=none

case "$HARDWARE" in
	SUN4)
		HOSTTYPE=sun
		ECHO="/usr/5bin/echo"
		PS='/bin/ps -cax'
		archtype=`/bin/uname -m`
		if [ "$archtype" = aushp ] ; then
			ARCHTYPE=auspex
			SPSCAN=/usr/openv/volmgr/bin/spscan
		else
			ARCHTYPE=$archtype
		fi
		;;
	SOLARIS)
		HOSTTYPE=solaris
		;;
	SGI)
		HOSTTYPE=SGI
		;;
	HP9000-700)
		HOSTTYPE=HP700
		os_level=`uname -r | cut -c2-4`
		if [ "${os_level}" = .10 ] ; then
			HOSTTYPE=HPUX10
			IOSCAN=/sbin/ioscan
		else
			IOSCAN=/etc/ioscan
		fi
		;;
	HP9000-800)
		HOSTTYPE=HP800
		os_level=`uname -r | cut -c2-4`
		if [ "${os_level}" = .10 ] ; then
			HOSTTYPE=HPUX10
			IOSCAN=/sbin/ioscan
		else
			IOSCAN=/etc/ioscan
		fi
		;;
	RS6000)
		HOSTTYPE=RS6000
		aixversion=`/bin/uname -v`
		;;
	ALPHA)
		HOSTTYPE=ALPHA
		;;
	SEQUENT)
		HOSTTYPE=SEQUENT
		;;
	PYRAMID)
		HOSTTYPE=PYRAMID
		;;
	NCR)
		HOSTTYPE=NCR
		;;
	*)
		echo "
		/usr/openv/netbackup/version not found or corrupted.
		Unknown hardware type: \"$HARDWARE\"
"
		exit 3
		;;
esac

TPCONFIG=/usr/openv/volmgr/bin/tpconfig
TPCLEAN=/usr/openv/volmgr/bin/tpclean
STOPLTID=/usr/openv/volmgr/bin/stopltid
LTID=/usr/openv/volmgr/bin/ltid
TPFORMAT=/usr/openv/volmgr/bin/tpformat

if type hostname | grep 'not found' >/dev/null
then
	thishost=`uname -n`
else
	thishost=`hostname | sed 's/\..*$//'`
fi

# Make sure this is being run from root.
ISROOT=`/usr/bin/id | egrep "^uid=0\("`
if [ "${ISROOT}" = "" ] ; then
	$ECHO "
This must be run while logged in as root.
"
	exit 1
fi

# kludgey, but we need a tab to use in regular expressions
# and we want it to be obvious and not get broken accidentally.

TAB=`echo ' ' | tr ' ' '\011'`
SPACE=' '
lunone_changer=0
common_device_file=0	# set to '1' if we're using the same device file for
			# the robot and drive (eg. IBM 3590 B11 on IBM RS6000)
HW_PATH=0

update_services_all

install_app_defaults

if [ $INSTALL_ONLY -eq 1 ] ; then
	if [ $HARDWARE = SOLARIS ] ; then
		$ECHO "Installing sg driver."
		/usr/openv/volmgr/bin/driver/sg.install
	fi
	exit 0
fi

if [ "$HOSTTYPE" = NCR -o "$HOSTTYPE" = SEQUENT -o "$HOSTTYPE" = PYRAMID -o "$HOSTTYPE" = OLIVETTI ] ; then
	use_tpconfig
	use_vmadm
	exit 0
fi

if [ "$HOSTTYPE" = sun -a "$ARCHTYPE" = auspex ] ; then
	# On auspex, link to a version of the format utility that
	# works when formatting optical disks.  This is needed because
	# /usr/etc/format doesn't work for optical disks.

	if [ -f /usr/etc/format.414 ] ; then
		/bin/rm -f /usr/openv/volmgr/bin/format/format.414
		ln -s /usr/etc/format.414 /usr/openv/volmgr/bin/format/format.414
	fi
	pick_auspex_processor
fi

get_robot_type

# Do not make device files on solaris
if [ "$HOSTTYPE" = "solaris" ] ; then
	if [ "$ROBTYPE" = "Standalone Drive" ] ; then
		MSG="Do you want this script to check for the necessary device files\nfor the $ROBTYPE?  (if you answer no, this script will not\nperform any additional device or media configuration) "
	else
		MSG="Do you want this script to check for the necessary device\nfiles for the $ROBTYPE?  (if you answer no, this script will not\nperform any additional device or media configuration) "
	fi
else
	MSG="Do you want this script to check for and make the necessary device\nfiles for the $ROBTYPE?  (if you answer no, this script will not\nperform any additional device or media configuration) "
fi

if confirm "$MSG"
then
	make_dev_files
else
	case "$HOSTTYPE" in
		sun)
			if [ "$ARCHTYPE" = "auspex" ] ; then
				$ECHO "Use MAKEDEV to make device files on the host processor"
				$ECHO "Device files on the storage processor are created by the system"
			else
				$ECHO "Use MAKEDEV to make device files"
			fi
			;;
		SGI|ALPHA)
			$ECHO "Use MAKEDEV to make device files"
			;;
		HP700|HP800)
			$ECHO "Use mknod to make device files"
			;;
		HPUX10)
			$ECHO "Use mksf to make device files"
			;;
		RS6000)
			$ECHO "Use mkdev to make device files"
			;;
	esac

	use_tpconfig
	use_vmadm
	exit 1
fi

if confirm \
"Do you want this script to add the robot and/or drive(s) to the Drive \nand Robot databases, instead of using xdevadm or tpconfig interactively?\n(if you answer no, this script will not perform any additional device\nor media configuration) "
then
	$ECHO "Adding robots & drives to the Drive and Robot databases ..."
	tpconfig_robots_and_drives
	if test "$HOSTTYPE" = sun
	then
		if $AUSPEX_SP != 1 ] ; then
			$ECHO "Make sure the SG driver is installed and configured properly\c"
			if [ "${ROBTYPE}" = TLD -o "${ROBTYPE}" = TC4 -o "${ROBTYPE}" = TC8 ] ; then
				$ECHO " if you are using SCSI robotics."
			else
				ECHO ".":
			fi
		fi
	fi

	$ECHO "\nUse $TPCONFIG or xdevadm to alter the drive and robot"
	$ECHO "configuration, if necessary, at a later time.\n\n"
else
	use_tpconfig
	use_vmadm
	clean_and_exit 1
fi

# Do not do volume database population anymore in this script.  The
# automatic populate/reconcile feature in vmadm/xvmadm is much better
# and that is what should be used.
use_vmadm
clean_and_exit 0
