#!/bin/sh
#
# $RCSfile$
# $Revision: 2098 $
#
# installs framework
#

errorMsg() {
   echo "$*" 1>&2
}
#
# This hack checks if this shell script was called within (most probably) a cygwin context
# during an ssh to a windows box and if so, to actually exec the .bat batch file instead.
#
if [ -n "$OS" -a "$OS" = "Windows_NT" ]
then
   exec cmd.exe /C $RDECK_BASE/bin/rd-setup.bat "$@"
fi

argsOrig=$*


if [ "${RDECK_BASE}X" = "X" ]
then
   #determine base
   PDIR=$(cd `dirname $0/`/../.. && pwd)
   if [ -f "$PDIR/etc/framework.properties" ]
   then
       export RDECK_BASE=$PDIR
   fi
fi
if [ "${RDECK_BASE}X" = "X" ]
then
    errorMsg "RDECK_BASE was not set"
    exit 1
fi

if [ "${JAVA_HOME}X" = "X" ]
then
   errorMsg "JAVA_HOME not set"
   exit 1
fi
if [ ! -x $JAVA_HOME/bin/java ] 
then
   errorMsg "JAVA_HOME not set or set incorrectly"
   exit 1
fi

LIBDIR=$RDECK_BASE/tools/lib
cp=
for i in `ls $LIBDIR/*.jar`
do
  cp=${cp}:${i}
done
PATH=$JAVA_HOME/bin:$RDECK_BASE/bin:/usr/bin:/bin:/usr/sbin:/sbin
export PATH

exec ${JAVA_CMD:-java} -Dant.home=$ANT_HOME \
                    -Duser.java_home=$JAVA_HOME \
                    -Drdeck.base=$RDECK_BASE \
                    -cp $cp \
                    com.dtolabs.launcher.Setup "$@"

if [ $? -ne 0 ]; then
    exit $?
fi

echo "$argsOrig" > $RDECK_BASE/etc/setup.status

exit $?
