Skip to content

Instantly share code, notes, and snippets.

@jessepeterson
Created July 24, 2014 00:09
Show Gist options
  • Save jessepeterson/3d16d77525dd04d6c0f9 to your computer and use it in GitHub Desktop.
Save jessepeterson/3d16d77525dd04d6c0f9 to your computer and use it in GitHub Desktop.
Make OS X installer ISO (CDR) from OS Install app
#!/bin/sh
user_id=`id -u`
if [ $user_id -ne 0 ]; then
echo "$0: must be root"
exit 1
fi
if [ $# -lt 2 ]; then
echo "$0: not enough parameters. usage:"
echo "$0 <path-to-installer> <path-to-destination>"
exit 1
fi
installer_app_path="$1"
dest_dir="$2"
install_esd="$installer_app_path/Contents/SharedSupport/InstallESD.dmg"
install_esd_mount="/Volumes/OS X Install ESD"
if [ ! -f "$install_esd" ]; then
echo "$0: invalid installer app path"
exit 1
fi
if [ ! -d "$dest_dir" ]; then
echo "$0: invalid destination path"
exit 1
fi
base_sys="$install_esd_mount/BaseSystem.dmg"
temp_installer="$dest_dir/TempInstaller.sparseimage"
installer="$dest_dir/Installer.cdr"
if [ -f "$temp_installer" ]; then
echo "$0: temporary image exists"
echo "please delete $temp_installer"
exit 1
fi
if [ -f "$installer" ]; then
echo "$0: previous image exists"
echo "please delete $installer"
exit 1
fi
echo "Mounting ESD"
hdiutil attach \
-noverify \
-nobrowse \
"$install_esd"
echo "Converting BaseSystem"
hdiutil convert \
"$base_sys" -format UDSP -o "$temp_installer"
echo "Resizing converted BaseSystem"
hdiutil resize -size 8g "$temp_installer"
base_sys_mount="/Volumes/OS X Base System"
echo "Mounting converted BaseSystem"
hdiutil attach \
"$temp_installer" \
-noverify \
-nobrowse
rm "$base_sys_mount/System/Installation/Packages"
echo "Copying installer packages"
cp -pR "$install_esd_mount/Packages" "$base_sys_mount/System/Installation/"
echo "Ejecting Base"
hdiutil eject "$base_sys_mount"
echo "Ejecting ESD"
hdiutil eject "$install_esd_mount"
echo "Converting to UDTO"
hdiutil convert \
"$temp_installer" -format UDTO -o "$installer"
echo "Removing temp installer"
rm "$temp_installer"
echo
echo
echo 'Your shiney new installer CDR should be here:'
echo " $installer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment