36 lines
740 B
Bash
Executable File
36 lines
740 B
Bash
Executable File
#!/bin/bash -e
|
|
|
|
API='https://api.github.com'
|
|
|
|
function get_tag_urls() {
|
|
local repo="$1"
|
|
local tag="$2"
|
|
|
|
curl -sSL "$API/repos/$repo/releases/tags/$tag" | \
|
|
jq -r '.assets[] | select(.name | test(".apk$")) | .browser_download_url'
|
|
}
|
|
|
|
function get_urls() {
|
|
local repo="$1"
|
|
|
|
curl -sSL "$API/repos/$repo/releases/latest" | \
|
|
jq -r '.assets[] | select(.name | test(".apk$")) | .browser_download_url'
|
|
}
|
|
|
|
function get_repo_name_from_url() {
|
|
grep -Po '(?<=github.com/)[\w\d-]+/[\w\d-]+' <<< "$1"
|
|
}
|
|
|
|
function main() {
|
|
local repo; repo="$(get_repo_name_from_url "$1")"
|
|
local tag="$2"
|
|
|
|
if [ -z "$tag" ]; then
|
|
get_urls "$repo"
|
|
else
|
|
get_tag_urls "$repo" "$tag"
|
|
fi
|
|
}
|
|
|
|
main "$@"
|