mirror of
https://github.com/kaboomserver/server.git
synced 2025-08-06 21:02:55 +00:00
feat: bibliothek download type
This commit is contained in:
parent
5bd6437d60
commit
6243a0705e
2 changed files with 38 additions and 5 deletions
31
scripts/_sources/_bibliothek.sh
Normal file
31
scripts/_sources/_bibliothek.sh
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Bibliothek is Paper's API for downloading builds
|
||||||
|
# https://docs.papermc.io/misc/downloads-api
|
||||||
|
|
||||||
|
_fetch_latest_build() {
|
||||||
|
builds_url="$1/builds"
|
||||||
|
|
||||||
|
debug "fetch: $builds_url"
|
||||||
|
BUILD_JSON="$(fetch -so- "$builds_url")"
|
||||||
|
|
||||||
|
# We have to read the variables like this because POSIX read
|
||||||
|
# doesn't support reading multiple variables at a time
|
||||||
|
for var in LATEST_BUILD LATEST_BUILD_FILENAME; do
|
||||||
|
read -r "${var?}"
|
||||||
|
done <<FETCH_LATEST_BUILD_HEREDOC
|
||||||
|
$(echo "$BUILD_JSON" \
|
||||||
|
| jq --raw-output --exit-status '.builds[-1] | "\(.build)\n\(.downloads?.application?.name)"')
|
||||||
|
FETCH_LATEST_BUILD_HEREDOC
|
||||||
|
}
|
||||||
|
|
||||||
|
_download_type_bibliothek() {
|
||||||
|
read_args endpoint project version
|
||||||
|
require_args endpoint project version
|
||||||
|
project_url="${arg_endpoint:?}/v2/projects/${arg_project:?}/versions/${arg_version:?}"
|
||||||
|
|
||||||
|
_fetch_latest_build "$project_url"
|
||||||
|
debug "latest file: $LATEST_BUILD_FILENAME ($LATEST_BUILD)"
|
||||||
|
|
||||||
|
download_url="$project_url/builds/$LATEST_BUILD/downloads/$LATEST_BUILD_FILENAME"
|
||||||
|
download "$download_url" "$1"
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
|
|
||||||
|
. "$_SCRIPT_PATH"/_sources/_bibliothek.sh
|
||||||
. "$_SCRIPT_PATH"/_sources/_url.sh
|
. "$_SCRIPT_PATH"/_sources/_url.sh
|
||||||
. "$_SCRIPT_PATH"/_sources/_zip.sh
|
. "$_SCRIPT_PATH"/_sources/_zip.sh
|
||||||
|
|
||||||
|
@ -59,9 +60,10 @@ download_type() {
|
||||||
# Since the args are part of the function's stdin, they will be
|
# Since the args are part of the function's stdin, they will be
|
||||||
# be propagated into the _download_type_... functions.
|
# be propagated into the _download_type_... functions.
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"url") _download_type_url "$2";;
|
"bibliothek") _download_type_bibliothek "$2";;
|
||||||
"zip") _download_type_zip "$2";;
|
"url") _download_type_url "$2";;
|
||||||
*) echo Invalid download type "$1"
|
"zip") _download_type_zip "$2";;
|
||||||
return 1;;
|
*) echo Invalid download type "$1"
|
||||||
|
return 1;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue