#!/bin/sh
checkProc()
{
	if [ $# -lt 2 ]
	then
		return 0
	fi
	count=0
	cmdstr="$1"
	while [ $# -gt 1 ]
	do
		shift
		cmdstr="$cmdstr | $GREP \"$1\" "
	done
	cmdstr="$cmdstr | $GREP -v grep | $WC -l"
	count=`eval $cmdstr`

	if [ $count -gt 0 ]
	then
		echo "\nSome of the Sun Management Center Processes are running."
		echo "Please stop them before installing this patch.\n"
		exit 2
	fi
}

OS_V=`uname -r`
if [ 5.8 != $OS_V ] && [ 5.9 != $OS_V ] ; then
   echo "This patch is for SunOS 2.8 and SunOS 2.9. Please install the correct p
atch"
   exit 1
fi 

# If any of the sunMC processes are running
# we need to inform user to stop such processes
# before proceeding with patch installation.

PS="/usr/bin/ps"
GREP="/usr/bin/grep"
WC="/usr/bin/wc"
UCBPS="/usr/ucb/ps"

SUNMCESDPROC="esd - init"
SUNMCJAVASERVER="com.sun.symon.base.server.main.ServerMain"
SUNMCJAVASERVICES="com.sun.symon.base.mgmtservice.main.SunMCServices"
SUNMCJAVAHWDIAG="com.sun.entdiag.server.EDServerRMIServer"
SUNMCDBPROC="ora"
SMCORAU=smcorau

# checkProc <ps command with options> <grep pattern1>...<grep patternN>
checkProc "$PS -ef" "$SUNMCESDPROC" 
checkProc "$PS -ef" "$SUNMCDBPROC" $SMCORAU
checkProc "$UCBPS -wwagx" "$SUNMCJAVASERVER" java
checkProc "$UCBPS -wwagx" "$SUNMCJAVASERVICES" java
checkProc "$UCBPS -wwagx" "$SUNMCJAVAHWDIAG" java
