diff options
author | Gordon GECOS <u@adam> | 2024-07-29 16:59:35 -0400 |
---|---|---|
committer | Gordon GECOS <u@adam> | 2024-07-29 16:59:35 -0400 |
commit | 35b233aa6473b83e1385f247a79bb71b5ff08ef0 (patch) | |
tree | 39c53c0789f96b1a3eadc2311020a640c5c2d8ac /update-repo | |
parent | bad38013c1c52ec3238c4dfcf87d2ff1ddfc2eb1 (diff) |
search
Diffstat (limited to 'update-repo')
-rwxr-xr-x | update-repo | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/update-repo b/update-repo new file mode 100755 index 0000000..aa2804b --- /dev/null +++ b/update-repo | |||
@@ -0,0 +1,106 @@ | |||
1 | #!/bin/bash | ||
2 | set -e | ||
3 | shopt -s lastpipe | ||
4 | |||
5 | baseurl=https://f-droid.org | ||
6 | stale_hours=12 | ||
7 | |||
8 | quiet() | ||
9 | { | ||
10 | "$@" >/dev/null 2>&1 | ||
11 | } | ||
12 | |||
13 | stale() | ||
14 | { | ||
15 | [ ! -e "$1" ] || | ||
16 | [ $(( $(date +%s) - $(stat -c%Y "$1") )) -gt $(( 60*60*stale_hours )) ]; | ||
17 | } | ||
18 | |||
19 | wget_with_log() | ||
20 | { | ||
21 | set -- wget-log.txt "$@" | ||
22 | [ -e "$1" ] || touch "$1" | ||
23 | flock "$1" wget -a "$1" "${@:2}" | ||
24 | } | ||
25 | |||
26 | list_existing() | ||
27 | { | ||
28 | find repo/ -maxdepth 1 -type d | | ||
29 | xargs bash -c 'printf "%s\n" "${@#repo/}"' bash | ||
30 | } | ||
31 | |||
32 | parse_pkgname() | ||
33 | { | ||
34 | # Set package on succ | ||
35 | set -- "${1%/}" | ||
36 | case "$1" in | ||
37 | '' | $baseurl/??/packages/*/* | $baseurl/packages/*/* ) | ||
38 | false ;; | ||
39 | $baseurl/??/packages/* | $baseurl/packages/* ) | ||
40 | echo "${1#*/packages/}" ;; | ||
41 | */* ) | ||
42 | false ;; | ||
43 | * ) | ||
44 | echo "$1" | ||
45 | ;; | ||
46 | esac | ||
47 | } | ||
48 | |||
49 | show_pkg() | ||
50 | { | ||
51 | for x in name summary description | ||
52 | do | ||
53 | hxextract .package-$x "$1" | | ||
54 | w3m -T text/html | | ||
55 | sed -e '/^$/d' | ||
56 | echo | ||
57 | done | ||
58 | } | ||
59 | |||
60 | fetch_pkg() | ||
61 | { | ||
62 | local pkg="$1" | ||
63 | url=$baseurl/en/packages/$pkg | ||
64 | if wget_with_log -O index.html.part "$url" | ||
65 | then | ||
66 | mv -T index.html.part index.html | ||
67 | else | ||
68 | echo "failed to fetch url ${url@Q}" >&2 | ||
69 | return 1 | ||
70 | fi | ||
71 | |||
72 | hxwls index.html | | ||
73 | egrep "^$baseurl/repo/${pkg}_[0-9]+\.apk\$" | | ||
74 | sort -n | | ||
75 | tail -n1 | | ||
76 | read link && | ||
77 | [ "$link" ] || return | ||
78 | show_pkg index.html >&2 | ||
79 | wget_with_log -c "$link" "$link.asc" | ||
80 | } | ||
81 | |||
82 | quiet dpkg-query -W html-xml-utils || sudo apt install html-xml-utils | ||
83 | |||
84 | if [ -t 0 ] | ||
85 | then | ||
86 | exec < <(list_existing) | ||
87 | fi | ||
88 | while read | ||
89 | do | ||
90 | [ "$REPLY" ] || continue | ||
91 | if ! parse_pkgname "$REPLY" | read pkg || ! [ "$pkg" ] | ||
92 | then | ||
93 | echo "Skipping invalid URL: ${REPLY@Q}" >&2 | ||
94 | fi | ||
95 | pkgdir=repo/$pkg | ||
96 | mkdir -p "$pkgdir" | ||
97 | stale "$pkgdir"/stamp || continue | ||
98 | stale "$pkgdir"/failstamp || continue | ||
99 | echo "$pkg" >&2 | ||
100 | if ( cd "$pkgdir" && fetch_pkg "$pkg" ) | ||
101 | then | ||
102 | touch "$pkgdir"/stamp | ||
103 | else | ||
104 | touch "$pkgdir"/failstamp | ||
105 | fi | ||
106 | done | ||