Skip to content

Instantly share code, notes, and snippets.

@efmeeks
Last active October 29, 2017 02:23
Show Gist options
  • Save efmeeks/99fc75985749a2b6e452907a2e60f665 to your computer and use it in GitHub Desktop.
Save efmeeks/99fc75985749a2b6e452907a2e60f665 to your computer and use it in GitHub Desktop.

Create macOS USB Installer

What you'll need...

  • Apple computer
  • USB drive with ≥ 8GB capacity
  • Copy of macOS installer from the App Store

What you'll do...

Copy/paste this into Terminal

bash <(curl -Ls url.efmeeks.net/osx-usb-bash)

#!/bin/bash
# Create macOS USB Installer
# url.efmeeks.net/osx-usb
clear
cat << eof
╭──────────────────────────────────────╮
│ To quit, press CTRL+C at any time. │
╰──────────────────────────────────────╯
eof
pass() {
echo "$1 = ok"
}
fail() {
echo "$1 = fail"
fail=1
}
getinstaller() {
installer=''
while [ -z "$installer" ]; do
echo "Drag and drop the macOS installer here, then press ENTER"
sleep 1
open /Applications
read installer
done
}
getvolume() {
volume=''
while [ -z "$volume" ]; do
echo "Drag and drop your USB volume here, then press ENTER"
sleep 1
open /Volumes
read volume
done
}
validate() {
[ -d "$installer" ] && pass path || fail path
[ -x "$installer/Contents/Resources/createinstallmedia" ] && pass createinstallmedia || fail createinstallmedia
}
makeusb() {
cat << eof
╭─────────────────────────────────────────╮
│ Writing the bootable image to USB │
│ will take a considerable amount of time │
│ (especially USB 2.0) │
╰─────────────────────────────────────────╯
eof
cim="$(find "$installer" -type f -name "createinstallmedia")"
echo "Note: when prompted for your password, the prompt will remain blank as you type. This is normal."
sudo "$cim" --volume "$volume" --applicationpath "$installer"
echo "Done"
echo "Ejecting disk"
sudo diskutil ejectdisk "$volume"
}
# let's do it...
getinstaller
validate
[[ $fail == 1 ]] && exit
getvolume
makeusb
cat << eof
╭──────────────────────────────────────────╮
│ Now you can plug the USB drive into the │
│ target machine, reboot, and hold ⌘R │
│ then select the Installer as boot source │
╰──────────────────────────────────────────╯
eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment