From 35b233aa6473b83e1385f247a79bb71b5ff08ef0 Mon Sep 17 00:00:00 2001 From: Gordon GECOS Date: Mon, 29 Jul 2024 16:59:35 -0400 Subject: search --- update-repo | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 update-repo (limited to 'update-repo') diff --git a/update-repo b/update-repo new file mode 100755 index 0000000..aa2804b --- /dev/null +++ b/update-repo @@ -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