#!/bin/bash -f

# Copyright © 2018-2023, Spillbox. All rights reserved.
# Property of Spillbox Inc.
# Any kind of copying or producing derivative work is prohibited without
# explicit written consent from Spillbox Inc.

#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
case "$0" in
        ./*|/*)
                DIR="$(realpath $(dirname $0))"
                 ;;
        -bash)
                echo "Do not source this file"
                return
                ;;
         *)
               tmp=$(which $0)
               DIR="$(realpath $(dirname $tmp))"
                 ;;
esac
cmd=$(basename $0)

unset SPILLBOX_TRANSPORT_SERVER

if [[ "$SPLAPP_MULTI_CLUSTER" == "lsf" && "$SPILLBOX_SPLWRAPPER" == "" ]]; then
    setup_file=$DIR/setup.sh;
    if [ -f "$setup_file" ]; then
        . $setup_file
    fi
    if [[ -z "${LSF_BINDIR}" ]]; then
        echo "LSF_BINDIR environment not set. Please source LSF setup. "
        exit 1
    fi 
    exec $LSF_BINDIR/$cmd "$@"
else
    exec $DIR/../splrun brun -remote $cmd "$@"
fi

