#!/bin/sh
#
# Copyright 2000-2002 Sun Microsystems, Inc. All Rights Reserved.
#
#pragma ident  "@(#)wbemunconfig	1.1 02/05/17"
#
ECHO=/usr/bin/echo
#
#

set `/usr/bin/id`
if [ $1 != "uid=0(root)" ]; then
        $ECHO "You must be root to run this command"
        exit 1
fi

PKG=SUNWwbcor

#  Iterate over all the SUNWwbcor installed versions
#
list=`/bin/pkginfo -l SUNWwbcor* 2> /dev/null \
				| grep PKGINST \
				| sed -e "s/PKGINST://"`

RELOC=

#  Obtain the installation relocation base for SUNWdm
#
if pkginfo -q SUNWdm
then
    _BASEDIR=`/bin/pkgparam SUNWdm BASEDIR 2> /dev/null`
    _PARENTDIR=`/bin/pkgparam SUNWdm PARENTDIR 2> /dev/null`
    RELOC=${_BASEDIR}/${_PARENTDIR}

    foundpkg=

    for pkg in $list
    do
	BASEDIR=`/bin/pkgparam $pkg BASEDIR 2>/dev/null`
	if [ "$BASEDIR" = "$RELOC" ]
	then
	    foundpkg=$pkg
	    break
	fi
    done

    if [ "$foundpkg" = "" ]
    then
	echo $0: ERROR: could not found installed version of WBEM Services >&2
	exit 2
    fi

    BASEDIR=$RELOC
fi

#--------------
# Use pid files to stop  cimomboot, cimom object manager

	for daemon in cimbootserver cimomserver ; do
		pidfile=${BASEDIR}/var/sadm/wbem/logr/$daemon.pid
		if [ -f $pidfile ]; then
			pid=`/usr/bin/cat $pidfile`
			[ "$pid" -gt 0 ] && kill $pid >/dev/null 2>&1
			rm -f $pidfile
		fi
	done

	pkill -u 0 -f -- '-Dapp.name=wbem'

#
#/usr/bin/rm -rf ${BASEDIR}/var/sadm/wbem/logr

#
exit 0
