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

#ident	"%Z%sadmin/admin/menu/softwaremgmt:%M%	%I%"

#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"
while :; do
type=`checklist ${flags} -pfe -H'
	Installing a new package is not yet supported.  Currently,
	all available package are pre-installed with the default
	5.3 release.
	If you used removepkg to remove software packages from your
	system, and you saved the packages on tape before removing
	them, you may use this subcommand to re-install the package(s).' \
	'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`

	if [ "${type}" = "install" ]
	then
		echo "Installing a new package is not yet supported.\n"
		continue
	fi
	break
done

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

cd /; cpio -itvI $rew >/tmp/$$rmpkg 2>/dev/null
if grep '/tmp/rmpkgtoc$' /tmp/$$rmpkg > /dev/null
then
	cpio -iI $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

while :; do
	norew=`selectdevice \
  	-q "Choose the no-rewind device to use for reinstalling 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

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 -itvI ${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."
