From e84b25458cc3721e641547a546a353cc7938c770 Mon Sep 17 00:00:00 2001 From: thespad Date: Sun, 22 Dec 2024 15:49:43 +0000 Subject: [PATCH] If lockfile found, use cached download --- docker-mods.v3 | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/docker-mods.v3 b/docker-mods.v3 index c5bb7d9..ff033df 100755 --- a/docker-mods.v3 +++ b/docker-mods.v3 @@ -381,30 +381,34 @@ run_mods() { for ((i = 5 ; i < 21 ; i=i*2 )); do sleep $i if [[ ! -f "/modcache/${FILENAME}.lock" ]]; then + SKIP_MOD_DOWNLOAD=true break elif [[ $i == 20 ]]; then write_mod_error "${DOCKER_MOD} timed out waiting for lock, skipping\n\tIf no other containers are using this mod you may need to delete /modcache/${FILENAME}.lock" - SKIP_MOD_DOWNLOAD=true + SKIP_MOD=true fi done fi - if [[ "${SKIP_MOD_DOWNLOAD}" == "true" ]]; then + if [[ "${SKIP_MOD}" == "true" ]]; then continue + elif [[ "${SKIP_MOD_DOWNLOAD}" != "true" ]]; then + # Download and extract layer to / + touch "/modcache/${FILENAME}.lock" + curl -f --retry 5 --retry-max-time 30 --retry-all-errors \ + ${CURL_NOISE_LEVEL} \ + --location \ + --header "Authorization: Bearer ${TOKEN}" \ + --user-agent "${MOD_UA}" \ + "${BLOB_URL}${SHALAYER}" -o \ + "/modcache/${FILENAME}.tar.xz" fi - # Download and extract layer to / - touch "/modcache/${FILENAME}.lock" - curl -f --retry 5 --retry-max-time 30 --retry-all-errors \ - ${CURL_NOISE_LEVEL} \ - --location \ - --header "Authorization: Bearer ${TOKEN}" \ - --user-agent "${MOD_UA}" \ - "${BLOB_URL}${SHALAYER}" -o \ - "/modcache/${FILENAME}.tar.xz" - if ! tar -tzf "/modcache/${FILENAME}.tar.xz" >/dev/null 2>&1; then - write_mod_error "Invalid tarball, could not download ${DOCKER_MOD} from ${REGISTRY}" + fi + if ! tar -tzf "/modcache/${FILENAME}.tar.xz" >/dev/null 2>&1; then + write_mod_error "Invalid tarball for ${DOCKER_MOD}, skipping" + if [[ -f "/modcache/${FILENAME}.lock" ]]; then rm "/modcache/${FILENAME}.lock" || write_mod_error "Failed to delete lock file /modcache/${FILENAME}.lock" - continue fi + continue fi write_mod_info "Installing ${DOCKER_MOD}" mkdir -p /tmp/mod