#!/bin/sh5
########################################################################
#
#			Copyright (c) 1988, 1989 by
#		Digital Equipment Corporation, Maynard, MA
#			All rights reserved.
#
#	This software is furnished under a license and may be used and
#	copied  only  in accordance with the terms of such license and
#	with the  inclusion  of  the  above  copyright  notice.   This
#	software  or  any  other copies thereof may not be provided or
#	otherwise made available to any other person.  No title to and
#	ownership of the software is hereby transferred.		
#
#	The information in this software is subject to change  without
#	notice  and should not be construed as a commitment by Digital
#	Equipment Corporation.					
#
#	Digital assumes no responsibility for the use  or  reliability
#	of its software on equipment which is not supplied by Digital.
#
#	SCCSID = "@(#)SSINS	4.2	(ULTRIX)	8/5/90"
#
#	000	Jonathan Wallace	1-Jun-1990
#
#	001	James C. Overman	05-Aug-1990
#	    Moved references to /tmp to /usr/tmp 
#
########################################################################
#
#
trap 'Cleanup_Routine; exit' 1 2 3 18
LL="
"
set -h

>/usr/tmp/DEV.list
>/usr/tmp/DEV.tape
>/usr/tmp/DEV.CDrom

########################################################################
# Subroutines #
###############
#####################################
: Cleanup_Routine - Remove tmp files
#####################################
Cleanup_Routine()
{
	rm -f /usr/tmp/DEV.list /usr/tmp/DEV.tape /usr/tmp/DEV.CDrom
}


#####################################
: Ticker - Put time stamps on screen
#####################################
Ticker()
{
	(
		while :
		do
			echo "    working ..... \c"
			date
			sleep 120
		done
	)&
	TICKPID=$!
}


: Unticker - Stop time stamps to screen
Unticker()
{
	[ -n "$TICKPID" ] &&
	{
		(
		kill -15 $TICKPID
		wait $TICKPID
		TICKPID=
		)&
	}
}


##################################
: FindDevice_Routine
##################################
FindDevice_Routine()
{
	clear
	[ -s /usr/tmp/DEV.$DEVTYPE ] ||
	{
		echo "${LL}*** SOFTWARE INSTALLATION PROCEDURE ***"
		echo "	Working ... `date` \c"
		X=0
		case $1 in
		tape )
			for K in /dev/rmt*
			do
				FI=`file $K`
				FI=`expr "$FI" : '\(.*\)[t][a][p][e]'`
				FI=`expr "$FI" : '.*[#][0-9][0-9]*\(.*\)'`
				case $? in
				0 )
					X=`expr $X + 1`
					case $X in
					[0-9])
						X=" $X"
						;;
					esac
					echo "$K" >>/usr/tmp/DEV.list
					echo "	${X} - $K$FI Tape" >>/usr/tmp/DEV.$DEVTYPE
					;;
				esac
			done
			;;
		CDrom )
			for K in /dev/rz*
			do
				X=`expr $X + 1`
				case $X in
				[0-9])
					X=" $X"
					;;
				esac

				FI=`file $K`
				FI=`expr "$FI" : '.*\(RRD[0-9][0-9]\)'`
				case $? in
				0 )
					echo "$K" >>/usr/tmp/DEV.list
					echo "  ${X} - $K$FI CDrom" >>/usr/tmp/DEV.$DEVTYPE
					;;
				esac
			done
			;;
		esac

		if [ -s /usr/tmp/DEV.$DEVTYPE ]
		then
			NONE=`expr $X + 1`
			case $NONE in
			[0-9])
				NONE=" $NONE"
				;;
			esac
			echo "	${NONE} - None of the above" >>/usr/tmp/DEV.$DEVTYPE
			return 0
		else
			NULLFLG=1
			return 1
		fi
	}
}


#####################################
: SelectDevice_Routine
#####################################
SelectDevice_Routine()
{
	clear
	echo "
*** SOFTWARE INSTALLATION PROCEDURE ***

Select the device you want to install from:
"

	cat /usr/tmp/DEV.$DEVTYPE

	echo "${LL}Enter your choice [1]: \c"
	read DEVNUM

	# is it a number?
	J=`expr "$DEVNUM" : '\([0-9][0-9]*\)'`

	case $J in
	"" )
		DEVNUM=1
		;;
	* )
		[ $J -gt $NONE ] && SelectDevice_Routine
		;;
	esac
}


################################################################
: ParseDevice_Routine
################################################################
ParseDevice_Routine()
{
	X=0
	for K in `cat /usr/tmp/DEV.list`
	do
		X=`expr $X + 1`
		case $X in
		$DEVNUM )
			DEVICE=$K
			break
			;;
		esac
	done
}


############################################################
: Setld_Routine
############################################################
Setld_Routine()
{
	clear
	echo "${LL}Working ... `date`"
	setld -l $DEVICE
	case $? in
	0 )
		;;
	* )
		echo "
Press <RETURN> to continue \c"
		read resp
		;;
	esac
}


##########################################################
: GetServer_Routine
##########################################################
GetServer_Routine()
{
	clear
	echo "
*** SOFTWARE INSTALLATION PROCEDURE ***

Enter the name of the server you will be using to install
software from: \c"
	read DEVICE

	case $DEVICE in
	"" )
		GetServer_Routine
		;;
	* )
		DEVICE="${DEVICE}:"
		;;
	esac

}


#######################################
# MAIN PROGRAM
####################
while true
do
	clear
	echo "${LL}*** SOFTWARE INSTALLATION PROCEDURE ***"
	case $NULLFLG in
	1 )
		echo
		echo "###########################################"
		echo "No valid $DEVTYPE device found on this system"
		echo "###########################################"
		NULLFLG=0
		;;
	esac
	echo "
Select the installation device type:

	1 - Tape
	2 - CDrom
	3 - Network

	0 - Return to Previous Menu

Enter your choice [no default]: \c"
	read DEVTYPE

	case $DEVTYPE in
	0)
		break
		;;
	1)
		DEVTYPE=tape
		FindDevice_Routine $DEVTYPE
		case $? in 
		1 )
			continue
			;;
		esac
		SelectDevice_Routine
		[ $DEVNUM -eq $NONE ] && continue
		ParseDevice_Routine
		Setld_Routine 
		break
		;;
	2)
		DEVTYPE=CDrom
		FindDevice_Routine $DEVTYPE
		case $? in 
		1 )
			continue
			;;
		esac
		SelectDevice_Routine
		[ $DEVNUM -eq $NONE ] && continue
		ParseDevice_Routine
		Setld_Routine 
		break
		;;
	3)
		DEVTYPE=network
		GetServer_Routine
		Setld_Routine
		break
		;;
	*)
		;;
	esac
done

Cleanup_Routine
exit 0
