Created
June 22, 2017 04:51
-
-
Save grahamperrin/d6b9e979d46708b41cdd25d79552a4cb to your computer and use it in GitHub Desktop.
https://github.com/geerlingguy/macos-virtualbox-vm/issues/28 work in progress
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 | |
# | |
# Create a bootable ISO image from Apple's installer application for | |
# OS X Yosemite (10.10.x), OS X El Capitan (10.11.x), | |
# macOS Sierra (10.12.x) or pre-release macOS High Sierra (10.13). | |
# | |
# Notes, including credits: | |
# https://github.com/geerlingguy/macos-virtualbox-vm/blob/master/README.md | |
# | |
# Updating for 10.13: | |
# https://github.com/geerlingguy/macos-virtualbox-vm/issues/28 | |
# | |
# | |
# createISO | |
# | |
# This function creates the ISO image for the user. | |
# Inputs: $1 = The name of the installer - located in your Applications folder or in your local folder/PATH. | |
# $2 = The name that you want to give to the ISO file. | |
# | |
function createISO() | |
{ | |
if [ $# -eq 2 ] ; then | |
local installerAppName=${1} | |
local isoName=${2} | |
local error=0 | |
# echo Debug: installerAppName = ${installerAppName} , isoName = ${isoName} | |
# ======================================= | |
# Producing an ISO from Apple's installer | |
# ======================================= | |
echo | |
echo Mount the electronic software distribution (ESD) at /Volumes/install_app | |
echo -------------------------------------------------------------------------------- | |
if [ -e "${installerAppName}" ] ; then | |
echo $ hdiutil attach "${installerAppName}"/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app | |
hdiutil attach "${installerAppName}"/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app | |
error=$? | |
elif [ -e /Applications/"${installerAppName}" ] ; then | |
echo $ hdiutil attach /Applications/"${installerAppName}"/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app | |
hdiutil attach /Applications/"${installerAppName}"/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app | |
error=$? | |
else | |
echo "A compatible installer was not found." | |
error=1 | |
fi | |
if [ ${error} -ne 0 ] ; then | |
echo "Failed to mount the InstallESD.dmg from within the installer at ${installerAppName}. Exiting. (${error})" | |
return ${error} | |
fi | |
echo | |
echo Create ${isoName} – an empty disk image with an Apple partition map (APM) | |
echo -------------------------------------------------------------------------------- | |
echo $ hdiutil create -o /tmp/${isoName} -size 8g -layout SPUD -fs HFS+J -type SPARSE | |
hdiutil create -o /tmp/${isoName} -size 8g -layout SPUD -fs HFS+J -type SPARSE | |
echo | |
echo Mount ${isoName} for package addition at /Volumes/install_build | |
echo -------------------------------------------------------------------------------- | |
echo $ hdiutil attach /tmp/${isoName}.sparseimage -noverify -nobrowse -mountpoint /Volumes/install_build | |
hdiutil attach /tmp/${isoName}.sparseimage -noverify -nobrowse -mountpoint /Volumes/install_build | |
echo | |
echo Write the base system to /Volumes/install_build | |
echo -------------------------------------------------------------------------------- | |
# echo $ asr restore -source /Volumes/install_app/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase | |
# asr restore -source /Volumes/install_app/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase | |
echo $ time asr restore -source "${installerAppName}"/Contents/SharedSupport/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase | |
time asr restore -source "${installerAppName}"/Contents/SharedSupport/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase | |
echo | |
echo Remove a link (if present), copy packages | |
echo -------------------------------------------------------------------------------- | |
# echo $ rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages | |
# rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages | |
echo $ time ditto -V /Volumes/install_app/Packages /Volumes/OS\ X\ Base\ System/System/Installation/ | |
time ditto -V /Volumes/install_app/Packages /Volumes/OS\ X\ Base\ System/System/Installation/ | |
echo | |
echo Copy dependencies | |
echo -------------------------------------------------------------------------------- | |
# echo $ cp -rp /Volumes/install_app/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/BaseSystem.chunklist | |
# cp -rp /Volumes/install_app/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/BaseSystem.chunklist | |
echo $ ditto -V "${installerAppName}"/Contents/SharedSupport/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/BaseSystem.chunklist | |
ditto -V "${installerAppName}"/Contents/SharedSupport/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/BaseSystem.chunklist | |
# echo $ cp -rp /Volumes/install_app/BaseSystem.dmg /Volumes/OS\ X\ Base\ System/BaseSystem.dmg | |
# cp -rp /Volumes/install_app/BaseSystem.dmg /Volumes/OS\ X\ Base\ System/BaseSystem.dmg | |
echo $ time ditto -V "${installerAppName}"/Contents/SharedSupport/BaseSystem.dmg /Volumes/OS\ X\ Base\ System/BaseSystem.dmg | |
time ditto -V "${installerAppName}"/Contents/SharedSupport/BaseSystem.dmg /Volumes/OS\ X\ Base\ System/BaseSystem.dmg | |
echo | |
echo Unmount an image from /Volumes/install_app | |
echo -------------------------------------------------------------------------------- | |
echo $ hdiutil detach /Volumes/install_app | |
hdiutil detach /Volumes/install_app | |
echo | |
echo Unmount the image of the base system | |
echo -------------------------------------------------------------------------------- | |
echo $ hdiutil detach /Volumes/OS\ X\ Base\ System/ | |
hdiutil detach /Volumes/OS\ X\ Base\ System/ | |
echo | |
echo Resize the partition in ${isoName} – remove free space | |
echo -------------------------------------------------------------------------------- | |
echo $ hdiutil resize -size `hdiutil resize -limits /tmp/${isoName}.sparseimage | tail -n 1 | awk '{ print $1 }'`b /tmp/${isoName}.sparseimage | |
hdiutil resize -size `hdiutil resize -limits /tmp/${isoName}.sparseimage | tail -n 1 | awk '{ print $1 }'`b /tmp/${isoName}.sparseimage | |
echo | |
echo Convert ${isoName} to UDTO (DVD/CD-R master for export) | |
echo -------------------------------------------------------------------------------- | |
echo $ time hdiutil convert /tmp/${isoName}.sparseimage -format UDTO -o /tmp/${isoName} | |
time hdiutil convert /tmp/${isoName}.sparseimage -format UDTO -o /tmp/${isoName} | |
echo | |
echo Remove the temporary .sparseimage file | |
echo -------------------------------------------------------------------------------- | |
echo $ rm /tmp/${isoName}.sparseimage | |
rm /tmp/${isoName}.sparseimage | |
echo | |
echo Rename the .iso file, move it to the desktop | |
echo -------------------------------------------------------------------------------- | |
echo $ mv /tmp/${isoName}.cdr ~/Desktop/${isoName}.iso | |
mv /tmp/${isoName}.cdr ~/Desktop/${isoName}.iso | |
fi | |
} | |
# | |
# installerExists | |
# | |
# Returns 0 if the installer was found either locally or in the /Applications directory. 1 if not. | |
# | |
function installerExists() | |
{ | |
local installerAppName=$1 | |
local result=1 | |
if [ -e "${installerAppName}" ] ; then | |
result=0 | |
elif [ -e /Applications/"${installerAppName}" ] ; then | |
result=0 | |
fi | |
return ${result} | |
} | |
# | |
# Main script code | |
# | |
# Eject installer disk in case it was opened after download from App Store | |
hdiutil info | grep /dev/disk | grep partition | cut -f 1 | xargs hdiutil detach -force | |
# Seek a compatible installer. | |
# If found, then begin the ISO production routine. | |
installerExists "Install macOS Sierra.app" | |
result=$? | |
if [ ${result} -eq 0 ] ; then | |
createISO "Install macOS 10.13 Beta.app" "10.13" | |
else | |
installerExists "Install macOS Sierra.app" | |
result=$? | |
if [ ${result} -eq 0 ] ; then | |
createISO "Install macOS Sierra.app" "Sierra" | |
else | |
installerExists "Install OS X El Capitan.app" | |
result=$? | |
if [ ${result} -eq 0 ] ; then | |
createISO "Install OS X El Capitan.app" "El Capitan" | |
else | |
installerExists "Install OS X Yosemite.app" | |
result=$? | |
if [ ${result} -eq 0 ] ; then | |
createISO "Install OS X Yosemite.app" "Yosemite" | |
else | |
echo "A compatible installer was not found." | |
fi | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment