#!/bin/ksh 
#
# @02 03/08/05 LCL Add ITMinstall. to JREEXE invocations
# @01 09/06/03 LCL Export saveLang in case we need to use it in CandleAgent.

#################################################################
#             (C) COPYRIGHT Candle Corporation 1998             #
#                      All Rights Reserved                      #
#                                                               #
#       Licensed Materials - Property of Candle Corporation     #
#         Duplication or disclosure prohibited without the      #
#        expressed written consent of the Candle Corporation.   #
#                                                               #
#################################################################
bindir=`pwd`/$(dirname $0)
[ "$(print $0 | grep '\./')" = "" ] && [ "$(print $0 | grep '^/.*')" = "" ] && [ `pwd` = '/' ] && bindir=`pwd`$(dirname $0)
[ "$(print $0 | grep '^/.*')" != "" ] && bindir=$(dirname $0)

export TEXTDOMAINDIR=$bindir/../config/nls/msg
export PATH=$bindir:$PATH

export PATH=/usr/bin:$PATH
if [[ -z "$ITMCMD" ]]
then
    PROGNAME=$(basename $0)
else
    PROGNAME="$ITMCMD"
fi

DEBUG_CON=""
SAFE_MODE=""

CURR_DIR=$(pwd)

while  getopts ':h:u:?c' OPTS > /dev/null 2>&1
do case $OPTS in
   h) CANDLEHOME=$OPTARG
       ;;
   u) print "\n$PROGNAME [ -h install_dir  ]\n"
      exit 2
       ;;
   c) DEBUG_CON="-debugcon"
       ;;
   ?) print "\n$PROGNAME [ -h install_dir ]\n"
      exit 2
      ;;
   esac
done

[ -n "$CANDLEHOME" ] || CANDLEHOME=$(cd $(dirname $0) ; dirname $(pwd) )
export CANDLEHOME

if [ -z "$CANDLEHOME" ]
then
   #$NLS-E$ "\nCANDLEHOME not specified, use $PROGNAME -h install_dir\n"	
   print "\n `nls_replace 'KCI0410E' CANDLEHOME $PROGNAME '-h install_dir'`\n"
   exit

else
   full=$(print $CANDLEHOME | grep ^/)
   if [ -z "$full" ]
   then
      CANDLEHOME=$CURR_DIR/$CANDLEHOME
   fi
fi

if [ $(print "$CANDLEHOME" | wc -w) -ne 1 ]
then
  #$NLS-E$ "Blanks are not permitted in install_dir"
  nls_replace 'KCI0411E' install_dir >&2
  exit 1
fi


#
# setup the logfile
#
LOGFILE=${CANDLEHOME}/logs/CandleManage.log
if [ ! -f ${LOGFILE} ]
then
    touch ${LOGFILE} > /dev/null 2>&1
fi

# Just for cleanliness, clean up the plugin temp dir
if [ -z "$INST_COMP_CALLPOINT_LOCATION" ]
then
rm -rf /tmp/plugin_tmp
fi

cd $CANDLEHOME/tables || exit 1


# determine architecture


. $CANDLEHOME/bin/dynarch.shl $CANDLEHOME/registry/archdsc.tbl

# EJF (#17239) run ulimit on linux
os=$(print $cArch|cut -c1-2)
[[ $os = "li" || $os = "ls" ]] && ulimit -s unlimited

setJavaEnv $cArch

setKSYLibPath $cArch


savePath=$PATH
export PATH=$savePath:/usr/bin/X11:/usr/openwin/bin

# export saveLang=$LANG
# export LANG=C

space=10000

   $JREEXE -classpath $CLASSPATH $SAFE_MODE -Dkjr.crypto.keyfilesURL="file://${CANDLEHOME}/keyfiles" -DGlobalDbgLevel="$TRACE_LEVEL" -DInstallRASConfig="$CANDLEHOME/config/ITMConfigRAS.properties"  ITMinstall.JFrame1 -dsa $space -ca $cArch -ch $CANDLEHOME -ad "$archDesc" -mo $DEBUG_CON  >> $LOGFILE  2>&1
   
   #$NLS-E$ "A problem occurred.  See logs/CandleManage.log for details."
   [[ $? -ne 0 ]] && nls_replace 'KCI0412E' 'logs/CandleManage.log'

# Restore the library path.  It was saved in dynarch.shl.  The restoration must be done after the
# GUI has exited.

if [ -n "$saveLibPath" ]
then
  [[ "$1" = aix+([0-9]) ]] && export LIBPATH="$saveLibPath"
  [[ "$1" = hp+([0-9]) ]] && export SHLIB_PATH="$saveLibPath"
  [[ "$1" = hpi+([0-9]) ]] && export SHLIB_PATH="$saveLibPath"
  [[ "$1" = sol+([0-9]) ]] && export LD_LIBRARY_PATH="$saveLibPath"
fi

# Just for cleanliness, clean up the plugin temp dir
if [ -z "$INST_COMP_CALLPOINT_LOCATION" ]
then
rm -rf /tmp/plugin_tmp
fi
 
export PATH="$savePath"
#export LANG="$saveLang"
