#! /bin/sh
trap _abort 1 2 3 15
_abort()
{
exitCode=$?
rm -f $hadbm_envfile
tty > /dev/null && stty echo
exit $exitCode
}


if [ -n "$JAVA_HOME"  ] ; then
  JAVACMD="$JAVA_HOME/bin/java"
else
  JAVACMD=`which java`
fi
 
if [ ! -x "$JAVACMD" ] ; then
  echo "Error: JAVA_HOME is not defined correctly."
  echo "  We cannot execute $JAVACMD"
  exit 1
fi

JAVAVERSION=`$JAVACMD -version 2>&1 |egrep 1.4` 
if [ -z "$JAVAVERSION" ] ; then
  echo "Error: JAVA_HOME is not defined correctly to point to J2SE 1.4"
  exit 1
fi

progdir=`dirname "$0"`
progname=`basename "$0"`

installdir="$progdir/.."

# absolutize installdir
oldpwd=`pwd` ; cd "${installdir}"; installdir=`pwd`; cd "${oldpwd}"; unset oldpwd

hadbm_envfile="/tmp/hadbm_env.$$"

if [ -x /usr/bin/env ] ; then
    /usr/bin/env | egrep HADBM_ > "$hadbm_envfile"
else
    echo "" > "$hadbm_envfile"
fi  

echo InstallDir=$installdir/bin >> "$hadbm_envfile"
LIBDIR=$installdir/lib

$JAVACMD  -Duser.path=$PATH -Dosenv=$hadbm_envfile -DCliName=$progname -DIFS="$IFS" -DInstallDir=$installdir/bin -Djava.util.logging.config.file=$LIBDIR/hadbmlogging.properties -cp $LIBDIR/hadbm.jar:$LIBDIR/hadbmgt.jar:$LIBDIR/hadbjdbc4.jar com.sun.hadb.cli.framework.AdminMain "${@}"
exitCode=$?
tty > /dev/null && stty echo
rm -f $hadbm_envfile
exit $exitCode

