#!/bin/sh

#
# ident  "@(#)cimworkshop	1.8 99/07/20 Sun Microsystems"
# Copyright 07/20/99 Sun Microsystems, Inc. All Rights Reserved.
#
#

PKG=SUNWwbapi  # This is the Solaris package for cimapi.jar
BASEDIR=`/bin/pkgparam $PKG BASEDIR 2>/dev/null`
if [ -z "$BASEDIR" ]    # Wbem services pkg not installed or installed several times
then
    BASEDIR=/    # set default. Maybe the dir is nfs mounted
fi

# Get the path to sadm directory
SADMDIR=${BASEDIR}usr/sadm
getsadmdir () {
# Wbem could be installed on a user selected directory - when using Wbem installer -
# in that case wbemInstallDir.properties file will contain the installed directory path.
# Wbem installer uses java "user.home" system property to create this file.
if [ -f /wbemInstallDir.properties ]  # "user.home" = "/" on Solaris
then
    SADMDIR=`grep WBEMINSTALLDIRECTORY /wbemInstallDir.properties|cut -d"=" -f2`"/sadm"
elif [ -f /root/wbemInstallDir.properties ] # "user.home" = "/root" on Linux
then
    SADMDIR=`grep WBEMINSTALLDIRECTORY /root/wbemInstallDir.properties|cut -d"=" -f2`"/sadm"
else
    SADMDIR=..   # properties file not found, use relative path
fi
}
# --------- end getsadmdir
if [ ! -f $SADMDIR/lib/wbem/cimapi.jar ]   # If cimapi.jar does not exists
then
    getsadmdir
fi

USRSADMBIN=${SADMDIR}/bin
USRSADMLIB=${SADMDIR}/lib
SUNWBHOME=${USRSADMLIB}/wbem
INSTALLDIR=install.dir
#

ARCH=`uname -p`
JAVACMD="java"
#
#
setJavaPath() {
  if [ -z "$JAVA_HOME" ]
  then 
    JAVA_HOME=/usr/java
    JAVAPATH=${JVBASEDIR}/usr/java/bin
    JAVALIBS=${JVBASEDIR}/usr/java/lib
  else 
    JAVAPATH=${JAVA_HOME}/bin
    JAVALIBS=${JAVA_HOME}/lib
  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
}
# --------- end setJavaPath


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

LD_LIBRARY_PATH=${USRSADMBIN}:${SUNWBHOME}:${LD_LIBRARY_PATH}
CLASSPATH=.:${SUNWBHOME}:${SUNWBHOME}/cimworkshop.jar:${SUNWBHOME}/cimapi.jar:${USRSADMLIB}/xml.jar

export PATH
export LD_LIBRARY_PATH
export CLASSPATH

setJavaPath

CIMWSSERVER=com.sun.wbem.apps.cimworkshop.CIMWorkshop
umask 066; ${JAVACMD} -D"${INSTALLDIR}=${SUNWBHOME}" $CIMWSSERVER "$@" & 

exit 0

