feat(fdroid): automatic apk download

This commit is contained in:
ange 2024-02-05 16:03:13 +01:00
parent 3c1578e137
commit b4c9f173bd
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D
8 changed files with 87 additions and 6 deletions

View File

@ -2,6 +2,7 @@ BASE_URL=fdroid.
EMAIL= EMAIL=
REPO_NAME=fdroid REPO_NAME=fdroid
CRON_APP_UPDATE='0 0 * * 1'
PUID=1000 PUID=1000
PGID=1000 PGID=1000

View File

@ -1,7 +1,9 @@
FROM docker.io/nginx:latest FROM docker.io/nginx:latest
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
cron \
fdroidserver \ fdroidserver \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY entrypoint.sh /docker-entrypoint.d/99-init-fdroid.sh COPY entrypoint.sh /docker-entrypoint.d/99-entrypoint.sh
COPY scripts/ /usr/local/bin/
COPY default.conf /etc/nginx/conf.d/ COPY default.conf /etc/nginx/conf.d/

6
fdroid/apks.txt Normal file
View File

@ -0,0 +1,6 @@
# 1 URL by line
# Supported URLS patterns:
# - .*github.com/OWNER/REPO.*
# - .*gitlab.com/OWNER/REPO.*
# Exemple:
# https://gitlab.com/fdroid/fdroidclient

View File

@ -18,10 +18,12 @@ services:
environment: environment:
- BASE_URL - BASE_URL
- REPO_NAME - REPO_NAME
- CRON_APP_UPDATE
- PUID - PUID
- PGID - PGID
volumes: volumes:
- ./repo/:/repo/ - ./repo/:/repo/
- ./apks.txt:/:ro
networks: networks:
- nginx - nginx

View File

@ -7,10 +7,10 @@
-e "/repo_url/s .* repo_url:\ https://$BASE_URL/repo " \ -e "/repo_url/s .* repo_url:\ https://$BASE_URL/repo " \
-e "/repo_name/s .* repo_name:\ \"$REPO_NAME\" " \ -e "/repo_name/s .* repo_name:\ \"$REPO_NAME\" " \
config.yml config.yml
fdroid update -c
) )
if [ -n "$PUID" ]; then get_apks.sh
chown -R "$PUID:$PGID" /repo/
fi echo "$CRON_APP_UPDATE root get_apks.sh" > /etc/cron.d/get_new_apks
/etc/init.d/cron start

31
fdroid/scripts/get_apks.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash -e
SCRIPT_PATH="$(dirname "$0")"
function get_links() {
FILE="$1"
awk 'NF && $1!~/^#/' "$FILE" | while read -r URL; do
case "$URL" in
*github.com*)
"$SCRIPT_PATH/get_github_dl_links.sh" "$URL"
;;
*gitlab.com*)
"$SCRIPT_PATH/get_gitlab_dl_links.sh" "$URL"
;;
*)
;;
esac
done
}
LINKS="$(get_links apks.txt)"
(cd /repo/
xargs -n1 -P8 curl -LO <<< "$LINKS"
fdroid update -c
)
if [ -n "$PUID" ]; then
chown -R "$PUID:$PGID" /repo/
fi

View File

@ -0,0 +1,19 @@
#!/bin/bash -e
API='https://api.github.com'
CONTENT_TYPE='"application/vnd.android.package-archive"'
function get_urls() {
local repo="$1"
curl -sSL "$API/repos/$repo/releases/latest" | \
jq -r ".assets.[] | select(.content_type == $CONTENT_TYPE) | .browser_download_url"
}
function get_repo_name_from_url() {
grep -Po '(?<=github.com/)[[:alnum:]]+/[[:alnum:]]+' <<< "$1"
}
for repo in "$@"; do
get_urls "$(get_repo_name_from_url "$repo")"
done

View File

@ -0,0 +1,20 @@
#!/bin/bash -e
API='https://gitlab.com/api/v4'
function get_urls() {
local repo="$1"
curl -L "$API/projects/$repo/releases" | \
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")" | \
jq -sRr '@uri'
}
for repo in "$@"; do
get_urls "$(get_repo_name_from_url "$repo")"
done