diff --git a/fdroid/entrypoint.sh b/fdroid/entrypoint.sh index cf7a836..b087c9f 100755 --- a/fdroid/entrypoint.sh +++ b/fdroid/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/bash -(cd /repo/ +(cd /repo/ || exit 1 fdroid init sed -i \ diff --git a/fdroid/scripts/get_apks.sh b/fdroid/scripts/get_apks.sh index c911f59..576c326 100755 --- a/fdroid/scripts/get_apks.sh +++ b/fdroid/scripts/get_apks.sh @@ -3,6 +3,31 @@ SCRIPT_PATH="$(dirname "$0")" APK_FILE=/apks.txt +function is_newer() { + local url="$1" + local remote_date local_date + local headers; headers="$(curl -sSLI "$url")" + local file; file="$(grep -Po '(?<=filename=).*\.apk' <<< "$headers")" + + if ! [ -f "$file" ]; then + return 0 + fi + remote_date="$(sed -n 's/last-modified: //p' <<< "$headers")" + local_date="$(stat "$file" | sed -n 's/^Modify: //p')" + [ "$(date -d "$remote_date" '+%s')" -gt "$(date -d "$local_date" '+%s')" ] +} + +function filter_links() { + links=() + + for link in "$@"; do + if is_newer "$link"; then + links+=("$link") + fi + done + echo "${links[@]}" +} + function get_links() { local file="$1" local url @@ -22,13 +47,16 @@ function get_links() { *) ;; esac - done < <(awk 'NF && $1!~/^#/' "$file") + done < <(awk 'NF && $1!~/^#/' "$file" | sort -u) } function main() { - local links; links="$(get_links "$APK_FILE")" + local links - (cd /repo/repo/ && xargs -n1 -P8 curl -LOC- <<< "$LINKS") + readarray -t links < <(get_links "$APK_FILE" | sort -u) + read -ra links < <(filter_links "${links[@]}") + + (cd /repo/repo/ && xargs -n1 -P8 curl -sSLO <<< "${links[@]}") (cd /repo/ && fdroid update -c) if [ -n "$PUID" ]; then diff --git a/fdroid/scripts/get_gitlab_dl_links.sh b/fdroid/scripts/get_gitlab_dl_links.sh index 7b0ed76..2eb115d 100755 --- a/fdroid/scripts/get_gitlab_dl_links.sh +++ b/fdroid/scripts/get_gitlab_dl_links.sh @@ -6,14 +6,14 @@ function get_tag_urls() { local repo="$1" local tag="$2" - curl -L "$API/projects/$repo/releases/$tag" | \ + curl -sSL "$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" | \ + curl -sSL "$API/projects/$repo/releases" | \ jq -r '.[0].assets.links[] | select(.name | test(".apk$")) | .url' }