#!/bin/sh
#============================================================
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#============================================================
#   Control script for OpenEJB
#   --------------------------
#    
#   This script is the central entry point to 
#   all of OpenEJB's functions.
#  
#   Contributed by:
#
#    - David Blevins <david.blevins@visi.com>
#    - Daniel S. Haischt <daniel.haischt@daniel-s-haischt.biz>
#             
#               
# ___________________________________________________________
# $Rev: 693920 $ $Date: 2010-09-01 14:07:43 $
#============================================================

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

if [ -z "$OPENEJB_HOME" -o ! -d "$OPENEJB_HOME" ] ; then
  # find OpenEJB
  if [ -d /opt/openejb ] ; then
    OPENEJB_HOME=/opt/openejb
  fi

  if [ -d "${HOME}/opt/openejb" ] ; then
    OPENEJB_HOME="${HOME}/opt/openejb"
  fi

  ## resolve links - $0 may be a link to openejb's home
  PRG="$0"
  progname=`basename "$0"`

  # need this for relative symlinks
  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


  OPENEJB_HOME=`dirname "$PRG"`/..

  # make it fully qualified
  OPENEJB_HOME=`cd "$OPENEJB_HOME" && pwd`
fi

if $cygwin; then
  OPENEJB_HOME=`cygpath --path --windows "$OPENEJB_HOME"`
fi

#echo OPENEJB_HOME = $OPENEJB_HOME

OPTIONS="-Dopenejb.home=$OPENEJB_HOME"

OPENEJB_CORE_JAR="$OPENEJB_HOME/lib/openejb-core-3.1.2.jar"
OPENEJB_JAVAAGENT_JAR="$OPENEJB_HOME/lib/openejb-javaagent-3.1.2.jar"

## Uncomment for easy debug setup
# OPENEJB_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

java $OPENEJB_OPTS "-javaagent:$OPENEJB_JAVAAGENT_JAR" -jar "$OPENEJB_CORE_JAR" "$@"
