#!/bin/sh

source /opt/gensoft/adm/etc/profile.d/modules.sh && module load apptainer/1.2.5

# bind mount specific FS to be abble to accces usual files
# /pasteur => homes, projets
# /local => scratch, databases
# /mount => gensoft 
# ${HOME} to be sure to have ~ 

# bind mount not always available: cluster vs other machine
MOUNTS=''
if [ -d /pasteur ]; then MOUNTS="${MOUNTS} -B /pasteur"; fi
if [ -d /local/scratch ]; then MOUNTS="${MOUNTS} -B /local/scratch"; fi
if [ -d /mount ]; then MOUNTS="${MOUNTS} -B /mount"; fi
if [ -d /run/user/${UID} ]; then MOUNTS="${MOUNTS} -B /run/user/${UID}"; fi
if [ ! -z ${TMPDIR} ]; then MOUNTS="${MOUNTS} -B ${TMPDIR}:/tmp"; fi

#---- create and mount specific wine folder
test -d ${HOME}/.wine || mkdir ${HOME}/.wine
# and add it to mount points
MOUNTS="${MOUNTS} -B ${HOME}/.wine:/mywineprefix"

PROG=$(basename $0)

test "x$DEBUG" = xx && cat <<EOT 
"############################################################" 
apptainer run --cleanenv ${ENV_OPT} --writable-tmpfs \
                -B ${HOME} \
                ${MOUNTS} \
                /opt/gensoft/exe/ProteoWizard/3.0/libexec/ProteoWizard-3.0.simg \
                ${PROG} \
                ${1+"$@"} 
"############################################################\n"
EOT

apptainer run --cleanenv ${ENV_OPT} --writable-tmpfs\
                 -B ${HOME} \
                 ${MOUNTS} \
                 /opt/gensoft/exe/ProteoWizard/3.0/libexec/ProteoWizard-3.0.simg \
                 ${PROG} \
                 ${1+"$@"} 

