ripasso-cursive: cosmetic changes (#361736)
[NixPkgs.git] / pkgs / by-name / sy / sysdig-cli-scanner / update.sh
blobb5b3191e21ff5fb41d601b8d36aeca72671d415d
1 #! /usr/bin/env nix-shell
2 #! nix-shell -i bash -p bash curl jq
4 set -euo pipefail
6 LATEST_VERSION=$(curl -L -s https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt)
7 SUPPORTED_OPERATING_SYSTEMS=("linux" "darwin")
8 SUPPORTED_ARCHITECTURES=("x86_64" "aarch64")
9 SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
10 VERSIONS_FILE="${SCRIPT_DIR}/sysdig-cli-scanner.versions.nix"
12 main() {
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"
26 formatArchitectureForURL() {
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
35 fetchFileHash() {
36 local url="$1"
37 nix store prefetch-file --json "$url" | jq -r .hash
40 appendToVersionsFile() {
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
48 ${architecture}-${operating_system} = {
49 url = "$url";
50 hash = "$hash";
52 EOF
55 main