diff --git a/fdroid/apks.txt b/fdroid/apks.txt index 6f57f80..9504d9b 100644 --- a/fdroid/apks.txt +++ b/fdroid/apks.txt @@ -1,6 +1,16 @@ # 1 URL by line +# lines starting with a # will be ignored +# # Supported URLS patterns: # - .*github.com/OWNER/REPO.* # - .*gitlab.com/OWNER/REPO.* -# Exemple: +# +# line syntax: +# URL [tag] +# +# if no tag, the latest release will be chosen +# +# Examples: # https://gitlab.com/fdroid/fdroidclient +# https://github.com/android-password-store/Android-Password-Store latest + diff --git a/fdroid/scripts/get_apks.sh b/fdroid/scripts/get_apks.sh index dc9e129..c911f59 100755 --- a/fdroid/scripts/get_apks.sh +++ b/fdroid/scripts/get_apks.sh @@ -1,29 +1,39 @@ #!/bin/bash -e SCRIPT_PATH="$(dirname "$0")" +APK_FILE=/apks.txt function get_links() { - FILE="$1" + local file="$1" + local url + local tag + local line - awk 'NF && $1!~/^#/' "$FILE" | while read -r URL; do - case "$URL" in - *github.com*) - "$SCRIPT_PATH/get_github_dl_links.sh" "$URL" + while read -r line; do + IFS=' ' read -r url tag <<< "$line" + + case "$url" in + *github.com/*) + "$SCRIPT_PATH/get_github_dl_links.sh" "$url" "$tag" ;; - *gitlab.com*) - "$SCRIPT_PATH/get_gitlab_dl_links.sh" "$URL" + *gitlab.com/*) + "$SCRIPT_PATH/get_gitlab_dl_links.sh" "$url" "$tag" ;; *) ;; esac - done + done < <(awk 'NF && $1!~/^#/' "$file") } -LINKS="$(get_links /apks.txt)" +function main() { + local links; links="$(get_links "$APK_FILE")" -(cd /repo/repo/ && xargs -n1 -P8 curl -LOC- <<< "$LINKS") -(cd /repo/ && fdroid update -c) + (cd /repo/repo/ && xargs -n1 -P8 curl -LOC- <<< "$LINKS") + (cd /repo/ && fdroid update -c) -if [ -n "$PUID" ]; then - chown -R "$PUID:$PGID" /repo/ -fi + if [ -n "$PUID" ]; then + chown -R "$PUID:$PGID" /repo/ + fi +} + +main "$@" diff --git a/fdroid/scripts/get_github_dl_links.sh b/fdroid/scripts/get_github_dl_links.sh index 7b3c1b8..666ba29 100755 --- a/fdroid/scripts/get_github_dl_links.sh +++ b/fdroid/scripts/get_github_dl_links.sh @@ -1,19 +1,35 @@ #!/bin/bash -e API='https://api.github.com' -CONTENT_TYPE='"application/vnd.android.package-archive"' + +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(.[].content_type == $CONTENT_TYPE) | .[].browser_download_url" + jq -r '.assets[] | select(.name | test(".apk$")) | .browser_download_url' } function get_repo_name_from_url() { - grep -Po '(?<=github.com/)[[:alnum:]]+/[[:alnum:]]+' <<< "$1" + grep -Po '(?<=github.com/)[\w\d-]+/[\w\d-]+' <<< "$1" } -for repo in "$@"; do - get_urls "$(get_repo_name_from_url "$repo")" -done +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 "$@" diff --git a/fdroid/scripts/get_gitlab_dl_links.sh b/fdroid/scripts/get_gitlab_dl_links.sh index 19c1f14..7b0ed76 100755 --- a/fdroid/scripts/get_gitlab_dl_links.sh +++ b/fdroid/scripts/get_gitlab_dl_links.sh @@ -2,19 +2,36 @@ API='https://gitlab.com/api/v4' +function get_tag_urls() { + local repo="$1" + local tag="$2" + + curl -L "$API/projects/$repo/releases/$tag" | \ + jq -r '.assets.links[] | select(.name | test(".apk$")) | .url' +} + function get_urls() { local repo="$1" curl -L "$API/projects/$repo/releases" | \ - jq -r '.[0].assets.links | select(.[].name | test(".apk$")) | .[].url' + jq -r '.[0].assets.links[] | select(.name | test(".apk$")) | .url' } function get_repo_name_from_url() { printf '%s' \ - "$(grep -Po '(?<=gitlab.com/)[[:alnum:]]+/[[:alnum:]]+' <<< "$1")" | \ + "$(grep -Po '(?<=gitlab.com/)[\w\d-]+/[\w\d-]+' <<< "$1")" | \ jq -sRr '@uri' } -for repo in "$@"; do - get_urls "$(get_repo_name_from_url "$repo")" -done +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 "$@"