#! /bin/sh

# Shift all arguments by one to get command parameters
getArguments () {
    args=""
    while [ "X$1" !=  "X" ] ; do
        args="${args} $1"
        shift
    done
    echo $args
}

usage() { 
/bin/cat >&2 << EOF

Create a reservation. If reservation is created using agreement, reservation
is made immediately. If reservation is created using rsl file, reservation is
made only after csf-rsv-submit is executed for the reservation.

Options:
	help | usage         	    Display usage
	version          	    Display command version
	rsl    rslFile [rsvName]    Create a reservation instance by using RSL file with/out a 
				    reservation name.
				    rslfile is path to your reservation rsl file.
	agreement agreementFile [rsvName]    		
				    Create a reservation instance by using agreements.
EOF
} 


##### MAIN #####

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

full=`which $0`
dir=`dirname $full`
CONFIG="${dir}/csf.sh"
if [ -r "${CONFIG}" ] ; then
   . "${CONFIG}"
else
   echo "Error: Cannot find ${CONFIG} configuration file"
   exit
fi

##### MAIN #####
if [ $# -lt 1 ]; then
    usage
    exit 1
else
    if [ $1 = "help" -o $1 = "usage" ]; then
        usage
        exit 1
    elif [ $1 = "version" ]; then
       echo $0 version ${CSF_VERSION}
       exit 1 
    elif [ $1 != "rsl" -a $1 != "id" -a $1 != "agreement" ]; then
       echo Error: invalid option 1>&2
       exit 1 

    fi
fi

ARGS=`getArguments "$@"`
java ${RSV_CLIENT} ${RSV_SERVICE} createService $ARGS
return_code=$?

exit $return_code


