mirror of
https://github.com/thewesker/osx-iso.git
synced 2025-12-20 12:21:06 -05:00
Refactor
Lil cleaner, clearer and easier to use.
This commit is contained in:
11
README.md
11
README.md
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
The appropriate installation file(s) must be located in `/Applications` i.e.
|
The appropriate installation app file(s) must be located in `/Applications` i.e.
|
||||||
|
|
||||||
```
|
```
|
||||||
/Applications/Install macOS High Sierra.app
|
/Applications/Install macOS High Sierra.app
|
||||||
@@ -19,13 +19,18 @@ Mac users can download theses files from the App Store.
|
|||||||
## Install with [bpkg](https://github.com/bpkg/bpkg)
|
## Install with [bpkg](https://github.com/bpkg/bpkg)
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ bpkg install busterc/osx-iso
|
$ bpkg install busterc/osx-iso -g
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ osxiso <"High Sierra"|Sierra|"El Capitan"|Yosemite|Mavericks>
|
$ osxiso
|
||||||
|
|
||||||
|
1) macOS High Sierra 3) OS X El Capitan 5) OS X Mavericks
|
||||||
|
2) macOS Sierra 4) OS X Yosemite 6) Quit
|
||||||
|
|
||||||
|
Select OS or Quit:
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
227
osxiso
227
osxiso
@@ -1,111 +1,79 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
function osxiso() {
|
function osxiso() {
|
||||||
|
PS3="
|
||||||
|
Select OS or Quit: "
|
||||||
|
temp="$PWD/temp"
|
||||||
|
dist="$PWD/dist"
|
||||||
|
base_mount="/Volumes/OS X Base System"
|
||||||
|
build_mount="/Volumes/install_build"
|
||||||
|
app_mount="/Volumes/install_app"
|
||||||
|
apps_v1="|macOS Sierra|OS X El Capitan|OS X Yosemite|OS X Mavericks|"
|
||||||
|
apps_v2="|macOS High Sierra|"
|
||||||
|
apps=(
|
||||||
|
"macOS High Sierra"
|
||||||
|
"macOS Sierra"
|
||||||
|
"OS X El Capitan"
|
||||||
|
"OS X Yosemite"
|
||||||
|
"OS X Mavericks"
|
||||||
|
)
|
||||||
|
apps_available=()
|
||||||
|
|
||||||
local app # path for "Install OS X <version>.app"
|
function log_warning() {
|
||||||
|
echo "$(tput setab 3)$(tput setaf 0)>> $* $(tput sgr0)"
|
||||||
function usage() {
|
|
||||||
cat <<EOF
|
|
||||||
|
|
||||||
Create a bootable ISO of OS X / macOS, from the installation app file.
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
|
|
||||||
$ ${0##*/} <"High Sierra"|Sierra|"El Capitan"|Yosemite|Mavericks>
|
|
||||||
|
|
||||||
Prerequisites:
|
|
||||||
|
|
||||||
The installation app file(s) must be unaltered and located at:
|
|
||||||
"/Applications/Install macOS High Sierra.app"
|
|
||||||
"/Applications/Install macOS Sierra.app"
|
|
||||||
"/Applications/Install OS X El Capitan.app"
|
|
||||||
"/Applications/Install OS X Yosemite.app"
|
|
||||||
"/Applications/Install OS X Mavericks.app"
|
|
||||||
EOF
|
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local temp="$PWD/temp"
|
function log_error() {
|
||||||
local dist="$PWD/dist"
|
>&2 echo "$(tput setab 1)$(tput setaf 7)>> $* $(tput sgr0)"
|
||||||
local iso="$dist/$1.iso"
|
}
|
||||||
local app_mount="/Volumes/install_app"
|
|
||||||
local build_mount="/Volumes/install_build"
|
function log_success() {
|
||||||
local base_mount="/Volumes/OS X Base System"
|
echo "$(tput setab 2)$(tput setaf 7)$*$(tput sgr0)"
|
||||||
local highsierra_mount="/Volumes/Install macOS High Sierra"
|
}
|
||||||
|
|
||||||
function detach_mounts() {
|
function detach_mounts() {
|
||||||
|
# Unmount OS
|
||||||
|
[[ ! -d "/Volumes/Install $1" ]] || hdiutil detach "/Volumes/Install $1"
|
||||||
# Unmount the installer image
|
# Unmount the installer image
|
||||||
[[ ! -d "$app_mount" ]] || hdiutil detach "$app_mount"
|
[[ ! -d "$app_mount" ]] || hdiutil detach "$app_mount"
|
||||||
|
|
||||||
# Unmount the sparse bundle
|
# Unmount the sparse bundle
|
||||||
[[ ! -d "$base_mount" ]] || hdiutil detach "$base_mount"
|
[[ ! -d "$base_mount" ]] || hdiutil detach "$base_mount"
|
||||||
|
|
||||||
# Unmount the High Sierra specific
|
|
||||||
[[ ! -d "$highsierra_mount" ]] || hdiutil detach "$highsierra_mount"
|
|
||||||
|
|
||||||
# Unmount temporary build path
|
# Unmount temporary build path
|
||||||
[[ ! -d "$build_mount" ]] || hdiutil detach "$build_mount"
|
[[ ! -d "$build_mount" ]] || hdiutil detach "$build_mount"
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
detach_mounts
|
detach_mounts "$1"
|
||||||
|
|
||||||
# Remove temp directory
|
# Remove temp directory
|
||||||
rm -rf "$temp"
|
rm -rf "$temp"
|
||||||
}
|
}
|
||||||
|
|
||||||
function abort() {
|
function abort() {
|
||||||
printf "\nCommand returned with error, aborting ...\n\n"
|
echo
|
||||||
|
log_error "Command returned with error, aborting ..."
|
||||||
|
echo
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
function prep_build() {
|
function prep_build() {
|
||||||
# Attempt cleanup of any previous attempts
|
# Attempt cleanup of any failed previous attempts
|
||||||
cleanup
|
cleanup "$1"
|
||||||
|
|
||||||
# Prepare to do work
|
# Prepare to do work
|
||||||
mkdir -p "$temp"
|
mkdir -p "$temp"
|
||||||
mkdir -p "$dist"
|
mkdir -p "$dist"
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_v2() {
|
function build_v1() {
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
trap abort ERR
|
trap abort ERR
|
||||||
|
|
||||||
prep_build
|
local app_file="/Applications/Install $1.app"
|
||||||
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
printf "<sudo> "
|
|
||||||
sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume "$build_mount"
|
|
||||||
|
|
||||||
# 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"
|
|
||||||
}
|
|
||||||
|
|
||||||
function build() {
|
|
||||||
trap cleanup EXIT
|
|
||||||
trap abort ERR
|
|
||||||
|
|
||||||
prep_build
|
prep_build
|
||||||
|
|
||||||
# Mount the installer image
|
# Mount the installer image
|
||||||
hdiutil attach "$app/Contents/SharedSupport/InstallESD.dmg" -noverify -nobrowse -mountpoint "$app_mount"
|
hdiutil attach "$app_file/Contents/SharedSupport/InstallESD.dmg" -noverify -nobrowse -mountpoint "$app_mount"
|
||||||
|
|
||||||
# Create a blank ISO of 7316MB with a Single Partition
|
# Create a blank ISO of 7316MB with a Single Partition
|
||||||
hdiutil create -o "$temp/$1.cdr" -size 7316m -layout SPUD -fs HFS+J
|
hdiutil create -o "$temp/$1.cdr" -size 7316m -layout SPUD -fs HFS+J
|
||||||
@@ -124,66 +92,103 @@ EOF
|
|||||||
cp -rp "$app_mount/BaseSystem.chunklist" "$base_mount/BaseSystem.chunklist"
|
cp -rp "$app_mount/BaseSystem.chunklist" "$base_mount/BaseSystem.chunklist"
|
||||||
cp -rp "$app_mount/BaseSystem.dmg" "$base_mount/BaseSystem.dmg"
|
cp -rp "$app_mount/BaseSystem.dmg" "$base_mount/BaseSystem.dmg"
|
||||||
|
|
||||||
# Detach mounts
|
detach_mounts "$1"
|
||||||
detach_mounts
|
|
||||||
|
|
||||||
# Convert the sparse bundle to ISO/CD master
|
# Convert the sparse bundle to ISO/CD master
|
||||||
hdiutil convert "$temp/$1.cdr.dmg" -format UDTO -o "$temp/$1.iso"
|
hdiutil convert "$temp/$1.cdr.dmg" -format UDTO -o "$temp/$1.iso"
|
||||||
|
|
||||||
# Rename the ISO and move it to the distribution "dist" dir
|
# Rename the ISO and move it to the distribution dir
|
||||||
mv "$temp/$1.iso.cdr" "$iso"
|
mv "$temp/$1.iso.cdr" "$dist/$1.iso"
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
printf "\n========== FINISHED ==========\n\n"
|
echo
|
||||||
printf "ISO is located at '%s'\n\n" "$iso"
|
log_success "========== FINISHED =========="
|
||||||
|
echo
|
||||||
|
printf "ISO is located at: '%s'\n\n" "$dist/$1.iso"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Verify OS X Version
|
function build_v2() {
|
||||||
[[ $# -ne 0 ]] || usage
|
trap cleanup EXIT
|
||||||
local versions=(
|
trap abort ERR
|
||||||
Yosemite
|
|
||||||
Mavericks
|
local app_file="/Applications/Install $1.app"
|
||||||
"El Capitan"
|
|
||||||
Sierra
|
prep_build "$1"
|
||||||
"High Sierra"
|
|
||||||
)
|
# Create a blank ISO of 7316MB with a Single Partition
|
||||||
for version in "${versions[@]}"; do
|
hdiutil create -o "$temp/$1.cdr" -size 7316m -layout SPUD -fs HFS+J
|
||||||
if [[ "$1" = "$version" ]]; then
|
|
||||||
if [[ "$1" == *"Sierra"* ]]; then
|
# Mount the blank ISO
|
||||||
app="/Applications/Install macOS $1.app"
|
hdiutil attach "$temp/$1.cdr.dmg" -noverify -nobrowse -mountpoint "$build_mount"
|
||||||
|
|
||||||
|
# Let createinstallmedia populate the blank ISO
|
||||||
|
printf "$(tput setab 3)$(tput setaf 0)%s$(tput sgr0) " "<sudo>"
|
||||||
|
sudo "$app_file"/Contents/Resources/createinstallmedia --volume "$build_mount" --nointeraction
|
||||||
|
|
||||||
|
detach_mounts "$1"
|
||||||
|
|
||||||
|
# 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 dir
|
||||||
|
mv "$temp/$1.iso.cdr" "$dist/$1.iso"
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
echo
|
||||||
|
log_success "========== FINISHED =========="
|
||||||
|
echo
|
||||||
|
printf "ISO is located at: '%s'\n\n" "$dist/$1.iso"
|
||||||
|
}
|
||||||
|
|
||||||
|
function choose() {
|
||||||
|
echo
|
||||||
|
|
||||||
|
select app in "${apps_available[@]}"; do
|
||||||
|
case "$app" in
|
||||||
|
"Quit")
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [[ "$apps_v2" == *"|$app|"* ]]; then
|
||||||
|
log_success "** Building ISO for $app **"
|
||||||
|
build_v2 "$app"
|
||||||
|
elif [[ "$apps_v1" == *"|$app|"* ]]; then
|
||||||
|
log_success "** Building ISO for $app **"
|
||||||
|
build_v1 "$app"
|
||||||
else
|
else
|
||||||
app="/Applications/Install OS X $1.app"
|
log_error "You must select a valid option *number* from the list."
|
||||||
|
choose
|
||||||
fi
|
fi
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
if [[ ! -e "$app" ]]; then
|
function main() {
|
||||||
cat <<EOF
|
for app in "${apps[@]}"; do
|
||||||
|
if [[ -d "/Applications/Install $app.app" ]]; then
|
||||||
Missing: $app
|
apps_available+=("$app")
|
||||||
|
|
||||||
* You can download it from the App Store
|
|
||||||
|
|
||||||
EOF
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Do Work
|
|
||||||
if [[ "$1" == "High Sierra" ]]; then
|
|
||||||
build_v2 "$1"
|
|
||||||
else
|
else
|
||||||
build "$1"
|
log_warning "Missing /Applications/Install $app.app"
|
||||||
fi
|
|
||||||
exit $?
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Invalid version provided
|
[[ ${#apps_available[@]} -eq 0 ]] && log_error "You do not have any installer apps available. You can download them from the App Store and try again!" && exit 1
|
||||||
usage
|
|
||||||
|
apps_available+=("Quit")
|
||||||
|
|
||||||
|
choose
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
}
|
}
|
||||||
|
|
||||||
## Export or run
|
## Export or run
|
||||||
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
|
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
|
||||||
export -f osxiso
|
export -f osxiso
|
||||||
else
|
else
|
||||||
osxiso "$@"
|
osxiso
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "osxiso",
|
"name": "osxiso",
|
||||||
"version": "2.0.0",
|
"version": "3.0.0",
|
||||||
"description": "Create a bootable ISO of OS X / macOS, from the installation app file.",
|
"description": "Create a bootable ISO of OS X / macOS, from the installation app file.",
|
||||||
"global": "1",
|
"global": "1",
|
||||||
"install": "install -c osxiso ${PREFIX:-/usr/local}/bin",
|
"install": "install -c osxiso ${PREFIX:-/usr/local}/bin",
|
||||||
|
|||||||
Reference in New Issue
Block a user