trap 'exit 3' 15

#+

postremovestat=0

AB2DIR=`pkgparam SUNWab2u BASEDIR 2>> /dev/null`

if [ "$AB2DIR" = "" ]
then
#        echo "WARNING: This package has been removed from this machine,"
#        echo "however an AnswerBook2 server is not accessible to remove collection from AB2 view."
#        echo "WARNING: This Collection will not be accessible until after the AB2 server"
#        echo "         has been installed."
	exit $postremovestat
fi

AB2BIN=${AB2DIR}/lib/ab2/bin
export AB2BIN

#-

if [ ! -x ${AB2BIN}/ab2admin ]
then
   echo "WARNING: Can't see ${AB2BIN}/ab2admin , the AnswerBook2 admin utility,"
   echo "on this machine!"
   echo "apparently this AB2 collection has resided on a file server which "
   echo "does not have the AB2 admin binaries."
   echo ""
   exit $postremovestat
fi

   cmd="${AB2BIN}/ab2admin -o uninstall -n ${PKGINST}"
   eval $cmd

   if [ "$?" -ne 0 ]
   then
	echo "WARNING: postremove failed to remove the AB2 database record"
	echo "for the collection associated with this package."
	echo "This means:"
	echo "The files of this collection have been physically removed,"
	echo "but there may still be a reference to this collection in the "
	echo "local AB2 collection database."
   else
	cmd1="${AB2BIN}/ab2admin -o stop"
	cmd2="${AB2BIN}/ab2admin -o start"
	echo "Restarting the server"
	echo "$cmd1"
	eval $cmd1
	echo "$cmd2"
	eval $cmd2
   fi

exit $postremovestat
