Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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