Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1#!/usr/bin/env nix-shell 2#!nix-shell -i bash -p curl jq coreutils common-updater-scripts 3set -eu -o pipefail 4 5currentVersion=$(nix-instantiate --eval -E "with import ./. {}; code-cursor.version or (lib.getVersion code-cursor)" | tr -d '"') 6 7declare -A platforms=( [x86_64-linux]='linux-x64' [aarch64-linux]='linux-arm64' [x86_64-darwin]='darwin-x64' [aarch64-darwin]='darwin-arm64' ) 8declare -A updates=( ) 9first_version="" 10 11for platform in ${!platforms[@]}; do 12 api_platform=${platforms[$platform]} 13 result=$(curl -s "https://api2.cursor.sh/updates/api/download/stable/$api_platform/cursor") 14 version=$(echo $result | jq -r '.version') 15 if [[ "$version" == "$currentVersion" ]]; then 16 exit 0 17 fi 18 if [[ -z "$first_version" ]]; then 19 first_version=$version 20 first_platform=$platform 21 elif [[ "$version" != "$first_version" ]]; then 22 >&2 echo "Multiple versions found: $first_version ($first_platform) and $version ($platform)" 23 exit 1 24 fi 25 url=$(echo $result | jq -r '.downloadUrl') 26 # Exits with code 22 if not downloadable 27 curl --output /dev/null --silent --head --fail "$url" 28 updates+=( [$platform]="$result" ) 29done 30 31# Install updates 32for platform in ${!updates[@]}; do 33 result=${updates[$platform]} 34 version=$(echo $result | jq -r '.version') 35 url=$(echo $result | jq -r '.downloadUrl') 36 source=$(nix-prefetch-url "$url" --name "cursor-$version") 37 hash=$(nix-hash --to-sri --type sha256 "$source") 38 update-source-version code-cursor $version $hash "$url" --system=$platform --ignore-same-version --source-key="sources.$platform" 39done