#!/bin/sh
#
# $Header: emll/bin/ocmJarUtil /main/2 2010/02/15 09:18:07 asunar Exp $
#
# ocmJarUtil
#
# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 
#
#    NAME
#      ocmJarUtil - <one-line expansion of the name>
#
#    DESCRIPTION
#      <short description of component this file declares/defines>
#
#    NOTES
#      <other useful comments, qualifications, etc.>
#
#    MODIFIED   (MM/DD/YY)
#    asunar      01/27/10 - Adding the definition of dirname command
#    tsubrama    02/22/09 - auto detect jdk/jre home
#    tsubrama    01/19/09 - creation
#    tsubrama    01/19/09 - Creation
#

_usrBinDir=/usr/bin
DIRNAME=${_usrBinDir}/dirname

if [ -z "${CCR_HOME}" ]
then
  echo "CCR_HOME is not found."
  exit 1
fi

## Get JDK/JRE Home (as per the logic in deployPackages)
if [ ! -z "${JAVA_HOME_CCR}" ]
then 
   _JAVA_HOME=${JAVA_HOME_CCR}
elif [ ! -z "${JAVA_HOME}" ]
then 
   _JAVA_HOME=$JAVA_HOME
elif [ ! -z "${CCR_JAVA_HOME}" ] # When it is called from  
then                             # livelink_packages.pl, CCR_JAVA_HOME is found.
  _JAVA_HOME=$CCR_JAVA_HOME
fi
if [ ! -f ${_JAVA_HOME}/bin/java ]
then
  _CCR_PARENT=`$DIRNAME ${CCR_HOME}`
  _JAVA_HOME=${_CCR_PARENT}/jdk
  if [ ! -f ${_JAVA_HOME}/bin/java ]
  then
      _JAVA_HOME=${_CCR_PARENT}/jre
      if [ ! -f ${_JAVA_HOME}/bin/java ]
      then
         _JAVA_HOME=""
      fi
  fi
fi

if [ ! -z "${_JAVA_HOME}" ]
then
   TEMP_JAVA_HOME=${_JAVA_HOME}
fi

if [ -z "${TEMP_JAVA_HOME}" ]
then
  echo "JAVA_HOME is not found."
  exit 1
fi


exec $TEMP_JAVA_HOME/bin/java -classpath $CCR_HOME/bin OCMJarUtil "$@"

## end of script