Quantcast
Channel: rtrouton – Der Flounder
Viewing all articles
Browse latest Browse all 764

Downloading macOS IPSW files for use with Mac virtual machines on Apple Silicon Macs

$
0
0

A change between creating Mac virtual machines on Intel Macs and creating them on Apple Silicon Macs is that virtualization on Apple Silicon Macs often assumes that the virtual machine is built using a macOS restore image . These restore images are files with an .ipsw file extension and are commonly referred to as IPSW files.

Apple publishes the download links for macOS restore images via the following URL:

https://mesu.apple.com/assets/macos/com_apple_macOSIPSW/com_apple_macOSIPSW.xml

If you look at the XML file from the link above, it provides download links for the current version of macOS for the various Mac models which support running that version of macOS.

Among the various models listed is the model identifier for Mac virtual machines (VirtualMac2,1) created using Apple’s Virtualization framework. This means that we should be able to identify and download the appropriate IPSW file for use when building Mac virtual machines.

Screenshot 2022-11-16 at 7.33.48 PM

Using this information, I’ve written a script to download the appropriate IPSW file for building macOS virtual machines by checking the file linked above for the download URL associated with the VirtualMac2,1 Mac model. For more details, please see below the jump.

The script checks Apple’s IPSW feed to get the appropriate IPSW file for the current release of macOS used by the VirtualMac2,1 Mac model. If it finds a matching IPSW download URL, it will take the following actions:

  1. Download the IPSW file to a temp directory.
  2. If the download succeeds, a message is displayed notifying the user that the download has completed and where the IPSW file is stored.
  3. If the download fails, a message is displayed notifying the user that the download failed and the script exits with an error.

Usage:

./download_latest_macOS_ipsw_for_virtualization.sh

Screenshot 2022 11 16 at 10 39 10 PM

Screenshot 2022 11 16 at 10 42 14 PM

This script is available below and also from GitHub at the following location:

https://github.com/rtrouton/rtrouton_scripts/tree/main/rtrouton_scripts/download_latest_macOS_ipsw_for_virtualization


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 checks Apple's IPSW feed to get the appropriate IPSW file
# for the current release of macOS used by the VirtualMac2,1 virtualization
# Mac model.
clear
exitCode=0
Apple_macOS_IPSW_Download_Directory=$(mktemp -d)
Apple_macOS_IPSW_Feed="https://mesu.apple.com/assets/macos/com_apple_macOSIPSW/com_apple_macOSIPSW.xml"
Apple_macOS_IPSW_XML=$(/usr/bin/curl -s "$Apple_macOS_IPSW_Feed" | xmllint –format –)
Apple_macOS_IPSW_Download_URL=$(/usr/libexec/PlistBuddy -c 'print ":MobileDeviceSoftwareVersionsByVersion:1:MobileDeviceSoftwareVersions:VirtualMac2,1"' /dev/stdin <<< "$Apple_macOS_IPSW_XML" | awk '/FirmwareURL/ {print $3}')
Apple_macOS_IPSW_Filename=$(echo "$Apple_macOS_IPSW_Download_URL" | awk -F / '{print $NF}')
# Verify that the IPSW download URL contains a filename which ends in .ipsw
if [[ -n $(echo "$Apple_macOS_IPSW_Download_URL" | grep -o ".ipsw") ]]; then
# If the IPSW download URL contains a filename which ends in .ipsw,
# download the IPSW file and store it in a temp directory.
echo "Downloading $Apple_macOS_IPSW_Filename"
echo "From: $Apple_macOS_IPSW_Download_URL"
echo "To: $Apple_macOS_IPSW_Download_Directory/$Apple_macOS_IPSW_Filename"
echo ""
/usr/bin/curl -L "$Apple_macOS_IPSW_Download_URL" -o "$Apple_macOS_IPSW_Download_Directory"/"$Apple_macOS_IPSW_Filename" && download_success=1
# If the download succeeds, display a message notifying the user that the
# download has completed and where the IPSW file is stored.
#
# If the download fails, display a message notifying the user that the download failed
# and exit with an error.
if [[ -n "$download_success" ]] && [[ -f "$Apple_macOS_IPSW_Download_Directory"/"$Apple_macOS_IPSW_Filename" ]]; then
echo ""
echo "$Apple_macOS_IPSW_Filename has been downloaded to the following location:"
echo "$Apple_macOS_IPSW_Download_Directory/$Apple_macOS_IPSW_Filename"
else
echo "Download of $Apple_macOS_IPSW_Filename from $Apple_macOS_IPSW_Download_URL has failed. Exiting."
exitCode=1
fi
else
# If the IPSW download URL does not contain a filename which ends in .ipsw,
# display a message notifying the user that an IPSW file was not found and
# exit with an error.
echo "Unable to detect macOS IPSW file to download. Exiting."
exitCode=1
fi
exit "$exitCode"

Viewing all articles
Browse latest Browse all 764

Trending Articles