From bad38013c1c52ec3238c4dfcf87d2ff1ddfc2eb1 Mon Sep 17 00:00:00 2001 From: Gordon GECOS Date: Mon, 29 Jul 2024 14:52:53 -0400 Subject: fix --- fdroids.sh | 101 ------------------------------------------------- update-fdroids.bash | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 101 deletions(-) delete mode 100755 fdroids.sh create mode 100755 update-fdroids.bash diff --git a/fdroids.sh b/fdroids.sh deleted file mode 100755 index 8830a18..0000000 --- a/fdroids.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/bash -set -e -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() -{ - 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 < <(list_existing) -fi -while read -do - [ "$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 - ( - cd "$pkgdir" - fetch_pkg "$pkg" - ) - break - fi -done diff --git a/update-fdroids.bash b/update-fdroids.bash new file mode 100755 index 0000000..aa2804b --- /dev/null +++ b/update-fdroids.bash @@ -0,0 +1,106 @@ +#!/bin/bash +set -e +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() +{ + 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 +} + +show_pkg() +{ + for x in name summary description + do + hxextract .package-$x "$1" | + w3m -T text/html | + sed -e '/^$/d' + echo + done +} + +fetch_pkg() +{ + local pkg="$1" + url=$baseurl/en/packages/$pkg + if wget_with_log -O index.html.part "$url" + then + mv -T index.html.part index.html + else + echo "failed to fetch url ${url@Q}" >&2 + return 1 + fi + + hxwls index.html | + egrep "^$baseurl/repo/${pkg}_[0-9]+\.apk\$" | + sort -n | + tail -n1 | + read link && + [ "$link" ] || return + show_pkg index.html >&2 + wget_with_log -c "$link" "$link.asc" +} + +quiet dpkg-query -W html-xml-utils || sudo apt install html-xml-utils + +if [ -t 0 ] +then + exec < <(list_existing) +fi +while read +do + [ "$REPLY" ] || continue + if ! parse_pkgname "$REPLY" | read pkg || ! [ "$pkg" ] + then + echo "Skipping invalid URL: ${REPLY@Q}" >&2 + fi + pkgdir=repo/$pkg + mkdir -p "$pkgdir" + stale "$pkgdir"/stamp || continue + stale "$pkgdir"/failstamp || continue + echo "$pkg" >&2 + if ( cd "$pkgdir" && fetch_pkg "$pkg" ) + then + touch "$pkgdir"/stamp + else + touch "$pkgdir"/failstamp + fi +done -- cgit v1.2.3