1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p coreutils curl file gzip jq xcbuild yq
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
15 trap 'rm -f -- "$scratch"' EXIT
17 if [[ "$(file "$catalog")" =~
gzip ]]; then
18 gzcat
"$catalog" > "$scratch"
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#*|}
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"
38 group_by(.version | split(".")[0])
39 | map(max_by(.version))
41 | "Package URL: \(.url)\n Xcode Ver: \(.version) (\(.long_version))\n"' "$scratch"