dput-ng: fix eval (#364540)
[NixPkgs.git] / pkgs / development / tools / infisical / update.sh
blobd0ad2342f415dedf2b868c5e76674761295a6687
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
4 set -euo pipefail
6 RELEASE_NAME=$(curl -s https://api.github.com/repos/infisical/infisical/releases \
7 | jq -r 'sort_by(.created_at) | reverse |
8 (map
9 (select ((.prerelease == false) and (.draft == false) and (.name | contains("infisical-cli")))) |
10 first
11 ) | .name')
12 VERSION=$(echo "$RELEASE_NAME" | sed -E 's/^infisical-cli\/v//')
14 echo "Latest infisical release: $VERSION"
16 ARCHS=(
17 "x86_64-linux:linux_amd64"
18 "x86_64-darwin:darwin_amd64"
19 "aarch64-linux:linux_arm64"
20 "aarch64-darwin:darwin_arm64"
23 NFILE=pkgs/development/tools/infisical/default.nix
24 HFILE=pkgs/development/tools/infisical/hashes.json
25 rm -f "$HFILE" && touch "$HFILE"
27 printf "{ \"_comment\": \"@generated by pkgs/development/tools/infisical/update.sh\"\n" >> "$HFILE"
29 for arch in "${ARCHS[@]}"; do
30 IFS=: read -r arch_name arch_target <<< "$arch"
31 sha256hash="$(nix-prefetch-url --type sha256 "https://github.com/infisical/infisical/releases/download/${RELEASE_NAME}/infisical_${VERSION}_${arch_target}.tar.gz")"
32 srihash="$(nix hash to-sri --type sha256 "$sha256hash")"
33 echo ", \"$arch_name\": \"$srihash\"" >> "$HFILE"
34 done
35 echo "}" >> "$HFILE"
37 sed -i \
38 '0,/version\s*=\s*".*";/s//version = "'"$VERSION"'";/' \
39 "$NFILE"
41 echo "Done; wrote $HFILE and updated version in $NFILE."