forked from mitchellh/zig-overlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update
executable file
·57 lines (49 loc) · 1.64 KB
/
update
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
#!/usr/bin/env nix-shell
#! nix-shell -p curl jq minisign -i sh
set -e
# The well known public key for Zig
PUBLIC_KEY="RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U"
# Grab the JSON and parse the version
rm -rf index.json index.json.minisig
curl -s 'https://ziglang.org/download/index.json' > index.json
VERSION=$(cat index.json | jq -r '.master.version')
echo "Parsing master version: ${VERSION}"
# Verify the signature of the JSON before we parse it
curl -s "https://ziglang.org/builds/zig-${VERSION}-index.json.minisig" > index.json.minisig
minisign -V -P ${PUBLIC_KEY} -x index.json.minisig -m index.json
# Build our new sources.json
cat index.json | jq '
["aarch64-linux", "x86_64-linux", "aarch64-macos", "x86_64-macos", "aarch64-windows", "x86_64-windows"] as $targets |
def todarwin(x): x | gsub("macos"; "darwin");
def toentry(vsn; x):
[(vsn as $version |
.value |
to_entries[] |
select(.key as $key | any($targets[]; . == $key)) | {
(todarwin(.key)): {
"url": .value.tarball,
"sha256": .value.shasum,
"version": $version,
}
}
)] | add | first(values, {});
reduce to_entries[] as $entry ({}; . * (
$entry | {
(.key): (
if (.key != "master") then
toentry(.key; .value)
else {
"latest": toentry(.value.version; .value),
(.value.date): toentry(.value.version; .value),
} end
)
}
))
' > sources.new.json
# For debugging
# cat sources.new.json
# exit
# Copy the old file since jq can't modify in-place. This is also a backup.
cp sources.json sources.old.json
# Recursive merge
jq -s '.[0] * .[1]' sources.old.json sources.new.json > sources.json