#!/bin/ksh

Quiet() {
	typeset -r cmd_n_args=$*
	eval "$cmd_n_args" >/dev/null
}

RemoveLink() {
	typeset -r link=$1
	typeset -r pkg=$2

	if [ -h $ROOTDIR/$link ] ; then
		## if the link exists, remove it.
		Quiet removef -R $ROOTDIR $pkg ${ROOTDIR}/$link
		/bin/rm -f $ROOTDIR/$link
	fi
}

GetPaths() {
	cat << EOF
	usr/platform/SUNW,Netra-CP2300/include		SUNWhea
	usr/platform/SUNW,Netra-CP2300/sbin/fruadm 	SUNWkvm
	usr/platform/SUNW,Netra-CP2300/sbin/fruadm 	SUNWfruip
	usr/platform/SUNW,Netra-CP2300/sbin 		SUNWkvm
EOF
}

# Remove the pathnames
typeset pathname= pkg=
GetPaths | while read pathname pkg ; do
	# If the pkg is *NOT* installed on the system,
	# do not remove the link.
	Quiet pkginfo -R $ROOTDIR $pkg 2>/dev/null || continue

	RemoveLink $pathname $pkg
done

# Finalize the removal of pathnames
typeset pkg=
for pkg in $(GetPaths | awk '{print $2}' | sort -u) ; do
	Quiet pkginfo -R $ROOTDIR $pkg 2>/dev/null || continue
	Quiet removef -R $ROOTDIR -f $pkg
done

exit 0
