Created
August 9, 2021 19:51
-
-
Save jief666/4b998d3ee772f6bbb1212b4095ddbed4 to your computer and use it in GitHub Desktop.
Script to build an iso file from the macOS installer.
This file contains hidden or 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 | |
set -e # exit on error | |
#Everything in put in a function so "return" will work even if this script is not sourced | |
function do_it() | |
{ | |
if [ $(ls -1dq "Install macOS "*.app | wc -l) -gt 1 ] | |
then | |
echo More than one Install macOS ...app in this folder | |
return 1 | |
fi | |
if [ $(ls -1dq "Install macOS "*.app | wc -l) -eq 0 ] | |
then | |
if [ $(ls -1dq "Install OS X "*.app | wc -l) -gt 1 ] | |
then | |
echo More than one Install OS X ...app in this folder | |
return 1 | |
else | |
if [ $(ls -1dq "Install OS X "*.app | wc -l) -eq 0 ] | |
then | |
echo No OS X or macOS installer found in this folder | |
return 1 | |
else | |
install_app=$(ls -1dq "Install OS X "*.app) | |
fi | |
fi | |
else | |
install_app=$(ls -1dq "Install macOS "*.app) | |
fi | |
dmg_name=${install_app%".app"} | |
echo install_app=$install_app | |
echo dmg_name="$dmg_name" | |
if ! [ -f "$dmg_name".dmg ] | |
then | |
# Create a Disk Image | |
size=$(du -gd0 "$install_app"/ | cut -f1) | |
((size=size+1)) | |
echo '-------> Create dmg of size ' ${size} | |
hdiutil create -o "$dmg_name" -size ${size}G -volname "$dmg_name" -layout SPUD -fs HFS+J | |
fi | |
# Mount this Image to macOS | |
hdiutil attach "$dmg_name".dmg -noverify | |
# Use Createinstallmedia Tool to create a Installer Image | |
sudo ./"$install_app"/Contents/Resources/createinstallmedia --volume "$(sparsebundle_mountpoint "$dmg_name".dmg)" --nointeraction | |
# Unmount Volumes | |
if [ -f "$install_app/Contents/SharedSupport/SharedSupport.dmg" ]; then | |
mountpoint="$(sparsebundle_mountpoint "$install_app/Contents/SharedSupport/SharedSupport.dmg")" | |
! [ -z "$mountpoint" ] && hdiutil eject "$mountpoint" | |
fi | |
if [ -f "$dmg_name".dmg ] | |
then | |
dmg_mountpoint="$(sparsebundle_mountpoint "$dmg_name".dmg)" | |
if ! [ -z "$dmg_mountpoint" ] | |
then | |
if [ -f "$dmg_mountpoint"/"$install_app"/Contents/SharedSupport/SharedSupport.dmg ]; then | |
mountpoint="$(sparsebundle_mountpoint "$dmg_mountpoint"/"$install_app"/Contents/SharedSupport/SharedSupport.dmg)" | |
! [ -z "$mountpoint" ] && hdiutil eject "$mountpoint" | |
fi | |
hdiutil eject "$dmg_mountpoint" | |
fi | |
fi | |
# Convert the bigsur.dmg to a bigsur.iso for Virtual Machine | |
hdiutil convert "$dmg_name".dmg -format UDTO -o "$dmg_name".cdr | |
# Move and Rename bigsur Image to Desktop | |
mv "$dmg_name".cdr "$dmg_name".iso | |
rm "$dmg_name".dmg | |
} | |
do_it "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works from Mavericks.
Place this script in a folder where there is a mac OS installer (Install macOS... .app or Install OS X... .app) and run. You'll find an iso with the same name as the installer app.
The iso can be used for install in virtual machines.