#!/bin/bash
# -----------------------------------------------------------------------------
# jruby-ng - Start Script for the JRuby interpreter, using NailGun
#
# -----------------------------------------------------------------------------

cygwin=false

# ----- Identify OS we are running under --------------------------------------
case "`uname`" in
CYGWIN*) cygwin=true
esac

# ----- Verify and Set Required Environment Variables -------------------------

## resolve links - $0 may be a link to  home
PRG=$0
progname=`basename "$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

JRUBY_HOME_1=`dirname "$PRG"`           # the ./bin dir
JRUBY_HOME_1=`dirname "$JRUBY_HOME_1"`  # the . dir
if [ -d "${JRUBY_HOME_1}/lib" ] ; then
  JRUBY_HOME="${JRUBY_HOME_1}"
fi

# ----- Execute The Requested Command -----------------------------------------

if $cygwin; then
  JAVA_HOME=`cygpath --mixed "$JAVA_HOME"`
  JRUBY_HOME=`cygpath --mixed "$JRUBY_HOME"`
fi

exec $JRUBY_HOME/tool/nailgun/ng org.jruby.util.NailMain $JRUBY_OPTS "$@"
