Skip to content

Instantly share code, notes, and snippets.

@paulgalow
Last active April 18, 2022 00:38
Show Gist options
  • Save paulgalow/71d609da0322f09c67531d5f5773ffc1 to your computer and use it in GitHub Desktop.
Save paulgalow/71d609da0322f09c67531d5f5773ffc1 to your computer and use it in GitHub Desktop.
Extract macOS release and build versions from a macOS Big Sur installer. Pass it a path to an InstallAssistant app, like so: ./get-macos-build.sh "/Applications/Install macOS Big Sur.app/"
#!/bin/sh
readonly installAssistant="$1"
# Display error messages and exit script
error() {
echo "[ERROR] $*"
exit 1
}
# Check operating system
isOs() {
if [ ! "$(/usr/bin/uname)" = "$1" ]; then return 1; fi
}
# Check if parameter $1 has been passed in to script
checkParams() {
if [ ! "$installAssistant" ] ; then return 1; fi
}
# Attach SharedSupport.dmg
attachDmg() {
dmgPath="${installAssistant}/Contents/SharedSupport/SharedSupport.dmg"
if [ ! -f "$dmgPath" ]; then
error "Could not find '$(basename "$dmgPath")'. Is this a macOS Big Sur InstallAssistant app?"
fi
/usr/bin/hdiutil attach \
-nobrowse \
-noverify \
-quiet \
"$dmgPath"
}
# Extract "OSVersion" and "Build" keys from com_apple_MobileAsset_MacSoftwareUpdate.xml
parsePlist() {
path="/Volumes/Shared Support/com_apple_MobileAsset_MacSoftwareUpdate/com_apple_MobileAsset_MacSoftwareUpdate.xml"
if [ ! -f "$path" ]; then
error "Could not parse 'com_apple_MobileAsset_MacSoftwareUpdate.xml'"
fi
osVersion=$(/usr/libexec/PlistBuddy \
-c "Print :Assets:0:OSVersion" \
"$path")
buildVersion=$(/usr/libexec/PlistBuddy \
-c "Print :Assets:0:Build" \
"$path")
}
cleanUp() {
# Detach SharedSupport volume
volume="/Volumes/Shared Support/"
/usr/bin/hdiutil detach \
-quiet \
"$volume"
}
trap cleanUp INT TERM EXIT
isOs Darwin || error "It seems you are not running macOS. Exiting …"
checkParams || error "Please provide path to InstallAssistant app, e.g. $0 \"/Applications/Install macOS Big Sur.app/\""
attachDmg
parsePlist
echo "macOS version:" "$osVersion"
echo "Build version:" "$buildVersion"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment