Skip to content

Instantly share code, notes, and snippets.

@maojj
Last active August 29, 2015 14:03
Show Gist options
  • Save maojj/63d8479d865f34da8e8e to your computer and use it in GitHub Desktop.
Save maojj/63d8479d865f34da8e8e to your computer and use it in GitHub Desktop.
A script for burning a Mac OS X bootable USB drive.
#!/bin/bash
#
# BurnUSBInstall.sh
#
# This is the script for burning a Mac OS X bootable USB drive.
#
# Author: maojj
# 2014.07.10
#
# Prepare an 8GB+ USB stick and format it with GUID partition mapping and a partition named Untitled
# print usage
usage() {
cat << EOF
Usage:
BurnUSBInstall.sh <APP Path> <USB Volume Name>
example:
BurnUSBInstall.sh "/Applications/Install OS X 10.10 Developer Preview.app" "UnTitled"
EOF
}
if [ `id -u` -ne 0 ]
then
echo "please run it by root"
exit 0
fi
if [[ $# -lt 2 ]]; then
usage
exit 1
fi
INSTALL_APP_PATH=$1
ORI_VOLUME_NAME=$2
DEST_VOLUME_NAME="OS X Base System"
SOURCE_VOLUME_NAME="OS X Install ESD"
echo "step1:Attach $INSTALL_APP_PATH/Contents/SharedSupport/InstallESD.dmg"
hdiutil attach "$INSTALL_APP_PATH/Contents/SharedSupport/InstallESD.dmg"
echo "step2:Restore InstallESD.dmg to /Volumes/$ORI_VOLUME_NAME"
asr restore -source "/Volumes/$SOURCE_VOLUME_NAME/BaseSystem.dmg" -target "/Volumes/$ORI_VOLUME_NAME" -erase -format HFS+
echo "step3:rm Packages in /Volumes/$DEST_VOLUME_NAME/System/Installation/Packages"
rm "/Volumes/$DEST_VOLUME_NAME/System/Installation/Packages"
echo "step4:copy Packages"
rsync --progress -r "/Volumes/$SOURCE_VOLUME_NAME/Packages/" "/Volumes/$DEST_VOLUME_NAME/System/Installation/Packages"
echo "step5: copy BaseSystem.dmg"
rsync --progress "/Volumes/$SOURCE_VOLUME_NAME/BaseSystem.dmg" "/Volumes/$SOURCE_VOLUME_NAME/BaseSystem.chunklist" "/Volumes/$DEST_VOLUME_NAME"
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment