#!/bin/bash
#
# Startup script for the UNICORE Commandline client
#

#
# Installation directory
#
dir=`dirname $0`
if [ "${dir#/}" = "${dir}" ]
then
  if [ "$dir" != "." ]
  then
    dir="$(pwd)/$dir"
  else
    dir="$(pwd)"
  fi
fi

INST="${dir%/bin}"

#Alternatively specify the absolute path of the installation dir here
#INST=

#
# Java command 
#
JAVA=java

#
# Options to the Java VM
#

#
# helper function to set an option if it is not already set
#
# arg1: option name (without leading "-", e.g "Ducc.extensions")
# arg2: option value (e.g. =conf/extensions)
#
Options=( )
set_option(){
	if [[ "$UCC_OPTS" != *$1* ]]
	then
		N=${#Options[*]}
		Options[$N]="-$1$2"
	fi
}


#
# Memory for the VM
#
set_option "Xmx" "128m"

#
# default location of user preferences file
#
set_option "Ducc.preferences" "=${HOME}/.ucc/preferences"

#
# extensions file
#
set_option "Ducc.extensions" "=${INST}/conf/extensions"

#
# log configuration
#
set_option "Dlog4j.configuration" "=file://${INST}/conf/logging.properties"

# set this one if you have ssl problems and need debug info
#set_option "Djavax.net.debug" "=ssl,handshake"

#
# put all jars in lib/ on the classpath
#
CP=.$(find "$INST/lib" -name "*.jar" -exec printf ":{}" \; )


if [ -d ${HOME}/.ucc/lib ]
then
#
# put all jars in ${HOME}/.ucc/lib/ on the classpath
#
CP=$CP:$(find "${HOME}/.ucc/lib" -name "*.jar" -exec printf ":{}" \; )
fi


#
# setup endorsed directory
#
DEFS="-Djava.endorsed.dirs=$INST/lib/endorsed"


#
# go
#
$JAVA "${Options[@]}" ${DEFS} ${UCC_OPTS} -cp "${CP}" de.fzj.unicore.ucc.UCC ${1+"$@"}




