# $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: previewpkg 1.2 89/10/10 $"
#menu# preview a software package
#help# 
#help#	Previewpkg compares the bill of materials (BOM) file for the
#help#  package, with the current BOM file, if it exist and the files
#help#  currently installed on the system.  It produces a preview.log
#help#  file that is required by the preload and install steps.
#help#  You must preview the package before you can preload or install it.

trap 'exit 0' 1 2  15

optdir=/usr/options

ddrive=/dev/rSA/ctape0n

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

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 | grep /INSTALL`
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 | grep /INSTALL`
        if [ -z "${answer}" ]
        then
                echo "\\n\\tThis distribution media is not a software installation package."
                exit 1
        fi
        skip=2
fi
pkg=`sed -e "s;/INSTALL;;" << END_OF_FILE
${answer}
END_OF_FILE`

echo "\\n\\tDo you wish to install the ${pkg} package (y/n)? - \\c"
while [ true ] ; do
	read reply
	case $reply in
		y)	break ;;
		n)	exit 0 ;;
		*)	echo Enter y or n. ;;
	esac
done
# Extract the INSTALL program from distribution
cd ${optdir}
/etc/mt -f ${ddrive} rew
/etc/mt -f ${ddrive} fsf $skip
cpio -iduvm -C 102400 < ${ddrive} >/dev/null 2>&1

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