ci: Update pinned Nixpkgs (#376039)
[NixPkgs.git] / pkgs / by-name / ap / apple-sdk / scripts / get-sdks-from-catalog.sh
blob1293fab11cc92a47ca8e19468a0349f43b6466e0
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p coreutils curl file gzip jq xcbuild yq
4 set -eu -o pipefail
6 catalog=${1-}
8 if [ -z "$catalog" ]; then
9 echo "usage: get-sdks-from-catalog.sh <catalog>"
10 echo " <catalog> Apple software update catalog (may be gzipped)" >&2
11 exit 1
14 scratch=$(mktemp)
15 trap 'rm -f -- "$scratch"' EXIT
17 if [[ "$(file "$catalog")" =~ gzip ]]; then
18 gzcat "$catalog" > "$scratch"
19 else
20 cp --reflink=auto "$catalog" "$scratch"
23 # Grab all SDK packages from the catalog
24 filter='.Products[].Packages[] | select(.URL | test(".*CLTools_macOSNMOS_SDK.pkg")) | "\(.URL)|\(.MetadataURL)"'
26 declare -A package_list
27 for package in $(plutil -convert json -o - "$scratch" | jq -r "$filter"); do
28 package_list[${package%%|*}]=${package#*|}
29 done
31 truncate --size 0 "$scratch"
32 for pkg in "${!package_list[@]}"; do
33 ver=$(curl --silent "${package_list[$pkg]}" | xq -r '."pkg-info"."@version"')
34 echo "{\"url\": \"$pkg\", \"version\": \"$(cut -d. -f1-3 <<< "$ver")\", \"long_version\": \"$ver\"}" >> "$scratch"
35 done
37 jq -r --slurp '
38 group_by(.version | split(".")[0])
39 | map(max_by(.version))
40 | sort_by(.version)[]
41 | "Package URL: \(.url)\n Xcode Ver: \(.version) (\(.long_version))\n"' "$scratch"