#! /bin/sh

EXEC=org.globus.ogsa.client.SetServiceDataByName
DEF_OPTIONS=""
DEF_CMD_OPTIONS=""

updateOptions() {
     
    if [ "X$2" != "X" ] ; then
        GLOBUS_OPTIONS="$GLOBUS_OPTIONS -D$1=$2"
    fi

}

####### MAIN BODY ##########

if [ ! -d "$GLOBUS_LOCATION" ] ; then
    echo "Error: GLOBUS_LOCATION invalid or not set: $GLOBUS_LOCATION" 1>&2
    exit 1
fi

CONFIG=$GLOBUS_LOCATION/etc/templates/unix/setClassPath

if [ -r "${CONFIG}" ] ; then
   . "${CONFIG}"
else
   echo "Error: Cannot find ${CONFIG} configuration file"
   exit
fi

### SETUP OTHER VARIABLES ####

updateOptions "java.endorsed.dirs" "$GLOBUS_LOCATION/endorsed"
updateOptions "org.globus.ogsa.server.webroot" "$GLOBUS_LOCATION"
updateOptions "X509_USER_PROXY" "$X509_USER_PROXY"
updateOptions "GLOBUS_HOSTNAME" "$GLOBUS_HOSTNAME"
updateOptions "GLOBUS_TCP_PORT_RANGE" "$GLOBUS_TCP_PORT_RANGE"

if [ "X${DEF_CMD_OPTIONS}" != "X" ]; then 
    set - ${GLOBUS_OPTIONS} -classpath ${LOCALCLASSPATH} ${EXEC}  ${DEF_CMD_OPTIONS} "$@"
else
    set - ${GLOBUS_OPTIONS} -classpath ${LOCALCLASSPATH} ${EXEC} "$@"
fi

for i in `echo ${DEF_OPTIONS} |cut -d'-' -f1-` ; do
    DEFINE=`echo $i|cut -d'=' -f1`
    VALUE="`eval echo $i|cut -d'=' -f2`"
    set - $DEFINE="$VALUE" "$@"
done


### EXECUTE ############

exec java "$@"



