feat: add skip_404 arg to url/zip download type

This commit is contained in:
amyavi 2024-12-20 16:30:17 -03:00
parent d73ce8a1f6
commit d6244c6e75
Signed by: amy
SSH key fingerprint: SHA256:CoLIqZWDYPZEhs1j1HQWwV0j1JhC3BFWcaUF7ZLZHJA
5 changed files with 36 additions and 11 deletions

View file

@ -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

View file

@ -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"
}

View file

@ -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
}

View file

@ -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"

View file

@ -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"
}