# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.
#ident	"$Header: installpkg 1.9 89/10/10 $@(#)sadmin:admin/menu/softwaremgmt/installpkg	2.6"
#menu# install software package onto system
#help# 
#help#	Installpkg copies files from removable media onto disk and
#help#	performs additional work as necessary so you can run that software.
#help#	From then on, you will have access to that software.
#help#  You must preview the package before you can install it.

trap 'exit 0' 1 2  15

optdir=/usr/options

ddrive=/dev/rSA/ctape0n

#list sw packages - from listpkg
unset c
if [ -d ${optdir} ]
then
	cd ${optdir}
	c=`ls /usr/options 2>/dev/null`
	if [ -n \"${c}\" ]
	then
		echo '\n\tThe following software packages have been previewed:\n'
		for i in ${c}
		do
			if [ -d /usr/options/${i} ]
			then
				if [ -s /usr/options/${i}/preview.log ]
				then
					if [ -s /usr/options/${i}/${i}.name ]
					then
						echo "${i}:\t\c"
						cat /usr/options/${i}/${i}.name
					fi
				fi
			fi
		done
	fi
fi
if [ -z "${c}" ]
then
	echo '\n\tNo software packages have been previewed.'
	exit 0
fi
echo ''

echo '\n\tEnter name of software package to install -
\tor type  "q"  to quit - \c'
read pkg
if [ -z "${pkg}" ] || [ ${pkg} = "q" ]
then
	echo '\n\tNo software packages installed.'
	exit 0
fi

if [ ! -f ${optdir}/${pkg}/preview.log ]
then
	echo '\n\tRequested software has not been previewed.'
	exit 1
fi

if [ ! -f ${optdir}/${pkg}/INSTALL ]
then
	echo '\n\tINSTALL program not found. Cannot remove software.'
	exit 1
fi

if [ ! -f ${optdir}/${pkg}/.preloaded ]
then
	echo "\\n\\tPress <RETURN> when installation media is ready to be read
	\\tor type  \"q\"  to quit - \\c"
	read answer
	if [ "${answer}" ]
	then
		exit 0
	fi

	cd ${optdir}

	if [ ${ddrive} = "/dev/rSA/ctape0n" ]
	then
		echo "\\n\\tRewinding tape..."
	fi
	/etc/mt -f ${ddrive} rew

	skip=0
	#check if the directory ${pkg} is on the tape
	answer=`cpio -itc < ${ddrive} 2>/dev/null | sed -n "/$pkg\/INSTALL/p"`
	if [ -z "${answer}" ]
	then
	        # skip past bootblock and bootprogram if this is a
		# bootable distribution
	        /etc/mt -f ${ddrive} fsf 1
	        answer=`cpio -itc < ${ddrive} 2>/dev/null | sed -n "/$pkg\/INSTALL/p"`
	        if [ -z "${answer}" ]
        	then
                	echo "\\n\\tThis distribution media does not contain ${pkg} software."
	                exit 1
	        fi
	        skip=2
	fi
fi

if [ ! -f ${optdir}/${pkg}/INSTALL ]
then
	echo '\n\tINSTALL program not found. Cannot install software.'
	exit 1
fi

# Execute the software specific INSTALL program that was read from medium.
cd ${pkg}
./INSTALL delta
