Skip to content

Instantly share code, notes, and snippets.

@knalli
Last active December 16, 2024 23:49
Show Gist options
  • Save knalli/5e48e5788feb7528c5d0e7945b073208 to your computer and use it in GitHub Desktop.
Save knalli/5e48e5788feb7528c5d0e7945b073208 to your computer and use it in GitHub Desktop.
Create ISO of "Install macOS Sequoia"
#!/bin/bash
# based on https://osxdaily.com/2020/07/20/how-convert-macos-installer-iso/, but compressed to the details
MACOSNAME="Sequoia"
IMAGESIZE=17000m
set -e
TMPDIR=""
trap cleanup EXIT
function main() {
echo "Ensure installer for '$MACOSNAME' is already downloaded, at /Applications/Install macOS ${MACOSNAME}.app"
read -p "Press enter to continue"
TMPDIR=$(mktemp -d)
echo "Creating empty destination image file..."
hdiutil create "${TMPDIR}/${MACOSNAME}" -size "${IMAGESIZE}" -volname "${MACOSNAME}" -layout SPUD -fs HFS+J
echo "Mounting volume..."
hdiutil attach "${TMPDIR}/${MACOSNAME}.dmg" -noverify -mountpoint "/Volumes/${MACOSNAME}"
echo "Burning media to volume..."
pushd "/Applications/Install macOS ${MACOSNAME}.app/Contents/Resources"
sudo ./createinstallmedia --volume "/Volumes/${MACOSNAME}" --nointeraction
popd
echo "Detaching volume again..."
hdiutil detach "/Volumes/Install macOS ${MACOSNAME}"
echo "Converting volume to ISO file..."
hdiutil convert "${TMPDIR}/${MACOSNAME}.dmg" -format UDTO -o "${TMPDIR}/${MACOSNAME}.cdr"
mv "${TMPDIR}/${MACOSNAME}.cdr" ~/Downloads/"macOS_${MACOSNAME}.iso"
echo "File is available at ~/Downloads/macOS_${MACOSNAME}.iso"
echo "You may want to delete the installer again: /Applications/Install macOS ${MACOSNAME}.app"
}
function cleanup() {
echo "Cleanup any errored volumes..."
hdiutil detach "/Volumes/${MACOSNAME}" || true
hdiutil detach "/Volumes/Install macOS ${MACOSNAME}" || true
echo "Cleanup up temp files..."
if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
rm -rf "$TMPDIR"
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment