Rewrite server update script (#148)

* refactor!: rewrite update script

* refactor: split common URL logic into download_with_args

* feat: add skip_404 arg to url/zip download type
This commit is contained in:
amy 2024-12-21 00:24:52 -03:00 committed by GitHub
parent 1f1deda15c
commit c4ca438600
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 373 additions and 69 deletions

56
scripts/update.sh Executable file
View file

@ -0,0 +1,56 @@
#!/bin/sh
# shellcheck disable=SC1091 # Included files should be manually checked
set -e
# Pipefail is part of POSIX.1-2024, however some shells haven't
# implemented it yet. Turn it on only if it's available.
# shellcheck disable=SC3040
if (set -o pipefail 2>/dev/null); then
set -o pipefail
fi
_SCRIPT_PATH="$(dirname "$(readlink -f -- "$0")")"
. "$_SCRIPT_PATH"/_common.sh
. "$_SCRIPT_PATH"/_sources/_index.sh
_FILTER="$1"
if [ "$_FILTER" = "help" ]; then
cat <<USAGE
Usage: scripts/update.sh [FILTER]
Downloads all files contained in scripts/downloads.json. If FILTER
is specified, only files whose JSON paths start with FILTER will be
downloaded.
Examples:
scripts/update.sh server
scripts/update.sh plugins/internal
USAGE
exit 1
fi
_parse_downloads() {
exitcode=0
jq --null-input --raw-output --exit-status \
--arg arg1 "$_FILTER" \
--from-file "$_SCRIPT_PATH"/_parser.jq \
--stream "$_SCRIPT_PATH"/downloads.json || exitcode=$?
if [ $exitcode = 4 ]; then
echo 'No downloads matched the filter.'>&2
return $exitcode
fi
return $exitcode
}
echo "Downloading with filter ${_FILTER:-"<none>"}..."
_parse_downloads | while read -r path; read -r type; read -r args; do
echo "> $path"
if ! check_path "$path"; then
echo "Bailing!"
exit 1
fi
debug "download_type: type=$type; args=$args"
echo "$args" | download_type "$type" "$path"
done