#!/bin/sh

#  Script to start the SOG application. If not set the position of
#  this script is taken to be in the SOG part of the standard Starlink
#  Java "bin" directory and will be used to locate the application
#  jar file.

echo "Starting SOG"

#  Find where this script is located, this is SOG_DIR, unless SOG_DIR
#  is already set. 
if test -z "$SOG_DIR"; then
   SOG_DIR=`dirname $0`
fi

#  Locate the application jar file. This is relative to this script or
#  SOG_DIR.
appjar="$SOG_DIR/../../lib/sog/sog.jar"
if test ! -f "$appjar"; then
   echo "Failed to locate the SOG application. Please define SOG_DIR"
   exit
fi

#  Setup any defines that are required. User defines are set in
#  SOG_DEFINES.
defines="-Daxis.EngineConfigFactory=uk.ac.starlink.soap.AppEngineConfigurationFactory"
defines="$defines -Daxis.ServerFactory=uk.ac.starlink.soap.AppAxisServerFactory"
if test ! -z "$SOG_DEFINES"; then
   defines="$SOG_DEFINES $defines"
fi

#  Set the port used for the remote-control web-services. Override
#  default by SOG_PORT
if test -z "$SOG_PORT"; then
   SOG_PORT="8082"
fi

#  Locate the "starjava" command. This should be in ".." or on the 
#  PATH.
if test -f "$SOG_DIR/../starjava"; then
   starjava="$SOG_DIR/../starjava"
else
   starjava="starjava"
fi

#  Check for Cygwin and transform appjar to windows format.
case "`uname`" in
  CYGWIN*) 
    appjar=`cygpath --windows "${appjar}"`
  ;;
esac

#  Run up SOG.
$starjava $defines -jar $appjar -port $SOG_PORT $*
