anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / applications / blockchains / solana-validator / update.sh
blobcb8aa43ac61eee5a45434e64a81d767d5d62e329
1 #!/usr/bin/env nix-shell
2 #! nix-shell -i oil -p jq moreutils nix-prefetch-github gnused
4 # TODO set to `verbose` or `extdebug` once implemented in oil
5 shopt --set xtrace
6 # we need failures inside of command subs to get the correct cargoHash
7 shopt --unset inherit_errexit
9 const directory = $(dirname $0 | xargs realpath)
10 const owner = "solana-labs"
11 const repo = "solana"
12 const latest_rev = $(curl -q https://api.github.com/repos/${owner}/${repo}/releases/latest | \
13 jq -r '.tag_name')
14 const latest_version = $(echo ${latest_rev#v})
15 const current_version = $(jq -r '.version' $directory/pin.json)
16 if ("$latest_version" === "$current_version") {
17 echo "solana is already up-to-date"
18 return 0
19 } else {
20 const tarball_meta = $(nix-prefetch-github $owner $repo --rev "$latest_rev")
21 const tarball_hash = $(echo $tarball_meta | jq -r '.hash')
23 jq ".version = \"$latest_version\" | \
24 .\"hash\" = \"$tarball_hash\" | \
25 .\"cargoHash\" = \"\"" $directory/pin.json | sponge $directory/pin.json
27 const new_cargo_hash = $(nix-build -A solana-validator 2>&1 | \
28 tail -n 2 | \
29 head -n 1 | \
30 sed 's/\s*got:\s*//')
32 jq ".cargoHash = \"$new_cargo_hash\"" $directory/pin.json | sponge $directory/pin.json