-
Notifications
You must be signed in to change notification settings - Fork 11
/
bump-live-catalog.sh
executable file
·32 lines (24 loc) · 930 Bytes
/
bump-live-catalog.sh
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
#!/usr/bin/env bash
NAME=live-catalog
URL_BASE=https://pkgs.racket-lang.org/pkgs-all
set -eou pipefail
cd "${BASH_SOURCE[0]%/*}"
# Avoid an error when evaluating the version:
# `path '/nix/store/wpwijvjhwjh6pg6n1r8khl1alzma2vm8-source.drv' is not valid`
nix-build --no-out-link nixpkgs > /dev/null
# Ugh eval to remove the quotes around the string
version=$(eval echo $(nix-instantiate --eval -E 'with import ./pkgs {}; racket-full.version'))
save_url=https://web.archive.org/save/$URL_BASE?version=$version
save_headers=$(curl -sfiI "$save_url")
snapshot_url=$(while read -r header value; do
if [[ $header == location: ]]; then echo "${value%$'\r'}"; exit 0; fi;
done <<< "$save_headers"; exit 1)
sha256=$(nix-prefetch-url --name $NAME --type sha256 "$snapshot_url")
cat > live-catalog.json.new <<EOF
{
"name": "$NAME",
"url": "$snapshot_url",
"sha256": "$sha256"
}
EOF
mv live-catalog.json.new live-catalog.json