#!/bin/ksh
#
# @04 03/08/05 LCL Add ITMinstall. to JREEXE invocations
# @03 11/09/01 LCL Check for missing .tmp
# @02 11/07/01 LCL Not-so Initial
# @01 10/10/01 LCL Initial
#
# This script is a shell wrapper for ConvertDB.class. It checks command 
# line arguments and passes them to ConvertDB.class for further processing.

PROGNAME=$(basename $0)

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] [-r] [-v] -f db"
	#$NLS-E$ " -v for verbose operation"
    print -u2 "`nls_replace 'KCI0790I' -v`"
	#$NLS-E$ " -r to revert a database to tinySQL"
    print -u2 "`nls_replace 'KCI0791I' -r tinySQL`"
    exit 2
}

###################################################################
#                         Main Routine                            #
###################################################################
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
UsrCmd="$0 $*"
HOPTION=""
SAFE_MODE=""
VERBOSE=""
REVERT=""
file=""

while getopts ":h:f:t:rv" OPTS
do case $OPTS in
     h) CANDLEHOME=$OPTARG
        HOPTION="ON"
        ;;
     f) file=$OPTARG
        ;;
     r) REVERT="-r"
        ;;
     v) VERBOSE="-v"
        ;;
     ?) Use_report
        ;;
   esac
done

[ -z "$file" ] && Use_report

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

#$NLS-E$ "Cannot set CANDLEHOME environment variable"
[ ! -d "$CANDLEHOME" ] && Err_report fail "`nls_replace 'KCI0792E' CANDLEHOME`"

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

bigK_defaults=$CANDLEHOME/config/.ConfigData/.tmp
if [ ! -d "$bigK_defaults" ] 
then
  #$NLS-E$ "Missing $bigK_defaults"
  Err_report info "`nls_replace 'KCI0793I' $bigK_defaults`"
  #$NLS-E$ "Configuration database defaults directory was not found"
  Err_report fail "`nls_replace 'KCI0794E'`"
fi

CurRegPath=$CANDLEHOME/registry
ArchTbl=$CurRegPath/archdsc.tbl
DynShl=$CANDLEHOME/bin/dynarch.shl

. $DynShl $ArchTbl

setJavaEnv $cArch

$JREEXE -classpath $CLASSPATH $SAFE_MODE -DGlobalDbgLevel="$TRACE_LEVEL" -DInstallRASConfig="$CANDLEHOME/config/ITMConfigRAS.properties" ITMinstall.ConvertDB -ch $CANDLEHOME $VERBOSE $REVERT -f $file
