#	START NEW ARIX SCCS HEADER
#
#	@(#) installpkg: version 25.1 created on 12/2/91 at 16:57:12
#
#	Copyright (c) 1990 by Arix Corporation
#	All Rights Reserved
#
#	@(#)installpkg	25.1	12/2/91 Copyright (c) 1990 by Arix Corporation
#
#	END NEW ARIX SCCS HEADER
#

#	ATT: ident	"sadmin:admin/menu/softwaremgmt/installpkg	2.6"

#ident	"@(#)sadmin/admin/menu/softwaremgmt:installpkg	1.1"

#menu# install new software package onto built-in disk
#help# 
#help#	Installpkg copies files from tape to the built-in disk and
#help#	performs additional work as necessary so you can run that software.

flags="-qq -k$$"
trap 'exit 0' 1 2  15
PATH=/bin:/usr/bin:/usr/lbin:/etc export PATH
REW="rmt1 9mt1"
NOREW="rmt0 9mt0"

echo "\n\n"

type=`checklist ${flags} -pfe \
	'Are you installing a new package, or do you want to re-install
a package previously removed by removepkg [i, r, q]:' install re-install`

rew=`selectdevice \
  -q "Choose the rewind device to use for [re]installing the packages." \
  -c $$ /dev ${REW}`

while :; do
	norew=`selectdevice -q \
	"Choose the no-rewind device to use for [re]installing the packages." \
	-c $$ /dev ${NOREW}`
	echo
	if [ "$norew" = "$rew" ]
	then
		echo "\nThe rewind and no-rewind devices must be different.  Try again."
		continue
	fi
	break
done

if [ "${type}" = "install" ]
then :
	if [ -d /install ] 	
	then
		cd /install
	else
		mkdir /install
		chmod 775 /install
		cd /install 
	fi
	cpio -iud <$rew 2>/dev/null
	if [ ! -f INSTALL ]
	then
		echo "\nThis tape is not a proper software distribution tape.  Cannot find "INSTALL" file.\n"
		exit 2
	fi
	./INSTALL $rew $norew	# extra parameters here as required
	rm -f INSTALL
	echo "\nInstallation completed"
	exit 0
fi

cd /; cpio -iv < $rew >/tmp/$$rmpkg 2>/dev/null
if grep '/tmp/rmpkgtoc$' /tmp/$$rmpkg > /dev/null
then
	cpio -i <$rew 2>/dev/null
else
	echo "\nThis tape was not written by removepkg. This command will
only restore packages which have been saved by removepkg.\n"
	exit 2
fi

echo "\nThe following software packages are stored on the tape in ${rew}:"
cat /tmp/rmpkgtoc|sed 's/^/	/'
choices=`cat /tmp/rmpkgtoc`
pkgs=`checklist ${flags} -fe -l ' ' -H'
	Type in the names of the software packages you want reinstalled
	from the tape in ${rew}.' \
	'Enter the names of the packages to be reinstalled [?, q]:' ${choices}`

< ${norew}
for i in ${choices}; do
	if echo ${pkgs}|grep "$i" > /dev/null
	then
		echo "\nReinstalling the $i software package"
		cpio -idmva < ${norew}
		z=`grep "\.$i$" /usr/options/${i}.rlst`
		if [ -n "$z" ]
		then
			if [ ! -s /tmp/$$rinst ]
			then echo "
The following files from the various packages are copies of system files
as they were when the packages were removed from the system.  You may
want to use some of the information in them to complete the reinstallation
process:\n" > /tmp/$$rinst
			fi
			for j in $z; do
				echo "\t$j" >> /tmp/$$rinst
			done
		fi
	else
		echo "Skipping over the $i software package"
		< ${norew}
	fi
done
echo "Rewinding the tape in ${rew}. Please wait."
< ${rew}
if [ -s /tmp/$$rinst ]
then	cat /tmp/$$rinst
fi
echo "\nReinstallions completed."
