#!/bin/sh
#
# Copyright (c) 2002 by Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#ident "@(#)prebackout 1.0 - 02/10/23"


stop_patch=no
cmd_torun=

# Admin server first
if [ -f ${ROOTDIR}/usr/iplanet/admserv5.1/admin-serv/logs/pid ]
then
    stop_patch=yes
    echo "Admin Server is running"
    cmd_torun="/usr/sbin/directoryserver stop-admin\n"
fi

# Directory server(s)
instance_list=`ls -d ${ROOTDIR}/var/ds5/slapd-* 2>/dev/null`
if [ ! "x${instance_list}" = x ]
then
    for i in `ls -d ${ROOTDIR}/var/ds5/slapd-*`
    do
	if [ -f ${i}/logs/pid ]
	then
	    stop_patch=yes
	    servername=`/bin/basename $i | /bin/awk '{ print substr($0,7,length($0)-6) }'` 
	    echo "Directory Server is running for instance ${i}"
	    cmd_torun="${cmd_torun}/usr/sbin/directoryserver -s ${servername} stop\n"
	fi
    done
fi

if [ ${stop_patch} = yes ]
then
    echo "You need to stop the servers before removing this patch."
    if [ "x${ROOTDIR}" = x ] || [ "x${ROOTDIR}" = "x/" ]
    then
	echo "Please run the following commands:"
    else
	echo "Please log on the machine on which this patch is to be"
	echo "installed and run the following commands:"
    fi
    echo ${cmd_torun}
    exit 1
fi


exit 0
