Repository navigation
Expand file tree
/
Copy pathupdate-mirror.sh
More file actions
executable file
·65 lines (59 loc) · 1.71 KB
/
Copy pathupdate-mirror.sh
File metadata and controls
executable file
·65 lines (59 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
set -euo pipefail
base_url="https://www.lua.org/ftp"
listing="$(curl -fsSL "$base_url/")"
targets="$(
printf '%s\n' "$listing" \
| awk '
/CLASS="name"/ {
name = ""
if (match($0, /lua-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz/)) {
name = substr($0, RSTART, RLENGTH)
}
next
}
/CLASS="sum"/ && name != "" {
if (match($0, /[0-9a-f]{64}/)) {
print name, substr($0, RSTART, RLENGTH)
}
name = ""
}
' \
| sort -k1,1V \
| awk '
{
version = $1
sub(/^lua-/, "", version)
sub(/\.tar\.gz$/, "", version)
split(version, parts, ".")
if (parts[1] + 0 != 5 || parts[2] + 0 < 1) {
next
}
latest[parts[1] "." parts[2]] = $0
}
END {
for (minor in latest) {
print latest[minor]
}
}
'
)"
if [[ -z "$targets" ]]; then
echo "could not parse the Lua source listing" >&2
exit 1
fi
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT
while read -r name sum; do
if [[ -f "$name" ]] && [[ "$(sha256sum "$name" | cut -d' ' -f1)" == "$sum" ]]; then
continue
fi
curl -fsSL "$base_url/$name" -o "$tmp"
actual="$(sha256sum "$tmp" | cut -d' ' -f1)"
if [[ "$actual" != "$sum" ]]; then
printf 'checksum mismatch for %s: expected %s, got %s\n' "$name" "$sum" "$actual" >&2
exit 1
fi
mv "$tmp" "$name"
printf 'added %s\n' "$name"
done <<< "$targets"