feat: github download source

This commit is contained in:
amyavi 2025-02-12 01:46:55 -03:00
parent be2d2943a2
commit 198f009cab
Signed by: amy
SSH key fingerprint: SHA256:CoLIqZWDYPZEhs1j1HQWwV0j1JhC3BFWcaUF7ZLZHJA
2 changed files with 22 additions and 0 deletions
scripts/_sources

View file

@ -0,0 +1,20 @@
#!/bin/sh
_fetch_github_asset() {
list_release_url="https://api.github.com/repos/$1/releases"
debug "fetch: $list_release_url"
# We have to read the variables like this because POSIX read
# doesn't support reading multiple variables at a time
download_url="$(fetch -so- "$list_release_url" | \
jq --raw-output --exit-status --arg filter "$2" \
'.[0].assets[] | select(.name | test($filter)) | .browser_download_url')"
}
_download_type_github() {
read_args repo asset
require_args repo asset
_fetch_github_asset "${arg_repo:?}" "${arg_asset:?}"
download "$download_url" "$1"
}

View file

@ -2,6 +2,7 @@
# shellcheck disable=SC1091
. "$_SCRIPT_PATH"/_sources/_bibliothek.sh
. "$_SCRIPT_PATH"/_sources/_github.sh
. "$_SCRIPT_PATH"/_sources/_url.sh
. "$_SCRIPT_PATH"/_sources/_zip.sh
@ -61,6 +62,7 @@ download_type() {
# be propagated into the _download_type_... functions.
case "$1" in
"bibliothek") _download_type_bibliothek "$2";;
"github") _download_type_github "$2";;
"url") _download_type_url "$2";;
"zip") _download_type_zip "$2";;
*) echo Invalid download type "$1"