#!/bin/bash
#
# You can set JAVA_HOME to point ot JDK 1.4 
# or shell will try to deterine java location using which
#


if [ -z "$JAVA_HOME" ] ; then
  JAVA=`/usr/bin/which java`
  if [ -z "$JAVA" ] ; then
    echo "Cannot find JAVA. Please set your PATH."
    exit 1
  fi
  JAVA_BIN=`dirname $JAVA`
  JAVA_HOME=$JAVA_BIN/..
else
  JAVA=$JAVA_HOME/bin/java
fi

#echo "JAVA= $JAVA"


if [ ! "`"$JAVA" -version 2>&1 | grep "\ 1\.[456789]"`" ]; then 
    echo Required 1.5 verion of JDK: can not use $JAVA
    echo Current version is:
    "$JAVA" -version
    exit 1
fi 

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '.*/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

PRGDIR=`dirname "$PRG"`

CP=`/bin/sh $PRGDIR/classpath.sh run`

# Cygwin trick
cygwin=false
case "`uname`" in
  CYGWIN*) cygwin=true;
esac

if $cygwin; then
  CP=`cygpath --path --windows "$CP"`
  # JAVA=`cygpath --unix "$JAVA.exe"`
fi

NAME=$1
shift

JAVA_OPTS="-Xmx1024m"
JAVA_OPTS="-Dlog=edu.indiana.extreme.xbaya:ALL $JAVA_OPTS"
JAVA_OPTS="-Dxsoap.port.range=12346-12446 $JAVA_OPTS"
JAVA_OPTS="-Dhttp_transport.server.port.range=12346-12446 $JAVA_OPTS"
JAVA_OPTS="-Djava.endorsed.dirs=lib/endorsed $JAVA_OPTS"

"$JAVA" $JAVA_OPTS -cp $CP org.python.util.jython $NAME "$@"

