#!/bin/sh

#
# ident  "@(#)wbemadmin.sh	1.20 99/11/17 Sun Microsystems"
# Copyright 11/17/99 Sun Microsystems, Inc. All Rights Reserved.
#

PKG=SUNWwbcor
BASEDIR=`/bin/pkgparam $PKG BASEDIR 2>/dev/null`
if [ -z "$BASEDIR" ]    # pkg not installed or installed several times
then
        BASEDIR=/    # set default. Maybe the dir is nfs mounted
fi

ARCH=`uname -p`
JAVACMD="java"
WBSERHOME=${BASEDIR}usr/sadm
USRLIB=${WBSERHOME}/lib
WBSERLIB=${WBSERHOME}/lib/wbem
WBSERBIN=${WBSERHOME}/bin
INSTALLDIR=install.dir

#
#
setJavaPath() {
  if [ -z "$JAVA_HOME" ]
  then 
    JVOK=0
    JVBASEDIR=`/bin/pkginfo -r SUNWjvrt 2>/dev/null`
    if [ -z "$JVBASEDIR" ]
    then
      JVBASEDIR=""
    else
      if [ "$JVBASEDIR" = "/" ] ; then
	JVBASEDIR=""
      fi
      JVOK=`pkgparam SUNWjvrt VERSION | cut -c3-3`
    fi
    if [ $JVOK -gt 0 -a -d "${JVBASEDIR}/usr/java" ]
    then
      JAVA_HOME=${JVBASEDIR}/usr/java
      JAVAPATH=${JVBASEDIR}/usr/java/bin
      JAVALIBS=${JVBASEDIR}/usr/java/lib
      if [ -x "${JAVAPATH}/jre" ]
      then
	JAVACMD="jre"
      fi
    else
      JVBASEDIR=`/bin/pkginfo -r SUNWdthj 2>/dev/null`
      if [ -z "$JVBASEDIR" ]
      then
	JVBASEDIR=/usr
      fi
      if [ -d "${JVBASEDIR}/dt/appconfig/hotjava/runtime" ]
      then
	JAVA_HOME=${JVBASEDIR}/dt/appconfig/hotjava/runtime
	JAVAPATH=${JVBASEDIR}/dt/appconfig/hotjava/runtime/bin
	JAVALIBS=${JVBASEDIR}/dt/appconfig/hotjava/runtime/lib/${ARCH}/green_threads
	if [ -x "${JAVAPATH}/jre" ]
	then
	  JAVACMD="jre"
	fi
      else
	if [ -z "$JAVAPATH" ]
	then
#	  MSG=`${GETTXT} "Can't locate Java runtime"`
#	  echo "${MSG}"
#	  MSG=`${GETTXT} "Install Java runtime or Set JAVA_HOME to its location"`
#	  echo "${MSG}"
	  exit 1
	fi
      fi
    fi
  else 
    JAVAPATH=${JAVA_HOME}/bin
    JAVALIBS=${JAVA_HOME}/lib
    if [ -x "${JAVAPATH}/jre" ]
    then
      JAVACMD="jre"
    fi
  fi
  PATH=${JAVAPATH}:${PATH}:$OLDPATH
  LD_LIBRARY_PATH=${JAVALIBS}:${LD_LIBRARY_PATH}
  export PATH
  export LD_LIBRARY_PATH
# jre doesn't update CLASSPATH if a CLASSPATH is set !
  if [ "${JAVACMD}" = "jre" ]
  then
    CLASSPATH=${JAVA_HOME}/lib/rt.jar:${JAVA_HOME}/lib/i18n.jar:${CLASSPATH}
    CLASSPATH=${JAVA_HOME}/classes:${JAVA_HOME}/lib/classes.zip:${CLASSPATH}
    export CLASSPATH
  fi
	#
	# set JAVA_COMPILER to none on intel. bug in the JIT compiler
	#
	if [ `/bin/uname -p` = i386 ]
	then
		JAVA_COMPILER=none
		export JAVA_COMPILER
	fi
}
# --------- end setJavaPath


OLDPATH=$PATH
PATH=/usr/sbin:/sbin:/usr/bin:${WBSERLIB}

LD_LIBRARY_PATH=${WBSERLIB}:${LD_LIBRARY_PATH}
CLASSPATH=${WBSERLIB}:${WBSERLIB}/wbemadmin.jar:${WBSERLIB}/cimapi.jar:${USRLIB}/xml.jar

export PATH
export LD_LIBRARY_PATH
export CLASSPATH

JAVA_PATH=/usr/java
if [ "$JAVA_HOME" = "" ]; then
    JAVA_HOME=/usr/java
    export JAVA_HOME
fi
setJavaPath

# 
	CIMADMSERVER=com/sun/wbem/apps/wbemadmin/WBEMAdmin
	umask 066
	${JAVACMD} -D"${INSTALLDIR}=${WBSERLIB}" $CIMADMSERVER &

exit 0
