mirror of
https://github.com/thewesker/osx-iso.git
synced 2025-12-20 04:11:15 -05:00
Reworked the script to support newer versions; now including: - macOS Sierra - OS X El Capitan
138 lines
3.1 KiB
Bash
Executable File
138 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
function osxiso() {
|
|
|
|
local app # path for "Install OS X <version>.app"
|
|
|
|
function usage() {
|
|
cat <<EOF
|
|
|
|
Create a bootable ISO of OS X / macOS, from the installation app file.
|
|
|
|
Usage:
|
|
|
|
$ ${0##*/} <Sierra|"El Capitan"|Yosemite|Mavericks>
|
|
|
|
EOF
|
|
exit 1
|
|
}
|
|
|
|
function build() {
|
|
local temp="$PWD/temp"
|
|
local dist="$PWD/dist"
|
|
local iso="$dist/$1.iso"
|
|
local app_mount="/Volumes/install_app"
|
|
local build_mount="/Volumes/install_build"
|
|
local base_mount="/Volumes/OS X Base System"
|
|
|
|
function detach_mounts() {
|
|
echo "Attempting to detach mounts"
|
|
|
|
# Unmount the installer image
|
|
[[ ! -d "$app_mount" ]] || hdiutil detach "$app_mount"
|
|
|
|
# Unmount the sparse bundle
|
|
[[ ! -d "$base_mount" ]] || hdiutil detach "$base_mount"
|
|
}
|
|
|
|
function cleanup() {
|
|
detach_mounts
|
|
|
|
# Remove temp directory
|
|
rm -rf "$temp"
|
|
}
|
|
|
|
function abort() {
|
|
printf "\nCommand returned with error, aborting ...\n\n"
|
|
exit 2
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
trap abort ERR
|
|
|
|
# Attempt cleanup of any previous attempts
|
|
cleanup
|
|
|
|
# Prepare to do work
|
|
mkdir -p "$temp"
|
|
mkdir -p "$dist"
|
|
|
|
# Mount the installer image
|
|
hdiutil attach "$app/Contents/SharedSupport/InstallESD.dmg" -noverify -nobrowse -mountpoint "$app_mount"
|
|
|
|
# Create a blank ISO of 7316MB with a Single Partition
|
|
hdiutil create -o "$temp/$1.cdr" -size 7316m -layout SPUD -fs HFS+J
|
|
|
|
# Mount the blank ISO
|
|
hdiutil attach "$temp/$1.cdr.dmg" -noverify -nobrowse -mountpoint "$build_mount"
|
|
|
|
# Restore the Base System into the blank ISO
|
|
asr restore -source "$app_mount/BaseSystem.dmg" -target "$build_mount" -noprompt -noverify -erase
|
|
|
|
# Remove Package link and replace with actual files
|
|
rm "$base_mount/System/Installation/Packages"
|
|
cp -rp "$app_mount/Packages" "$base_mount/System/Installation/"
|
|
|
|
# Copy "$1" installer dependencies
|
|
cp -rp "$app_mount/BaseSystem.chunklist" "$base_mount/BaseSystem.chunklist"
|
|
cp -rp "$app_mount/BaseSystem.dmg" "$base_mount/BaseSystem.dmg"
|
|
|
|
# Detach mounts
|
|
detach_mounts
|
|
|
|
# Convert the sparse bundle to ISO/CD master
|
|
hdiutil convert "$temp/$1.cdr.dmg" -format UDTO -o "$temp/$1.iso"
|
|
|
|
# Rename the ISO and move it to the distribution "dist" dir
|
|
mv "$temp/$1.iso.cdr" "$iso"
|
|
|
|
cleanup
|
|
|
|
printf "\n========== FINISHED ==========\n\n"
|
|
printf "ISO is located at '%s'\n\n" "$iso"
|
|
}
|
|
|
|
# Verify OS X Version
|
|
[[ $# -ne 0 ]] || usage
|
|
local versions=(
|
|
Yosemite
|
|
Mavericks
|
|
"El Capitan"
|
|
Sierra
|
|
)
|
|
for version in "${versions[@]}"; do
|
|
if [[ "$1" = "$version" ]]; then
|
|
if [[ "$1" = "Sierra" ]]; then
|
|
app="/Applications/Install macOS $1.app"
|
|
else
|
|
app="/Applications/Install OS X $1.app"
|
|
fi
|
|
|
|
if [[ ! -e "$app" ]]; then
|
|
cat <<EOF
|
|
|
|
Missing: $app
|
|
|
|
* You can install it with the App Store
|
|
|
|
EOF
|
|
exit 1
|
|
fi
|
|
|
|
# Do Work
|
|
build "$1"
|
|
exit $?
|
|
fi
|
|
done
|
|
|
|
# Invalid version provided
|
|
usage
|
|
}
|
|
|
|
## Export or run
|
|
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
|
|
export -f osxiso
|
|
else
|
|
osxiso "$@"
|
|
fi
|