#!/bin/bash

DOWNLOAD_DIR=$(dirname $0)

label=$1
if [ -n "${label}" ] ; then
    if [ ! -f "${DOWNLOAD_DIR}/${label}.sif" ] ; then
        echo "Downloading container image \"${label}\"..."
        for try in {1..3}; do
            apptainer pull "${DOWNLOAD_DIR}/${label}.sif" oras://ghcr.io/colvars/devel-containers:"${label}" && break
            retcode=$?
            if [ ${retcode} != 0 ] ; then
                echo "(download failed, retrying...)"
                sleep 15s
            fi
        done
    fi
fi
    
exit ${retcode}
