set -xuve

# This is where I should create the job list and dependencies 
# (/esarchive/autosubmit/a6cd/auto_lb_workflow/workflow-scripts)
EXPID=%EXPID%
ROOTDIR=%ROOTDIR%

# Check that the file with the candidates and the script to create the jobs exist
nproc_candidates_file=${ROOTDIR}/nproc_candidates.txt
create_lb_jobs_script=${ROOTDIR}/auto_lb_workflow/workflow-scripts/mn4/create_ece3_toy_jobs_mn4.sh
if [ ! -f ${nproc_candidates_file} ] || [ ! -f ${create_lb_jobs_script} ]; then
    echo "ERROR: ${nproc_candidates_file} or ${create_lb_jobs_script} does not exist"
    exit 1
fi

# Create a backup of the jobs.conf file only if it does not exist
target_jobs_file=${ROOTDIR}/conf/jobs_${EXPID}.conf
if [ ! -f ${target_jobs_file}.bak ]; then
    cp ${target_jobs_file} ${target_jobs_file}.bak
fi

# Create the jobs by calling the create_lb_jobs script
source ${create_lb_jobs_script} ${EXPID} ${nproc_candidates_file}
echo "LOCAL_SETUP Done"