diff options
author | Gordon GECOS <u@adam> | 2024-07-29 11:28:53 -0400 |
---|---|---|
committer | Gordon GECOS <u@adam> | 2024-07-29 11:28:53 -0400 |
commit | 1bcfddf6cece12f92885d1f618c4587330e8c6a7 (patch) | |
tree | 4184d18f30f67d11563479526fbf2169ef1efd28 /fdroids.sh | |
parent | 2fe569a12bfba865d7e8ef8dbf9bbbb1a6ad10d1 (diff) |
store html in repo/ and use locking
Diffstat (limited to 'fdroids.sh')
-rwxr-xr-x | fdroids.sh | 43 |
1 files changed, 31 insertions, 12 deletions
@@ -1,30 +1,49 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/bash |
2 | set -ex | 2 | set -e |
3 | quiet() { "$@" >/dev/null 2>&1; } | 3 | quiet() { "$@" >/dev/null 2>&1; } |
4 | quiet dpkg-query -W html-xml-utils || sudo apt install html-xml-utils | 4 | quiet dpkg-query -W html-xml-utils || sudo apt install html-xml-utils |
5 | stale() { [ $(( $(date +%s) - $(stat -c%Y "$1") )) -gt $(( 60*60*12 )) ]; } | 5 | stale() { [ $(( $(date +%s) - $(stat -c%Y "$1") )) -gt $(( 60*60*12 )) ]; } |
6 | wget_with_log() | ||
7 | { | ||
8 | touch "$1" | ||
9 | flock "$1" wget -a "$1" "${@:2}" | ||
10 | } | ||
6 | if [ -t 0 ] | 11 | if [ -t 0 ] |
7 | then | 12 | then |
8 | exec < fdroids.txt | 13 | exec < fdroids.txt |
9 | fi | 14 | fi |
10 | while read url | 15 | while read url |
11 | do | 16 | do |
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 |
30 | done | 49 | done |