Skip to content

Instantly share code, notes, and snippets.

@tjluoma
Created August 27, 2015 16:55
Show Gist options
  • Select an option

  • Save tjluoma/0160b49adf93e07a568c to your computer and use it in GitHub Desktop.

Select an option

Save tjluoma/0160b49adf93e07a568c to your computer and use it in GitHub Desktop.
Given an “Install OS X {whatever}.app” - make a bootable USB installer
#!/bin/zsh -f
## Make USB Installer from Installer app
##
## Based on:
## “How to make a bootable OS X 10.10 Yosemite install drive”
## http://www.macworld.com/article/2367748/how-to-make-a-bootable-os-x-10-10-yosemite-install-drive.html
##
## From: Timothy J. Luoma
## Mail: luomat at gmail dot com
## Date: 2015-08-26
## What is the name of the USB Drive as it appears in Finder?
USB_MOUNT='/Volumes/Untitled'
## Where is the Install OS X {Whatever}.app ?
APP='/Applications/Install OS X Yosemite.app'
#####|####|####|####|####|####|####|####|####|####|####|####|####|####|####
#
# Shouldn't have to change anything below this line
#
NAME="$0:t:r"
#####|####|####|####|####|####|####|####|####|####|####|####|####|####|####
if [ ! -e "$APP" ]
then
echo "$NAME: $APP not found"
exit 1
fi
#####|####|####|####|####|####|####|####|####|####|####|####|####|####|####
## Where is the `createinstallmedia` file?
CIM="$APP/Contents/Resources/createinstallmedia"
if [ ! -x "$CIM" ]
then
if [ ! -e "$CIM" ]
then
echo "$NAME: $CIM not found"
exit 1
fi
echo "$NAME: $CIM exists but is not executable"
exit 1
fi
#####|####|####|####|####|####|####|####|####|####|####|####|####|####|####
if [ ! -d "$USB_MOUNT" ]
then
echo "$NAME: Nothing mounted at $USB_MOUNT"
exit 1
fi
#####|####|####|####|####|####|####|####|####|####|####|####|####|####|####
zmodload zsh/datetime
TIME=`strftime "%Y-%m-%d--%H.%M.%S" "$EPOCHSECONDS"`
function timestamp { strftime "%Y-%m-%d--%H.%M.%S" "$EPOCHSECONDS" }
#####|####|####|####|####|####|####|####|####|####|####|####|####|####|####
## This next line means "If growlnotify is installed AND Growl is running
## use growlnotify. Otherwise, it will be ignored
if (( $+commands[growlnotify])) && (pgrep -qx Growl)
then
growlnotify --sticky \
--appIcon "$APP:t:r" \
--identifier "$NAME" \
--message "Started at `timestamp`" \
--title "$NAME"
fi
echo "$NAME: Started at `timestamp`"
####|####|####|####|####|####|####|####|####|####|####|####|####|####|####
#
# Here is where the action really starts!
#
sudo "$APP/Contents/Resources/createinstallmedia" \
--volume "$USB_MOUNT" \
--applicationpath "$APP" \
--nointeraction
EXIT="$?"
if [ "$EXIT" = "0" ]
then
afplay /System/Library/Sounds/Glass.aiff
if (( $+commands[growlnotify])) && (pgrep -qx Growl)
then
growlnotify \
--appIcon "$APP:t:r" \
--identifier "$NAME" \
--message "Finished at`timestamp`" \
--title "$NAME SUCCESS"
fi
echo "$NAME: Successful finish at `timestamp`"
exit 0
else
afplay /System/Library/Sounds/Funk.aiff
if (( $+commands[growlnotify])) && (pgrep -qx Growl)
then
growlnotify --sticky \
--appIcon "$APP:t:r" \
--identifier "$NAME" \
--message "Exit code = $EXIT" \
--title "$NAME FAILED"
fi
echo "$NAME: 'createinstallmedia' failed with exit code = $EXIT at `timestamp`"
exit 1
fi
exit 0
#
#EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment