
###########################################################################
# Name    : chk_tape
# Purpose : The purpose of this routine is to check the distribution tape.
#	    If it is in SVR3 format, it will read the tape in a temp. dir-
#	    ectory and set the the shell variable 'DISTRIBUTOR' to PRIME
#	    and 'TMPDIR' to the temp. directory where the tape was read
#	    and 'CPLOG' to /tmp/cplog$$. If cpio fails to read the tape
#	    it will test the tape for mips format, if the test pass
#	    the shell variable 'DISTRIBUTOR' will be set to MIPS
#
# Author  : Tripty Dhar
#
# HISTORY
#
# Date		Programmer	Comment
# 11/20/90	T. Dhar		Initial Coding
#
# 01/15/91      T. Dhar         (1) Modified the message "Varifying tape type"
#				    to "Varifying tape type (possibly reading,
#				    please wait"
#				(2) /usr/tmp may not be a existing directory
#				    so if needed create it.
#
#
###########################################################################
#
#!/bin/sh
TMPDIR=/usr/tmp/install$$
OUTFILE=/tmp/outfiles
CPLOG=/tmp/cplog$$
trap "trap '' 1 2 3 9 15; cd /; rm -rf ${TMPDIR} ${CPLOG}; echo You have canceled the installation.; sync; exit 1" 1 2 3 9 15

					# check for supar user 
RC=`id | sed -e 's/uid=//' -e 's/(.*//'`
if [ "$RC" != "0" ]
then
echo  "
You (${LOGNAME}) do not have permission to perform software Installation
Please consult your Operations/System Administration Guide for more \
information on assigning permissions to privileged operations."
	exit 1
fi
DISTRIBUTOR=0
rm -rf ${TMPDIR}
if [ ! -d /usr/tmp ]
then
	mkdir /usr/tmp
fi
mkdir ${TMPDIR}
echo "
Please mount the (first, if multiple tapes) distribution
tape, then press return... "
read Ans
echo "Verifying tape type ( possibly reading, please wait )......."
#mt -f /dev/rmt/ctape0 rewind
cd ${TMPDIR}
cpio -icdu < /dev/rmt/ctape0 2>${CPLOG}
					# if a cpio tape, check if the Install
					#  Name and Size files are there
if [ $? -eq 0 ]
then
	valid=y
	FILES="Install Remove Size Name"
	for i in ${FILES}
	do
		if [ ! -f $i ]
		then
			valid=n
			break
		fi
	done
	if [ $valid = "y" ]
	then
		echo "
The Distribution tape is in 5.3 Format"
		DISTRIBUTOR=PRIME
	fi
else

					# Not in 5.3 format
	mt -f /dev/rmt/ctape0 rewind
	Ibs="" 
	Id="`dd if=/dev/rmt/ctape0 $Ibs 2>/dev/null | sed -e '2,$d'`"
	case "$Id" in
		"") Id=bogusid ;;
		esac
	set $Id
	if [ $# = 3 ]
	then
		echo "
The Distribution tape is in RISC/os Format

===============================Warning===========================
This utility is designed only to install Application Software.
Please do not take the system to single user mode. If you do
so, SYSADM will have no record of its being installed and
unable to display it by 'displaypkg' or remove it by 'removepkg'.
=================================================================

"
		PATH=$PATH:/etc; export PATH
		DISTRIBUTOR=MIPS
	fi
fi
if [ ${DISTRIBUTOR} = 0 ]
then 
	rm -rf ${TMPDIR}
	echo "Bad tape type\n\n"
	exit 1
fi
export DISTRIBUTOR TMPDIR CPLOG
echo "
Please do no not remove the tape until Software Installation is complete"
sleep 2
