#!/bin/sh
#
# Copyright (c) 2003 by Sun Microsystems, Inc.
# All rights reserved.
#
#ident "@(#)preremove 1.0 - 01/10/17"

# Check to see if the admin server is configured. If it is the
# case quit the pkgrm process, otherwise continue with pkgrm.

# Directory server(s)
MPS_SR="/var/mps/serverroot"
BASEDIR=`pkginfo -r SUNWasvu | head -1`
NEED_UNCONFIGURATION_MSG="The Administration Server is configured."
HA_CASE=0
if [ -f "${PKG_INSTALL_ROOT}/${BASEDIR}/etc/mps/admin/v5.2/shared/config/serverroot.conf" ]; then
    MPS_SR=`cat ${PKG_INSTALL_ROOT}/${BASEDIR}/etc/mps/admin/v5.2/shared/config/serverroot.conf`
    # identifing whether we are in HA case and if the admin server 
    # unconfiguration has already been performed on another cluster node.
    if [ ! -f ${MPS_SR}/setup/uninstall_*.class ]; then
	NEED_UNCONFIGURATION_MSG="Administration Server is configured on this node."
	HA_CASE=1
    fi
fi
if [ -f ${MPS_SR}/setup/uninstall_Sun_ONE_Administration_Distribution.class ] || [ ${HA_CASE} -eq 1 ]; then
	echo "\n"
	echo "**********************************************************"
	echo ""
	echo "     ${NEED_UNCONFIGURATION_MSG}"
	echo ""
	echo "You must unconfigure the product before removing "
	echo "the package."
	echo ""
	echo "Run the following command:"
	echo "${PKG_INSTALL_ROOT}/${BASEDIR}/usr/sbin/mpsadmserver unconfigure"
	echo ""
	echo "**********************************************************"
	echo "\n"
	exit 1
fi
