As of macOS Catalina and Big Sur, Apple added some useful functionality to the softwareupdate tool which allows you to list the macOS installers (starting on macOS Big Sur) available to a particular Mac and then to download them (starting on macOS Catalina.)
I’ve used both functions frequently when I needed to identify and download new macOS installers, so I decided to write a script which makes the task easier. For more details, please see below the jump.
The script uses the softwareupdate tool to list all macOS installers that are available to the Mac you’re running the script on, along with the version number information you would need to provide to the softwareupdate tool in order to download that macOS version’s installer.
If you enter version information when prompted, the script will download the specified macOS installer and install the corresponding macOS installer application into /Applications.
This script is available below and also from GitHub at the following location:
https://github.com/rtrouton/rtrouton_scripts/tree/main/rtrouton_scripts/download_macos_installers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script uses the softwareupdate command to display available macOS installers | |
# for a particular Mac and then offers the option to download them. | |
available_os_installers=$(mktemp) | |
# Set exit status | |
error=0 | |
#Check for available macOS installers | |
/usr/sbin/softwareupdate –list-full-installers > "$available_os_installers" | |
clear | |
echo "The following macOS installers are available for this Mac:" | |
echo "" | |
cat "$available_os_installers" | tail -n +3 | awk -F ': |, |KiB' '($1 == "* Title") { print $2" "$4" Build "$9 ": "(int(($6 / 1000 / 1000) * 10 + 0.5) / 10) " GB" }' | |
echo "" | |
echo "Version numbers:" | |
grep -oE '\d+\.(\d|\.)*\d' "$available_os_installers" | |
echo "" | |
read -p "Please enter the version number of the macOS installer you wish to download: " macos_version | |
# Verify that data entered contains only numbers and periods by extracting all the numbers and | |
# periods and seeing if there's anything left over. If there is, not a valid version number. | |
macos_version_check=$(echo "$macos_version" | sed 's/[0-9]//g' | tr -d '.') | |
# If the version check returns no data, a version number containing only numbers and periods was entered. | |
if [[ -z "$macos_version_check" ]]; then | |
echo "Downloading installer…" | |
/usr/sbin/softwareupdate –fetch-full-installer –full-installer-version ${macos_version} | |
else | |
echo "$macos_version is not a valid version number. Exiting…" | |
error=1 | |
fi | |
exit $error |
Thanks to the folks in the #bash channel in the Mac Admins Slack for helping improve various parts of this script.