#!/bin/sh

myArray=( "$@" )
if [[ ! " ${myArray[*]}" =~ " --help" ]]; then
    #---- forbid usage of MGEfinder on submit node.
    #     unless help required
    if [[ $(hostname) = "maestro-submit" ]]; then 
        cat << EOT
************************************************************
*                                                          *
*    you MUST run MGEfinder trough a slurm allocation      *
*        either srun or salloc                             *
*    exiting now                                           *
************************************************************
EOT
        exit -1
    fi 
fi


source /opt/gensoft/adm/etc/profile.d/modules.sh && module load apptainer
# bind mount specific FS to be abble to accces usual files
# /pasteur => homes, projets
# /local => scratch, databases
# ${HOME} to be sure to have ~
# bind mount not always available: cluster vs other machine
#---- APPTAINER_BINDPATH can be set in order to bind mount additional volumes

MOUNTS=''
if [ -d /pasteur ]; then MOUNTS="${MOUNTS} -B /pasteur"; fi
if [ -d /local/databases ]; then MOUNTS="${MOUNTS} -B /local/databases"; fi
if [ -d /local/scratch ]; then MOUNTS="${MOUNTS} -B /local/scratch"; fi
if [ -d /run/user/${UID} ]; then MOUNTS="${MOUNTS} -B /run/user/${UID}"; fi
if [ ! -z ${TMPDIR} ]; then MOUNTS="${MOUNTS} -B ${TMPDIR}:/tmp"; fi

test "x$DEBUG" = xx && cat <<EOT
"############################################################"
apptainer run --cleanenv ${NV} ${ENV_OPT} \
                -B ${HOME} \
                ${MOUNTS} \
                /opt/gensoft/exe/MGEfinder/1.0.6/libexec/MGEfinder-1.0.6.simg \
                `basename $0` ${1+"$@"}
"############################################################\n"
EOT

apptainer run --cleanenv ${NV} ${ENV_OPT} \
                 -B ${HOME} \
                 ${MOUNTS} \
                 /opt/gensoft/exe/MGEfinder/1.0.6/libexec/MGEfinder-1.0.6.simg \
                 `basename $0` ${1+"$@"}
