summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon GECOS <u@adam>2024-07-29 11:28:53 -0400
committerGordon GECOS <u@adam>2024-07-29 11:28:53 -0400
commit1bcfddf6cece12f92885d1f618c4587330e8c6a7 (patch)
tree4184d18f30f67d11563479526fbf2169ef1efd28
parent2fe569a12bfba865d7e8ef8dbf9bbbb1a6ad10d1 (diff)
store html in repo/ and use locking
-rwxr-xr-xfdroids.sh43
1 files changed, 31 insertions, 12 deletions
diff --git a/fdroids.sh b/fdroids.sh
index 369c05e..b06d9a7 100755
--- a/fdroids.sh
+++ b/fdroids.sh
@@ -1,30 +1,49 @@
1#!/bin/sh 1#!/bin/bash
2set -ex 2set -e
3quiet() { "$@" >/dev/null 2>&1; } 3quiet() { "$@" >/dev/null 2>&1; }
4quiet dpkg-query -W html-xml-utils || sudo apt install html-xml-utils 4quiet dpkg-query -W html-xml-utils || sudo apt install html-xml-utils
5stale() { [ $(( $(date +%s) - $(stat -c%Y "$1") )) -gt $(( 60*60*12 )) ]; } 5stale() { [ $(( $(date +%s) - $(stat -c%Y "$1") )) -gt $(( 60*60*12 )) ]; }
6wget_with_log()
7{
8 touch "$1"
9 flock "$1" wget -a "$1" "${@:2}"
10}
6if [ -t 0 ] 11if [ -t 0 ]
7then 12then
8 exec < fdroids.txt 13 exec < fdroids.txt
9fi 14fi
10while read url 15while read url
11do 16do
17 baseurl=https://f-droid.org
18 url=${url%/}
12 case "$url" in 19 case "$url" in
13 https://f-droid.org/en/packages/*/) 20 $baseurl/??/packages/*/* | $baseurl/packages/*/* )
14 pkg=${url#https://f-droid.org/en/packages/} 21 continue ;;
15 pkg=${pkg%/} 22 $baseurl/??/packages/* | $baseurl/packages/* )
16 ;; 23 pkg=${url#*/packages/} ;;
17 *) continue ;; 24 * ) continue ;;
18 esac 25 esac
19 html=$pkg.html 26 html=repo/$pkg/index.html
20 if [ ! -e "$html" ] || stale "$html" 27 if [ ! -e "$html" ] || stale "$html"
21 then 28 then
22 wget -a wget-log.txt -c -O "$html" "$url" || { rm -f "$html"; break; } 29 (
30 echo "$pkg" >&2
31 mkdir -p "${html%/*}"
32 cd "${html%/*}" || continue
33 if wget_with_log wget-log.txt -c -O "$html" "$url"
34 then
35 touch "$html"
36 else
37 continue
38 fi
23 link=$(hxwls "$html" | egrep "/repo/${pkg}_[0-9]+\.apk\$" | sort -n | tail -n1) 39 link=$(hxwls "$html" | egrep "/repo/${pkg}_[0-9]+\.apk\$" | sort -n | tail -n1)
24 if [ "$link" ] 40 if [ "$link" ] &&
41 wget_with_log wget-log.txt -c "$link" "$link.asc"
25 then 42 then
26 mkdir -p repo 43 continue
27 (cd repo && wget -c "$link" "$link.asc" -a "$pkg".wget-log.txt) 44 else
45 echo "failed to fetch $pkg" >&2
28 fi 46 fi
47 )
29 fi 48 fi
30done 49done