feat(fdroid): download tagged releases

This commit is contained in:
ange 2024-02-06 16:39:39 +01:00
parent 718662b9d8
commit 9f03ababcf
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D
4 changed files with 79 additions and 26 deletions

View File

@ -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

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"