summaryrefslogtreecommitdiff
path: root/update-repo
diff options
context:
space:
mode:
Diffstat (limited to 'update-repo')
-rwxr-xr-xupdate-repo106
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
2set -e
3shopt -s lastpipe
4
5baseurl=https://f-droid.org
6stale_hours=12
7
8quiet()
9{
10 "$@" >/dev/null 2>&1
11}
12
13stale()
14{
15 [ ! -e "$1" ] ||
16 [ $(( $(date +%s) - $(stat -c%Y "$1") )) -gt $(( 60*60*stale_hours )) ];
17}
18
19wget_with_log()
20{
21 set -- wget-log.txt "$@"
22 [ -e "$1" ] || touch "$1"
23 flock "$1" wget -a "$1" "${@:2}"
24}
25
26list_existing()
27{
28 find repo/ -maxdepth 1 -type d |
29 xargs bash -c 'printf "%s\n" "${@#repo/}"' bash
30}
31
32parse_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
49show_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
60fetch_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
82quiet dpkg-query -W html-xml-utils || sudo apt install html-xml-utils
83
84if [ -t 0 ]
85then
86 exec < <(list_existing)
87fi
88while read
89do
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
106done