2022-08-22 15:56:44 -07:00
|
|
|
#!/usr/bin/env nix-shell
|
2023-01-19 15:43:00 -08:00
|
|
|
#! nix-shell -p curl jq minisign -i sh
|
2022-08-22 17:54:16 -07:00
|
|
|
set -e
|
2022-08-22 15:56:44 -07:00
|
|
|
|
2023-01-19 15:43:00 -08:00
|
|
|
# The well known public key for Zig
|
|
|
|
PUBLIC_KEY="RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U"
|
|
|
|
|
|
|
|
# Grab the JSON and parse the version
|
2023-01-19 15:44:55 -08:00
|
|
|
rm -rf index.json index.json.minisig
|
2023-01-19 15:43:00 -08:00
|
|
|
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
|
|
|
|
|
2022-08-22 17:38:53 -07:00
|
|
|
# Build our new sources.json
|
2023-01-19 15:43:00 -08:00
|
|
|
cat index.json | jq '
|
2022-10-31 21:20:31 -07:00
|
|
|
["aarch64-linux", "x86_64-linux", "aarch64-macos", "x86_64-macos", "aarch64-windows", "x86_64-windows"] as $targets |
|
2022-08-22 17:38:53 -07:00
|
|
|
def todarwin(x): x | gsub("macos"; "darwin");
|
2023-01-19 15:34:25 -08:00
|
|
|
def toentry(vsn; x):
|
2022-08-22 17:38:53 -07:00
|
|
|
[(vsn as $version |
|
|
|
|
.value |
|
|
|
|
to_entries[] |
|
|
|
|
select(.key as $key | any($targets[]; . == $key)) | {
|
2023-01-19 15:34:25 -08:00
|
|
|
(todarwin(.key)): {
|
2022-11-01 04:35:45 +00:00
|
|
|
"url": .value.tarball,
|
2023-01-19 15:34:25 -08:00
|
|
|
"sha256": .value.shasum,
|
2022-11-01 04:35:45 +00:00
|
|
|
"version": $version,
|
2023-01-19 15:34:25 -08:00
|
|
|
}
|
2022-08-22 17:38:53 -07:00
|
|
|
}
|
2022-11-01 04:35:45 +00:00
|
|
|
)] | add | first(values, {});
|
2022-08-22 15:56:44 -07:00
|
|
|
|
2022-11-01 04:35:45 +00:00
|
|
|
reduce to_entries[] as $entry ({}; . * (
|
|
|
|
$entry | {
|
2022-08-22 17:38:53 -07:00
|
|
|
(.key): (
|
2022-11-01 04:35:45 +00:00
|
|
|
if (.key != "master") then
|
2023-01-19 15:34:25 -08:00
|
|
|
toentry(.key; .value)
|
2022-11-01 04:35:45 +00:00
|
|
|
else {
|
2023-01-19 15:34:25 -08:00
|
|
|
"latest": toentry(.value.version; .value),
|
|
|
|
(.value.date): toentry(.value.version; .value),
|
2022-11-01 04:35:45 +00:00
|
|
|
} end
|
2022-08-22 17:38:53 -07:00
|
|
|
)
|
2022-11-01 04:35:45 +00:00
|
|
|
}
|
|
|
|
))
|
2022-08-22 17:38:53 -07:00
|
|
|
' > sources.new.json
|
2022-08-22 15:56:44 -07:00
|
|
|
|
2022-08-22 17:38:53 -07:00
|
|
|
# For debugging
|
|
|
|
# cat sources.new.json
|
|
|
|
# exit
|
2022-08-22 15:56:44 -07:00
|
|
|
|
2022-08-22 17:38:53 -07:00
|
|
|
# Copy the old file since jq can't modify in-place. This is also a backup.
|
|
|
|
cp sources.json sources.old.json
|
2022-08-22 15:56:44 -07:00
|
|
|
|
2022-08-22 17:38:53 -07:00
|
|
|
# Recursive merge
|
2022-11-01 04:35:45 +00:00
|
|
|
jq -s '.[0] * .[1]' sources.old.json sources.new.json > sources.json
|