#!/bin/ksh
###################################################################
#             (C) COPYRIGHT Candle Corporation 1999               #
#                      All Rights Reserved                        #
#                                                                 #
#       Licensed Materials - Property of Candle Corporation       #
#         Duplication or disclosure prohibited without the        #
#        expressed written consent of the Candle Corporation.     #
#                                                                 #
###################################################################

Err_report()
{
  case $1 in
    #$NLS-E$ "$PROGNAME warning:  $2, continuing ..."
    warn) print -u2 "$PROGNAME `nls_replace 'KCI0535I'`:  $2, `nls_replace 'KCI0536I'` ..."
          sleep 2
          return
          ;;
	#$NLS-E$ "$PROGNAME failure:  $2."	  
    fail) print -u2 "$PROGNAME `nls_replace 'KCI0537I'`:  $2."
          exit 2
          ;;
    info) print -u2 "$PROGNAME        :  $2."
          return
          ;;
  esac
}

Use_report()
{
  print -u2 "$PROGNAME [ -h CANDLEHOME ]" 
  exit 2
}


###################################################################
#                          Main                                   #
###################################################################
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
PROGNAME=$(basename $0)
silentMode=""
BINDIR=`pwd`
CANDLEHOME=`dirname "$BINDIR"`
while getopts :h:p: opt
do
  case $opt in
    h) CANDLEHOME=$OPTARG
       CANDLEHOME=$(eval print $CANDLEHOME)  # Process ~ if it was entered.
       ;;
    p) PARM_FILE=$OPTARG
       silentMode=yes
       export PARM_FILE
       export silentMode
       ;;
  esac
done
export CANDLEHOME
export cArch
if [ -z "$CANDLEHOME" ]
then
  #$NLS-E$ "CANDLEHOME not specified"
  Err_report fail "`nls_replace 'KCI0851E' CANDLEHOME`"
fi

if [ $(print "$CANDLEHOME" | wc -w) -ne 1 ]
then
  #$NLS-E$ "Blanks are not permitted in CANDLEHOME"
  Err_report fail "`nls_replace 'KCI0682E' CANDLEHOME`"
fi

# Check for required scripts and text files.

dynShl=$CANDLEHOME/bin/dynarch.shl
[ -x $dynShl ] || Err_report fail "cannot execute \"$dynShl\""

regPath=$CANDLEHOME/registry
archTbl=$regPath/archdsc.tbl  # archTbl is needed by dynarch.shl
#$NLS-E$ "cannot read \"$archTbl\""
[ -r $archTbl ] || Err_report fail "`nls_replace 'KCI0852E' \\"$archTbl\\"`"

# Determine the machine's architecture.

. $dynShl $archTbl  # dynarch.shl will determine a value for cArch.
#$NLS-E$ "could not determine the machine's architecture"
[ -n "$cArch" ] || Err_report fail "`nls_replace 'KCI0853E'`"

# Set the JAVA_HOME location for iKeyMan in runGSkit
 setJavaEnv $cArch
 if [ "X$silentMode" = X ]
 then
   mode=cmd
 else
   mode=silent
 fi
 $CANDLEHOME/bin/runGSkit -mode $mode
exit
