lol
at 24.05-pre 51 lines 2.0 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell -I nixpkgs=./. -i bash -p curl jq nix-prefetch common-updater-scripts nix coreutils 3# shellcheck shell=bash 4set -euo pipefail 5 6VERSION=$(curl -s https://api.github.com/repos/facebook/buck2/releases \ 7 | jq -r 'sort_by(.created_at) | reverse | 8 (map 9 (select ((.prerelease == true) and (.name != "latest"))) | 10 first 11 ) | .name') 12PRELUDE_HASH=$(curl -sLo - "https://github.com/facebook/buck2/releases/download/${VERSION}/prelude_hash") 13PRELUDE_DL_URL="https://github.com/facebook/buck2-prelude/archive/${PRELUDE_HASH}.tar.gz" 14 15echo "Latest buck2 prerelease: $VERSION" 16echo "Compatible buck2-prelude hash: $PRELUDE_HASH" 17 18ARCHS=( 19 "x86_64-linux:x86_64-unknown-linux-musl" 20 "x86_64-darwin:x86_64-apple-darwin" 21 "aarch64-linux:aarch64-unknown-linux-musl" 22 "aarch64-darwin:aarch64-apple-darwin" 23) 24 25NFILE=pkgs/development/tools/build-managers/buck2/default.nix 26HFILE=pkgs/development/tools/build-managers/buck2/hashes.json 27rm -f "$HFILE" && touch "$HFILE" 28 29PRELUDE_SHA256HASH="$(nix-prefetch-url --type sha256 "$PRELUDE_DL_URL")" 30PRELUDE_SRIHASH="$(nix hash to-sri --type sha256 "$PRELUDE_SHA256HASH")" 31 32printf "{ \"_comment\": \"@generated by pkgs/development/tools/build-managers/buck2/update.sh\"\n" >> "$HFILE" 33printf ", \"_prelude\": \"$PRELUDE_SRIHASH\"\n" >> "$HFILE" 34 35for arch in "${ARCHS[@]}"; do 36 IFS=: read -r arch_name arch_target <<< "$arch" 37 sha256hash="$(nix-prefetch-url --type sha256 "https://github.com/facebook/buck2/releases/download/${VERSION}/buck2-${arch_target}.zst")" 38 srihash="$(nix hash to-sri --type sha256 "$sha256hash")" 39 echo ", \"$arch_name\": \"$srihash\"" >> "$HFILE" 40done 41echo "}" >> "$HFILE" 42 43sed -i \ 44 '0,/version\s*=\s*".*";/s//version = "'"$VERSION"'";/' \ 45 "$NFILE" 46 47sed -i \ 48 '0,/prelude-hash\s*=\s*".*";/s//prelude-hash = "'"$PRELUDE_HASH"'";/' \ 49 "$NFILE" 50 51echo "Done; wrote $HFILE and updated version in $NFILE."