From fc56bd0adfff665f36f9cf9750c80f731ca509e1 Mon Sep 17 00:00:00 2001 From: Gordon GECOS Date: Mon, 29 Jul 2024 12:21:07 -0400 Subject: cleanup --- .gitignore | 1 + fdroids.sh | 122 +++++++++++++++++++++++++++++++++++++++++++----------------- fdroids.txt | 6 +-- 3 files changed, 91 insertions(+), 38 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d37f1a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +repo/ diff --git a/fdroids.sh b/fdroids.sh index b06d9a7..8830a18 100755 --- a/fdroids.sh +++ b/fdroids.sh @@ -1,49 +1,101 @@ #!/bin/bash set -e -quiet() { "$@" >/dev/null 2>&1; } -quiet dpkg-query -W html-xml-utils || sudo apt install html-xml-utils -stale() { [ $(( $(date +%s) - $(stat -c%Y "$1") )) -gt $(( 60*60*12 )) ]; } +shopt -s lastpipe + +baseurl=https://f-droid.org +stale_hours=12 + +quiet() +{ + "$@" >/dev/null 2>&1 +} + +stale() +{ + [ ! -e "$1" ] || + [ $(( $(date +%s) - $(stat -c%Y "$1") )) -gt $(( 60*60*stale_hours )) ]; +} + wget_with_log() { - touch "$1" + set -- wget-log.txt "$@" + [ -e "$1" ] || touch "$1" flock "$1" wget -a "$1" "${@:2}" } + +list_existing() +{ + find repo/ -maxdepth 1 -type d | + xargs bash -c 'printf "%s\n" "${@#repo/}"' bash +} + +parse_pkgname() +{ + # Set package on succ + set -- "${1%/}" + case "$1" in + '' | $baseurl/??/packages/*/* | $baseurl/packages/*/* ) + false ;; + $baseurl/??/packages/* | $baseurl/packages/* ) + echo "${1#*/packages/}" ;; + */* ) + false ;; + * ) + echo "$1" + ;; + esac +} + +fetch_pkg() +{ + local pkg="$1" + url=$baseurl/en/packages/$url + if wget_with_log -c -O index.html "$url" + then + # Wget might not touch file if it is up-to-date + # with server + touch "$pkgdir"/index.html + else + echo "failed to fetch url ${url@Q}" >&2 + return + fi + + if hxwls "$pkgdir"/index.html | + egrep "^$baseurl/repo/${pkg}_[0-9]+\.apk\$" | + sort -n | + tail -n1 | + read link && + [ "$link" ] + then + (cd "$pkgdir" && + wget_with_log -c "$link" "$link.asc") + else + echo "failed to fetch package ${pkg@Q}" >&2 + fi +} + +quiet dpkg-query -W html-xml-utils || sudo apt install html-xml-utils + if [ -t 0 ] then - exec < fdroids.txt + exec < <(list_existing) fi -while read url +while read do - baseurl=https://f-droid.org - url=${url%/} - case "$url" in - $baseurl/??/packages/*/* | $baseurl/packages/*/* ) - continue ;; - $baseurl/??/packages/* | $baseurl/packages/* ) - pkg=${url#*/packages/} ;; - * ) continue ;; - esac - html=repo/$pkg/index.html - if [ ! -e "$html" ] || stale "$html" + [ "$REPLY" ] || continue + if ! parse_pkgname "$REPLY" | read pkg || ! [ "$pkg" ] + then + echo "Skipping invalid URL: ${REPLY@Q}" >&2 + fi + pkgdir=repo/$pkg + mkdir -p "$pkgdir" + if stale "$pkgdir"/index.html then - ( echo "$pkg" >&2 - mkdir -p "${html%/*}" - cd "${html%/*}" || continue - if wget_with_log wget-log.txt -c -O "$html" "$url" - then - touch "$html" - else - continue - fi - link=$(hxwls "$html" | egrep "/repo/${pkg}_[0-9]+\.apk\$" | sort -n | tail -n1) - if [ "$link" ] && - wget_with_log wget-log.txt -c "$link" "$link.asc" - then - continue - else - echo "failed to fetch $pkg" >&2 - fi - ) + ( + cd "$pkgdir" + fetch_pkg "$pkg" + ) + break fi done diff --git a/fdroids.txt b/fdroids.txt index 7993b85..8daa313 100644 --- a/fdroids.txt +++ b/fdroids.txt @@ -3,13 +3,13 @@ https://f-droid.org/en/packages/com.tutpro.baresip/ https://f-droid.org/en/packages/com.tutpro.baresip.plus/ https://f-droid.org/en/packages/org.jitsi.meet/ https://f-droid.org/en/packages/org.linphone/ -https://f-droid.org/en/packages/org.sipdroid.sipua -https://f-droid.org/en/packages/org.lumicall.android +https://f-droid.org/en/packages/org.sipdroid.sipua/ +https://f-droid.org/en/packages/org.lumicall.android/ https://f-droid.org/en/packages/ro.ui.pttdroid/ https://f-droid.org/en/packages/org.whitequark.sipcaller/ https://f-droid.org/en/packages/eu.siebeck.sipswitch/ https://f-droid.org/en/packages/org.briarproject.briar.android/ -https://f-droid.org/en/packages/com.serwylo.lexica +https://f-droid.org/en/packages/com.serwylo.lexica/ https://f-droid.org/en/packages/com.MarcosDiez.shareviahttp/ https://f-droid.org/en/packages/com.google.zxing.client.android/ -- cgit v1.2.3