diff --git a/scripts/_common.sh b/scripts/_common.sh index b3203d5..022683f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -55,19 +55,26 @@ check_path() { download() { debug "downloading $1 to $2" - exitcode=0 - # TTY present: enable curl's progress bar, clear curl output on exit + statuscode=0 + + curl_params="-fL $1 -o $2 --write-out %{http_code}" + + # shellcheck disable=SC2086 # Intentional if [ $_HAS_TTY = 1 ]; then - tput sc 2>/dev/null || true # save cursor pos - - curl -#fL "$1" -o "$2" </dev/tty 3>&1 || exitcode=$? + # TTY present: Enable curl's progress bar, clear it if operation successful + tput sc 2>/dev/null || true # Save cursor pos + statuscode=$(curl -# $curl_params </dev/tty 3>&1) || exitcode=$? if [ $exitcode = 0 ]; then - (tput rc; tput ed) 2>/dev/null || true # reset cursor pos; clear to end + (tput rc; tput ed) 2>/dev/null || true # Reset cursor pos; Clear to end fi else - curl -fL "$1" -o "$2" || exitcode=$? + statuscode=$(curl $curl_params) || exitcode=$? + fi + + if [ "$statuscode" = "404" ]; then + return 100 fi return $exitcode diff --git a/scripts/_sources/_index.sh b/scripts/_sources/_index.sh index 5e4857f..7ed61f2 100644 --- a/scripts/_sources/_index.sh +++ b/scripts/_sources/_index.sh @@ -46,6 +46,8 @@ require_args() { download_with_args() { require_args url + # Unfortunately we cannot handle skip_404 here as "zip" can't + # continue if we 404 download "${arg_url:?}" "$1" } diff --git a/scripts/_sources/_url.sh b/scripts/_sources/_url.sh index eb8482c..e2b2eb7 100644 --- a/scripts/_sources/_url.sh +++ b/scripts/_sources/_url.sh @@ -1,6 +1,12 @@ #!/bin/sh _download_type_url() { - read_args url - download_with_args "$@" + read_args url skip_404 + + exitcode=0 + download_with_args "$@" || exitcode=$? + + if [ $exitcode = 100 ] && [ "${arg_skip_404:-false}" = "true" ]; then + return 0 + fi } diff --git a/scripts/_sources/_zip.sh b/scripts/_sources/_zip.sh index d2c8e36..e5726cc 100644 --- a/scripts/_sources/_zip.sh +++ b/scripts/_sources/_zip.sh @@ -1,7 +1,7 @@ #!/bin/sh _download_type_zip() { - read_args url extract + read_args url skip_404 extract zip_path="$(mktemp --suffix=.zip)" @@ -9,7 +9,12 @@ _download_type_zip() { download_with_args "$zip_path" || exitcode=$? if [ $exitcode != 0 ]; then rm -f "$zip_path" 2>/dev/null - return $exitcode + + if [ $exitcode = 100 ] && [ "${arg_skip_404:-false}" = "true" ]; then + return 0 + else + return $exitcode + fi fi debug "extracting ${arg_extract:?} to $1" diff --git a/scripts/downloads.json b/scripts/downloads.json index 550d5c4..5da5132 100644 --- a/scripts/downloads.json +++ b/scripts/downloads.json @@ -40,26 +40,31 @@ "internal": { "plugins/CommandSpy.jar": { "type": "zip", + "skip_404": true, "url": "https://nightly.link/kaboomserver/commandspy/workflows/main/master/CommandSpy.zip", "extract": "CommandSpy.jar" }, "plugins/Extras.jar": { "type": "zip", + "skip_404": true, "url": "https://nightly.link/kaboomserver/extras/workflows/main/master/Extras.zip", "extract": "Extras.jar" }, "plugins/iControlU.jar": { "type": "zip", + "skip_404": true, "url": "https://nightly.link/kaboomserver/icontrolu/workflows/main/master/iControlU.zip", "extract": "iControlU.jar" }, "plugins/ParticleTrails.jar": { "type": "zip", + "skip_404": true, "url": "https://nightly.link/kaboomserver/particletrails/workflows/main/master/ParticleTrails.zip", "extract": "ParticleTrails.jar" }, "plugins/Weapons.jar": { "type": "zip", + "skip_404": true, "url": "https://nightly.link/kaboomserver/weapons/workflows/main/master/Weapons.zip", "extract": "Weapons.jar" }