#! /usr/bin/sh
#
# ident	"@(#)preremove	1.7	01/09/27 SMI"
#
# Copyright (c) 2000-2001 by Sun Microsystems, Inc.
# All rights reserved.
#

PATH="/usr/bin:/usr/sbin"
export PATH

iroot=${PKG_INSTALL_ROOT:-$BASEDIR}

############################################################################
#
# instance_count
#
# This function determines the number of installed instances of the provided
# package.
#
# $1 - package name (defaults to this package)
#
############################################################################
instance_count()
{
	pkg=${1:-${PKG}}

	# request infomation on all package instances w/ the name $pkg and count
	# them using the wc command
	count=`pkginfo $pkg.* 2>/dev/null | egrep -v '^ERROR' | wc -l`

	return $count
}


############################################################
# MAIN - execution starts here!
############################################################

# check if this package is the only instance (of this package)
# installed, if so then we can remove the version link since
# we are about to be removed.
instance_count
if [ $? -eq 1 ]; then
	# remove the SMS version link since it is no longer needed by
	# this package or any other instance of this package.
	VER_LINK=${iroot}/etc/opt/SUNWSMS/SMS
	rm -f $VER_LINK > /dev/null 2>&1
	exit $?
fi

exit 0
