Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1#! /usr/bin/env nix-shell 2#! nix-shell -i bash -p bash curl jq 3 4set -euo pipefail 5 6LATEST_VERSION=$(curl -L -s https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt) 7SUPPORTED_OPERATING_SYSTEMS=("linux" "darwin") 8SUPPORTED_ARCHITECTURES=("x86_64" "aarch64") 9SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 10VERSIONS_FILE="${SCRIPT_DIR}/sysdig-cli-scanner.versions.nix" 11 12main() { 13 echo "{" > "$VERSIONS_FILE" 14 echo " version = \"${LATEST_VERSION}\";" >> "$VERSIONS_FILE" 15 for os in "${SUPPORTED_OPERATING_SYSTEMS[@]}"; do 16 for arch in "${SUPPORTED_ARCHITECTURES[@]}"; do 17 formatted_arch=$(formatArchitectureForURL "$arch") 18 download_url="https://download.sysdig.com/scanning/bin/sysdig-cli-scanner/${LATEST_VERSION}/${os}/${formatted_arch}/sysdig-cli-scanner" 19 file_hash=$(fetchFileHash "$download_url") 20 appendToVersionsFile "$VERSIONS_FILE" "$arch" "$os" "$download_url" "$file_hash" 21 done 22 done 23 echo "}" >> "$VERSIONS_FILE" 24} 25 26formatArchitectureForURL() { 27 local architecture="$1" 28 case "$architecture" in 29 x86_64) echo "amd64" ;; 30 aarch64) echo "arm64" ;; 31 *) echo "Unsupported architecture: $architecture" >&2; return 1 ;; 32 esac 33} 34 35fetchFileHash() { 36 local url="$1" 37 nix store prefetch-file --json "$url" | jq -r .hash 38} 39 40appendToVersionsFile() { 41 local file="$1" 42 local architecture="$2" 43 local operating_system="$3" 44 local url="$4" 45 local hash="$5" 46 cat >> "$file" << EOF 47 48 ${architecture}-${operating_system} = { 49 url = "$url"; 50 hash = "$hash"; 51 }; 52EOF 53} 54 55main 56