@echo off

if "%GLOBUS_LOCATION%" == "" goto nogl
goto gl

:nogl

    echo Error: GLOBUS_LOCATION not set
    goto end

:gl

set CMD_LINE_ARGS=

:setupArgs
if %1a==a goto doneStart
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setupArgs

:doneStart
set LOCALCLASSPATH="%GLOBUS_LOCATION%\lib\bootstrap.jar";"%GLOBUS_LOCATION%\lib\cog-url.jar";"%GLOBUS_LOCATION%\lib\axis-url.jar"
set LOCAL_OPTS=-DGLOBUS_LOCATION="%GLOBUS_LOCATION%" -Djava.endorsed.dirs="%GLOBUS_LOCATION%\endorsed"

if "%X509_USER_PROXY%" == "" goto portRange1
set LOCAL_OPTS=-DX509_USER_PROXY="%X509_USER_PROXY%" %LOCAL_OPTS%

:portRange1
if "%GLOBUS_TCP_PORT_RANGE%" == "" goto portRange2
set LOCAL_OPTS=-DGLOBUS_TCP_PORT_RANGE=%GLOBUS_TCP_PORT_RANGE% %LOCAL_OPTS%

:portRange2
if "%GLOBUS_TCP_SOURCE_PORT_RANGE%" == "" goto portRange3
set LOCAL_OPTS=-DGLOBUS_TCP_SOURCE_PORT_RANGE=%GLOBUS_TCP_SOURCE_PORT_RANGE% %LOCAL_OPTS%

:portRange3
if "%GLOBUS_UDP_SOURCE_PORT_RANGE%" == "" goto caCertDir
set LOCAL_OPTS=-DGLOBUS_UDP_SOURCE_PORT_RANGE=%GLOBUS_UDP_SOURCE_PORT_RANGE% %LOCAL_OPTS%

:caCertDir
if "%X509_CERT_DIR%" == "" goto hostname
set LOCAL_OPTS=-DX509_CERT_DIR="%X509_CERT_DIR%" %LOCAL_OPTS%

:hostname
if "%GLOBUS_HOSTNAME%" == "" goto ibmvm
set LOCAL_OPTS=-DGLOBUS_HOSTNAME=%GLOBUS_HOSTNAME% %LOCAL_OPTS%

:ibmvm
if not "%IBM_JAVA_OPTIONS%" == "" goto run
set IBM_JAVA_OPTIONS=-Xquickstart

:run
set _RUNJAVA=java
if not "%JAVA_HOME%" == "" set _RUNJAVA="%JAVA_HOME%\bin\java"
%_RUNJAVA%  %LOCAL_OPTS% %GLOBUS_OPTIONS% -classpath %LOCALCLASSPATH% org.globus.bootstrap.Bootstrap org.globus.tools.ProxyInfo %CMD_LINE_ARGS%

:end
