-
-
Save mddelfino/cc81a7298be12dcfd0ecfb8c9b70c572 to your computer and use it in GitHub Desktop.
Create bootable ISO from HighSierra 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/sh | |
### AUTHOR DOCUMENTATION ### | |
# HISTORY: | |
# Original script by agentsim on 2017.06.09 | |
# Improvements provided by github users umetzu, halabibk, br0adband and pat-s, | |
# et al. throughout the remainder of 2017 | |
# Spruced up by Matthew Delfino on 2018.07.04 | |
### VARIABLES ### | |
# User that should own the iso. | |
THE_OWNER="matthew.delfino" | |
# Group that should own the iso. | |
THE_GROUP="staff" | |
# POSIX Permissions of iso. | |
POSIX_MODE="0664" | |
# Wherein would you like the final iso image to be placed? | |
ENCLOSING_FOLDER_OF_FINAL_ISO="/Users/Shared" | |
# What do you want the name of the final iso to be, sans the ".iso"? | |
NAME_OF_FINAL_ISO="Apple_macOS_10.13_High_Sierra_x86_64" | |
# The location of the temporary folder where most work will be done (/tmp). | |
TEMPORARY_FOLDER="/private/tmp" | |
# Path to the installer. Often is "/Applications/Install macOS High Sierra.app". | |
MAC_OS_INSTALLER_PATH="/Applications/Install macOS High Sierra.app" | |
# Arbitrary name of the image we'll be making to create the install media. | |
NAME_OF_MEDIA_FOR_INSTALLER="InstallMedia" | |
# An appropriate size for the media (at least 5397 at the time of authoring). | |
SIZE_OF_MEDIA="5400m" | |
# An appropriate disk format. HFS+J works fine. APFS might work, too (untested). | |
FORMAT_OF_MEDIA="HFS+J" | |
# The name that the installer will give the install media. Usually this is set | |
# by Apple. Almost always matches the name of the install app, sans the ".app". | |
INSTALLER_NAME="Install macOS High Sierra" | |
# Derives scriptname from name of file. To edit this, change the file name. | |
SCRIPTNAME="${0##*/}" | |
# The version of this script. | |
VERSION="1.0" | |
### FUNCTIONS ### | |
AdjustTerminalOutputColor() | |
{ | |
# Author matthew.delfino on 2018.07.04: | |
# | |
# Changes the output color of Terminal text. | |
# Parsed Argument Variables | |
local desiredColor=$1 # The color desired. We support default | |
# (none), red, green, yellow, blue, | |
# magenta, cyan and white (e.g., | |
# "blue"). | |
# Sequence | |
case $desiredColor in | |
red ) | |
tput setaf 1 | |
;; | |
green ) | |
tput setaf 2 | |
;; | |
yellow ) | |
tput setaf 3 | |
;; | |
blue ) | |
tput setaf 4 | |
;; | |
magenta ) | |
tput setaf 5 | |
;; | |
cyan ) | |
tput setaf 6 | |
;; | |
white ) | |
tput setaf 7 | |
;; | |
default ) | |
tput op | |
;; | |
* ) | |
tput op | |
;; | |
esac | |
} | |
ExitIfFail() | |
{ | |
# Author matthew.delfino on 2018.07.04: | |
# | |
# A function to exit the script if any operation fails to complete. | |
# Parsed Argument Variables | |
local theResult=$1 # Description (e.g., "example"). | |
# Sequence | |
if [[ $theResult -ne 0 ]] | |
then | |
AdjustTerminalOutputColor red | |
echo " ! Operation failed. Aborting..." | |
AdjustTerminalOutputColor default | |
exit 1 | |
else | |
AdjustTerminalOutputColor green | |
echo " o Operation complete!" | |
AdjustTerminalOutputColor default | |
fi | |
} | |
PrintHelpPage() | |
{ | |
# Author matthew.delfino on 2018.07.04: | |
# | |
# A helpful help page. | |
# Parsed Argument Variables | |
local illegalOption=$1 # An illegal option passed to the | |
# function (e.g., "--makemerich"). | |
local tipToPrint=$2 # A tip (e.g., "Try again.") | |
# Sequence | |
if [ "$illegalOption" != "" ]; then echo "${SCRIPTNAME}: illegal option: $illegalOption"; fi | |
if [ "$tipToPrint" != "" ]; then echo "${SCRIPTNAME}: $tipToPrint"; fi | |
echo | |
echo "$SCRIPTNAME is a script that creates an iso installer media for macOS." | |
echo "Currently configured for macOS High Sierra (10.13). Any customizations" | |
echo "must be done in the \"VARIABLES\" section of this bash shell script." | |
echo "You must have an installer for macOS High Sierra, and you must be root." | |
echo | |
echo "usage: $SCRIPTNAME [-vh]" | |
} | |
PrintVersion() | |
{ | |
# Author matthew.delfino on 2018.07.04: | |
# | |
# Just prints the current version. Takes no arguments. | |
# Sequence | |
echo $VERSION | |
} | |
### SEQUENCE ### | |
if [ "$1" ] | |
then | |
case $1 in | |
# So we can see the version of the script" | |
--version | -version | version | -v | v ) | |
PrintVersion | |
exit 0 | |
;; | |
# So people can get a help page" | |
--help | -help | help | -h | h ) | |
PrintHelpPage "" "" | |
exit 0 | |
;; | |
* ) | |
PrintHelpPage "$1" "Invalid argument." | |
exit 1 | |
;; | |
esac | |
else | |
# Test for root user - we need to be root" | |
if [[ $(id | awk '{ print $1 }' | cut -c 5) -ne 0 ]] | |
then | |
echo "Must be root!" | |
exit 1 | |
fi | |
fi | |
# Introduction | |
echo | |
echo "The macOS ISO Installation Media Creator" | |
echo "Version $VERSION" | |
echo "For customizations, please open me and edit my VARAIBLES section" | |
echo | |
echo " + Creating a DDM and an Apple Partition Scheme partition map DMG image called ${NAME_OF_MEDIA_FOR_INSTALLER}.dmg in the ${TEMPORARY_FOLDER} folder..." | |
AdjustTerminalOutputColor blue | |
hdiutil create -o "${TEMPORARY_FOLDER}/${NAME_OF_MEDIA_FOR_INSTALLER}" -size "$SIZE_OF_MEDIA" -layout SPUD -fs "${FORMAT_OF_MEDIA}" | |
ExitIfFail $? | |
echo " + Mounting the ${NAME_OF_MEDIA_FOR_INSTALLER}.dmg to /Volumes/${NAME_OF_MEDIA_FOR_INSTALLER}..." | |
AdjustTerminalOutputColor blue | |
hdiutil attach "${TEMPORARY_FOLDER}/${NAME_OF_MEDIA_FOR_INSTALLER}.dmg" -noverify -mountpoint "/Volumes/${NAME_OF_MEDIA_FOR_INSTALLER}" | |
ExitIfFail $? | |
echo " + We're going to turn /Volumes/${NAME_OF_MEDIA_FOR_INSTALLER} into a bootable install media..." | |
AdjustTerminalOutputColor blue | |
sudo "${MAC_OS_INSTALLER_PATH}/Contents/Resources/createinstallmedia" --volume "/Volumes/${NAME_OF_MEDIA_FOR_INSTALLER}" --applicationpath "${MAC_OS_INSTALLER_PATH}" --nointeraction | |
ExitIfFail $? | |
echo " + /Volumes/${NAME_OF_MEDIA_FOR_INSTALLER} is now /Volumes/${INSTALLER_NAME}, and it's a valid installation media. Time to eject..." | |
AdjustTerminalOutputColor blue | |
hdiutil detach "/Volumes/${INSTALLER_NAME}" | |
ExitIfFail $? | |
echo " + Converting the ${NAME_OF_MEDIA_FOR_INSTALLER}.dmg to cdr/iso format..." | |
AdjustTerminalOutputColor blue | |
hdiutil convert "${TEMPORARY_FOLDER}/${NAME_OF_MEDIA_FOR_INSTALLER}.dmg" -format UDTO -o "${TEMPORARY_FOLDER}/${NAME_OF_FINAL_ISO}" | |
ExitIfFail $? | |
echo " + Renaming it's extension from CDR to ISO (they're the same format)..." | |
AdjustTerminalOutputColor blue | |
mv "${TEMPORARY_FOLDER}/${NAME_OF_FINAL_ISO}.cdr" "${ENCLOSING_FOLDER_OF_FINAL_ISO}/${NAME_OF_FINAL_ISO}.iso" | |
ExitIfFail $? | |
echo " + Cleaning up the ${NAME_OF_MEDIA_FOR_INSTALLER}.dmg (no longer needed)..." | |
AdjustTerminalOutputColor blue | |
rm "${TEMPORARY_FOLDER}/${NAME_OF_MEDIA_FOR_INSTALLER}.dmg" | |
ExitIfFail $? | |
echo " + Brushing up permissions and showing you where it is!" | |
AdjustTerminalOutputColor blue | |
chmod "${POSIX_MODE}" "${ENCLOSING_FOLDER_OF_FINAL_ISO}/${NAME_OF_FINAL_ISO}.iso" | |
chown "${THE_OWNER}":"${THE_GROUP}" "${ENCLOSING_FOLDER_OF_FINAL_ISO}/${NAME_OF_FINAL_ISO}.iso" | |
open "${ENCLOSING_FOLDER_OF_FINAL_ISO}" | |
ExitIfFail $? | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment