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

# Check to see if the directory server is running or configured. For either
# cases quit the pkgrm process, else continue with pkgrm.

# Directory server(s)

if [ -z "$PKG_INSTALL_ROOT" ] ; then
    ROOTDIR="/"
else
    ROOTDIR=$PKG_INSTALL_ROOT
fi

MPS_SR=$ROOTDIR/"/var/mps/serverroot"
HA_CASE=0
if [ -f "$BASEDIR/etc/mps/admin/v5.2/shared/config/serverroot.conf" ]; then
    MPS_SR=$ROOTDIR/`cat $BASEDIR/etc/mps/admin/v5.2/shared/config/serverroot.conf`
	if [ ! -f ${MPS_SR}/setup/uninstall_*.class ]; then
		# there is no more uninstaller: means we are in HA
		HA_CASE=1
	fi
fi

instance_list=`ls -d ${MPS_SR}/slapd-* 2>/dev/null`
if [ ! "x${instance_list}" = x ] || [ ${HA_CASE} -eq 1 ]; then
	echo "\n"
	echo "**********************************************************"
	echo ""
	echo "          Directory Server 5.2 is configured."
	echo ""
	echo "You need to unconfigure the product "
	echo "before removing the package."
	echo ""
	echo "Please run the following command:"
	echo "$BASEDIR/usr/sbin/directoryserver -u 5.2 unconfigure\n"
    echo "" 
    echo "**********************************************************"
    exit 1
fi

exit 0
