# $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: removepkg 1.6 89/10/10 $@(#)sadmin:admin/menu/softwaremgmt/removepkg	2.7"
#menu# remove previously installed package from system
#help#
#help#	This subcommand show you a list of currently installed software
#help#	packages.
#help#	It then will perform whatever actions are necessary to remove
#help#	software packages you specify.

trap 'exit 0' 1 2  15

optdir=/usr/options

#list sw packages - from listpkg
unset c
if [ -d ${optdir} ]
then
	cd ${optdir}
	c=`ls */*.name 2>/dev/null  |  sed 's/\.name$//'`
	if [ -n "${c}" ]
	then
		echo '\n\tThe following software packages have been installed:\n'
		for i in ${c}
		do
			( echo "`basename ${i}`\t\c"; cat ${i}.name ) | pr -w79 -t -e9 -
		done
	fi
fi
if [ -z "${c}" ]
then
	echo '\n\tNo software packages have been installed.'
	exit 0
fi
echo ''

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

if [ ! -d ${optdir}/${pkg} ]
then
	echo '\n\tRequested software is not installed.'
	exit 1
fi

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

cd ${optdir}/${pkg}

./UNINSTALL
