ref: add proper Apple silicon support, apped '.iso' to DMG image

While the script is compatible with Apple silicon Macs, it’s still recommended
 to run it on an x86_64 Intel Mac for optimal results.

For easier use and distribution, the final DMG image will have '.iso' appended to its file name.
Rufus no longer require switching to "All files" to saw the DMG image in Explorer.
Also fix "qemu-img: Could not locate UDIF trailer in dmg file" error.
This commit is contained in:
Tieu Long authored and GitHub committed 2025-12-21 01:04:38 +07:00
1 parent 164088dc91
commit 8a93aaf852
3 files changed
+433 -188

No files matched your search

+30 -19
View File
@@ -24,7 +24,7 @@ on:
- 'Mountain Lion' - 'Mountain Lion'
- 'Lion' - 'Lion'
image_format: image_format:
description: 'Select image format: iso for virtual machines, dmg for burning to USB drive' description: 'Select image format: iso for virtual machines, dmg for flash to USB drive'
required: true required: true
type: choice type: choice
options: options:
@@ -48,18 +48,19 @@ jobs:
df -h df -h
echo "Memory:" echo "Memory:"
top -l 1 | grep PhysMem top -l 1 | grep PhysMem
echo "CPU model:"
sysctl -a | grep dep.cpu.brand_string
- name: Create Image - name: Create macOS image
id: create_image id: create_image
continue-on-error: true
run: | run: |
if [ "${{ github.event.inputs.image_format }}" == "iso" ]; then if [ "${{ github.event.inputs.image_format }}" == "iso" ]; then
echo "Creating macOS ${{ github.event.inputs.macos_version }} ISO image" sudo bash mkmaciso "${{ github.event.inputs.macos_version }}"
bash mkmaciso "${{ github.event.inputs.macos_version }}"
echo "image_name=$(basename *.iso)" >> $GITHUB_OUTPUT echo "image_name=$(basename *.iso)" >> $GITHUB_OUTPUT
else else
echo "Creating macOS ${{ github.event.inputs.macos_version }} DMG image" sudo bash mkmaciso "${{ github.event.inputs.macos_version }}" dmg
bash mkmaciso "${{ github.event.inputs.macos_version }}" dmg echo "image_name=$(basename *.dmg.iso)" >> $GITHUB_OUTPUT
echo "image_name=$(basename *.dmg)" >> $GITHUB_OUTPUT
fi fi
- name: Upload ISO artifact - name: Upload ISO artifact
@@ -76,21 +77,31 @@ jobs:
uses: actions/upload-artifact@v5 uses: actions/upload-artifact@v5
with: with:
name: ${{ steps.create_image.outputs.image_name }} name: ${{ steps.create_image.outputs.image_name }}
path: ./*.dmg path: ./*.dmg.iso
compression-level: 0 compression-level: 0
retention-days: 7 retention-days: 7
- name: Summary - name: Summary
if: always()
run: | run: |
if [ "${{ github.event.inputs.image_format }}" == "iso" ]; then if [ "${{ steps.create_image.outcome }}" == "failure" ]; then
echo "## Successfully built $(basename *.iso)" >> $GITHUB_STEP_SUMMARY echo "## Download macOS failed" >> $GITHUB_STEP_SUMMARY
echo "Note: This ISO is intended for create macOS virtual machine on Proxmox VE, QEMU, VMware, and VirtualBox." >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY
else echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
echo "## Successfully built $(basename *.dmg)" >> $GITHUB_STEP_SUMMARY echo "> This runner may have network issues. Please **re-run the workflow** to try a different runner." >> $GITHUB_STEP_SUMMARY
echo 'Note: This DMG is intended for flash to USB drive using [Rufus](https://rufus.ie/en/#download) (Windows) or dd (Linux)' >> $GITHUB_STEP_SUMMARY elif [ "${{ job.status }}" == "success" ]; then
if [ "${{ github.event.inputs.image_format }}" == "iso" ]; then
echo "## Successfully built $(basename *.iso)" >> $GITHUB_STEP_SUMMARY
echo "Note: This ISO image is intended for create macOS virtual machine on Proxmox VE, QEMU, VMware, and VirtualBox." >> $GITHUB_STEP_SUMMARY
else
echo "## Successfully built $(basename *.dmg.iso)" >> $GITHUB_STEP_SUMMARY
echo "> [!NOTE]" >> $GITHUB_STEP_SUMMARY
echo '> This DMG image is intended for flash to USB drive using [Rufus](https://rufus.ie/en/#download) (Windows) or dd (Linux)' >> $GITHUB_STEP_SUMMARY
echo '> Can also be used with virtual machines (require convert to `.vhd` for Hyper-V or `.vmdk` for VMware)' >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "Found this useful? [Give it a ⭐ star](https://github.com/LongQT-sea/macos-iso-builder) so others can find it too!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!TIP]" >> $GITHUB_STEP_SUMMARY
echo "> Enable [Cloudflare WARP](https://one.one.one.one/) for faster downloads." >> $GITHUB_STEP_SUMMARY
fi fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "Found this useful? Give it a ⭐ star so others can find it too! https://github.com/LongQT-sea/macos-iso-builder" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!TIP]" >> $GITHUB_STEP_SUMMARY
echo "> Enable [Cloudflare WARP](https://one.one.one.one/) for faster downloads." >> $GITHUB_STEP_SUMMARY
+5 -7
View File
@@ -15,9 +15,9 @@
> [!IMPORTANT] > [!IMPORTANT]
> * Use the **"Build macOS Recovery ISO image"** workflow unless you really need an offline installer. > * Use the **"Build macOS Recovery ISO image"** workflow unless you really need an offline installer.
> * GitHub-hosted runners are a free public resource — please use them responsibly. > * GitHub-hosted runners are a free public resource — please use them responsibly.
> * Already have macOS? Build macOS installer ISO/DMG image with this command (replace `tahoe` with the desired version): > * If you already have macOS VM, you can build macOS ISO/DMG image using the following command (replace `tahoe` with your desired version):
``` ```
curl -L https://raw.githubusercontent.com/LongQT-sea/macos-iso-builder/main/mkmaciso | bash -s tahoe curl -sL https://raw.githubusercontent.com/LongQT-sea/macos-iso-builder/main/mkmaciso | bash -s tahoe
``` ```
--- ---
@@ -27,7 +27,7 @@ curl -L https://raw.githubusercontent.com/LongQT-sea/macos-iso-builder/main/mkma
1. **Fork** this repository. 1. **Fork** this repository.
2. Go to the **Actions** tab in your forked repository. 2. Go to the **Actions** tab in your forked repository.
3. Click the green button **"I understand my workflows, go ahead and enable them"**. 3. Click the green button **"I understand my workflows, go ahead and enable them"**.
4. Select the **"Build macOS Installer ISO/DMG image"** or **"Build macOS Recovery ISO image"** workflow from the left sidebar.. 4. Select the **"Build macOS Installer ISO/DMG image"** or **"Build macOS Recovery ISO image"** workflow from the left sidebar.
5. Click the **"Run workflow"** button. 5. Click the **"Run workflow"** button.
6. Configure the workflow inputs: 6. Configure the workflow inputs:
@@ -37,8 +37,6 @@ curl -L https://raw.githubusercontent.com/LongQT-sea/macos-iso-builder/main/mkma
8. Wait for the workflow to complete (this may take 10-60 minutes). 8. Wait for the workflow to complete (this may take 10-60 minutes).
9. Open the completed workflow run and scroll to the **Artifacts** section. 9. Open the completed workflow run and scroll to the **Artifacts** section.
10. Download the artifact (e.g., `macOS_Sequoia_15.7.3.iso`). 10. Download the artifact (e.g., `macOS_Sequoia_15.7.3.iso`).
> [!TIP]
> Enable [Cloudflare WARP](https://one.one.one.one/) for faster downloads.
11. Extract the ZIP file to get your `.iso` or `.dmg` file. 11. Extract the ZIP file to get your `.iso` or `.dmg` file.
--- ---
@@ -46,9 +44,9 @@ curl -L https://raw.githubusercontent.com/LongQT-sea/macos-iso-builder/main/mkma
> [!TIP] > [!TIP]
> To create a bootable macOS installer USB drive on Windows: > To create a bootable macOS installer USB drive on Windows:
> 1. Open [Rufus](https://rufus.ie/en/#download) > 1. Open [Rufus](https://rufus.ie/en/#download)
> 2. Click **SELECT**, change the filter to **"All files"**, then select your macOS `.dmg` > 2. Click **SELECT**, then select your macOS `.dmg.iso` image
> 3. Click **START** > 3. Click **START**
> 4. Optional: After flashing the `dmg` image to the USB drive, there will be free/unallocated space remaining on the USB drive. Use Disk Management to create a new FAT32 partition and place your EFI folder there if needed. > 4. Optional: After flashing the DMG image to the USB drive, there will be free/unallocated space remaining on the USB drive. Use Disk Management to create a new FAT32 partition and place your EFI folder there if needed.
> [!NOTE] > [!NOTE]
> By default, artifacts are kept for 7 days. You can change this in the workflow YAML file. > By default, artifacts are kept for 7 days. You can change this in the workflow YAML file.
+398 -162
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (c) 2024–2025, LongQT-sea # Copyright (c) 2024–2025, LongQT-sea
# mkmaciso - the ultimate macOS utility for creating macOS installer ISO and DMG images # mkmaciso – the ultimate tool for creating macOS installer ISO and DMG images
# Run with -h or --help to show usage. # Run with -h or --help to show usage.
@@ -22,8 +22,15 @@
# - Can also be used with virtual machines, but must be attached as a virtual hard disk. # - Can also be used with virtual machines, but must be attached as a virtual hard disk.
# - Most VMM require convert the .dmg image to a compatible virtual disk format using qemu-img, # - Most VMM require convert the .dmg image to a compatible virtual disk format using qemu-img,
# e.g. convert to .vhd for Hyper-V or .vmdk for VMware. QEMU can use raw disk image without conversion. # e.g. convert to .vhd for Hyper-V or .vmdk for VMware. QEMU can use raw disk image without conversion.
#
# For easier use and distribution, the final DMG image will have '.iso' appended to its file name.
# Rufus no longer require switching to "All files" to saw the DMG image in Explorer.
# Also fix "qemu-img: Could not locate UDIF trailer in dmg file" error.
#
# While the script is compatible with Apple silicon Macs, it’s still recommended to run it on an x86_64 Intel Mac for optimal results.
set -e # Exit on error set -e # Exit on error
#set -x # Debug
# Official Apple download URLs for macOS 10.7-10.12 (except 10.9) # Official Apple download URLs for macOS 10.7-10.12 (except 10.9)
# https://support.apple.com/en-hk/102662#browser # https://support.apple.com/en-hk/102662#browser
@@ -33,6 +40,12 @@ YOSEMITE_URL="http://updates-http.cdn-apple.com/2019/cert/061-41343-20191023-024
EL_CAPITAN_URL="http://updates-http.cdn-apple.com/2019/cert/061-41424-20191024-218af9ec-cf50-4516-9011-228c78eda3d2/InstallMacOSX.dmg" EL_CAPITAN_URL="http://updates-http.cdn-apple.com/2019/cert/061-41424-20191024-218af9ec-cf50-4516-9011-228c78eda3d2/InstallMacOSX.dmg"
SIERRA_URL="http://updates-http.cdn-apple.com/2019/cert/061-39476-20191023-48f365f4-0015-4c41-9f44-39d3d2aca067/InstallOS.dmg" SIERRA_URL="http://updates-http.cdn-apple.com/2019/cert/061-39476-20191023-48f365f4-0015-4c41-9f44-39d3d2aca067/InstallOS.dmg"
# Official Apple download URLs for macOS 10.13-10.15
# https://swscan.apple.com/content/catalogs/others/index-15-14-13-12-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog
CATALINA_BASE_URL=https://swcdn.apple.com/content/downloads/26/37/001-68446/r1dbqtmf3mtpikjnd04cq31p4jk91dceh8/
MOJAVE_BASE_URL=https://swcdn.apple.com/content/downloads/17/32/061-26589-A_8GJTCGY9PC/25fhcu905eta7wau7aoafu8rvdm7k1j4el/
HIGH_SIERRA_BASE_URL=https://swcdn.apple.com/content/downloads/06/50/041-91758-A_M8T44LH2AW/b5r4og05fhbgatve4agwy4kgkzv07mdid9/
# Default parameters # Default parameters
VERSION="${1:-}" VERSION="${1:-}"
IMAGE_FORMAT="${2:-}" IMAGE_FORMAT="${2:-}"
@@ -41,6 +54,9 @@ RETRIES_COUNT=10
FINAL_OUTPUT_PATH="" FINAL_OUTPUT_PATH=""
DISK_ID="" DISK_ID=""
# Get CPU architecture
CPU_ARCH=$(uname -m)
# Color codes for output # Color codes for output
RED='\033[0;31m' RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
@@ -54,15 +70,15 @@ NC='\033[0m' # No Color
# Helper functions # Helper functions
log_info() { log_info() {
echo -e "${GREEN}[INFO]${NC} $1" echo -e "${GREEN}$(date +'%H:%M:%S') [INFO]${NC} $1"
} }
log_warn() { log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1" echo -e "${YELLOW}$(date +'%H:%M:%S') [WARN]${NC} $1"
} }
log_error() { log_error() {
echo -e "${RED}[ERROR]${NC} $1" echo -e "${RED}$(date +'%H:%M:%S') [ERROR]${NC} $1"
} }
check_sudo_access() { check_sudo_access() {
@@ -77,12 +93,17 @@ check_sudo_access() {
check_disk_space() { check_disk_space() {
local required_gb=40 local required_gb=40
local threshold_gb=15
local available=$(df -g . | awk 'NR==2 {print $4}') local available=$(df -g . | awk 'NR==2 {print $4}')
if [ "$available" -lt "$required_gb" ]; then if [ "$available" -lt "$threshold_gb" ]; then
log_error "CRITICAL: Only ${available} GB available, (${required_gb} GB or more recommended"
log_error "Cannot continue due to low disk space"
exit 1
elif [ "$available" -lt "$required_gb" ]; then
log_error "WARNING: Low disk space - ${available} GB available, ${required_gb} GB or more recommended" log_error "WARNING: Low disk space - ${available} GB available, ${required_gb} GB or more recommended"
log_warn "" echo ""
log_warn "Continue? (Y/n - auto-yes in 10 seconds): " echo -ne "${YELLOW}[WARN]${NC} Continue? (Y/n - auto-yes in 10 seconds): "
read -t 10 answer || answer="y" read -t 10 answer || answer="y"
case "$answer" in case "$answer" in
[Nn]|[Nn][Oo]) [Nn]|[Nn][Oo])
@@ -91,6 +112,7 @@ check_disk_space() {
;; ;;
*) *)
log_info "Continuing..." log_info "Continuing..."
echo ""
;; ;;
esac esac
fi fi
@@ -103,7 +125,7 @@ detach_disk() {
for attempt in $(seq 1 "$RETRIES_COUNT"); do for attempt in $(seq 1 "$RETRIES_COUNT"); do
log_info "Detach attempt $attempt of $RETRIES_COUNT..." log_info "Detach attempt $attempt of $RETRIES_COUNT..."
if sync && sleep 5 && hdiutil detach "$disk" 2>/dev/null || hdiutil detach "$disk" -force 2>/dev/null; then if sync && sleep 5 && hdiutil detach -quiet "$disk" || hdiutil detach -quiet "$disk" -force; then
log_info "Disk detached successfully" log_info "Disk detached successfully"
return 0 return 0
fi fi
@@ -122,6 +144,10 @@ cleanup() {
[ -d "$mnt" ] && detach_disk "$mnt" 2>/dev/null || true [ -d "$mnt" ] && detach_disk "$mnt" 2>/dev/null || true
done done
if [ -n "${DISK_ID:-}" ]; then
detach_disk "$DISK_ID"
fi
log_info "Cleaning up temporary files..." log_info "Cleaning up temporary files..."
sudo rm -rf "$WORK_DIR" sudo rm -rf "$WORK_DIR"
fi fi
@@ -533,7 +559,7 @@ download_legacy_macos() {
;; ;;
"10.9") "10.9")
download_mavericks download_mavericks
return return $?
;; ;;
"10.10") "10.10")
download_url="$YOSEMITE_URL" download_url="$YOSEMITE_URL"
@@ -610,21 +636,21 @@ k=$key")
install_legacy_app() { install_legacy_app() {
local version_num="$1" local version_num="$1"
local dmg_file="$2" local dmg_file="$2"
local cpu_arch=$(uname -m)
log_info "Installing macOS $(get_codename $version_num) installer to /Applications..." log_info "Installing macOS $(get_codename $version_num) installer to /Applications..."
# Check if version is in the legacy list
if [[ "$version_num" =~ ^(10\.7|10\.8|10\.10|10\.11|10\.12)$ ]]; then if [[ "$version_num" =~ ^(10\.7|10\.8|10\.10|10\.11|10\.12)$ ]]; then
# Mount the DMG # Mount the downloaded DMG image
hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/installer_mnt" "$dmg_file" hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/downloaded_dmg_mnt" "$dmg_file"
# Manual installation process for Apple silicon # Manual installation process for Apple silicon.
if [ "$cpu_arch" == "arm64" ]; then # The 'Install OSX/macOS.app' produced by manual install is not suitable
# for creating a bootable USB using 'createinstallmedia'.
if [ "$CPU_ARCH" == "arm64" ]; then
log_info "Apple silicon detected, using manual installation..." log_info "Apple silicon detected, using manual installation..."
# Extract the package # Extract the package
pkgutil --expand "$WORK_DIR/installer_mnt"/*.pkg "$WORK_DIR/pkg_extracted" pkgutil --expand "$WORK_DIR/downloaded_dmg_mnt"/*.pkg "$WORK_DIR/pkg_extracted"
# Find the inner package directory (InstallMacOSX.pkg) # Find the inner package directory (InstallMacOSX.pkg)
local inner_pkg=$(ls -d "$WORK_DIR/pkg_extracted"/*.pkg 2>/dev/null | head -1) local inner_pkg=$(ls -d "$WORK_DIR/pkg_extracted"/*.pkg 2>/dev/null | head -1)
@@ -636,17 +662,19 @@ install_legacy_app() {
# Copy InstallESD.dmg # Copy InstallESD.dmg
local app_path="/Applications/$(get_installer_app_name $version_num).app" local app_path="/Applications/$(get_installer_app_name $version_num).app"
sudo cp "$inner_pkg/InstallESD.dmg" "$app_path/Contents/SharedSupport/InstallESD.dmg" sudo ditto "$inner_pkg/InstallESD.dmg" "$app_path/Contents/SharedSupport/InstallESD.dmg"
sudo chown root:wheel "$app_path/Contents/SharedSupport/InstallESD.dmg" sudo chown root:wheel "$app_path/Contents/SharedSupport/InstallESD.dmg"
log_info "Installed $(get_installer_app_name $version_num) to /Applications" log_info "Installed $(get_installer_app_name $version_num) to /Applications"
log_warn "Note: This $(get_installer_app_name $version_num) is not suitable for creating a bootable USB using 'createinstallmedia'"
else else
# Standard installation for Intel Macs # Standard installation for Intel Macs
sudo installer -pkg "$WORK_DIR/installer_mnt"/*.pkg -target / && \ sudo installer -pkg "$WORK_DIR/downloaded_dmg_mnt"/*.pkg -target / && \
log_info "Installed $(get_installer_app_name $version_num) to /Applications" log_info "Installed $(get_installer_app_name $version_num) to /Applications"
fi fi
sync && detach_disk "$WORK_DIR/installer_mnt" sync && detach_disk "$WORK_DIR/downloaded_dmg_mnt"
elif [ "$version_num" == "10.9" ]; then elif [ "$version_num" == "10.9" ]; then
# Check if InstallESD.dmg exists # Check if InstallESD.dmg exists
@@ -671,38 +699,154 @@ install_legacy_app() {
fi fi
} }
# Reference: https://www.insanelymac.com/forum/topic/338810-create-legit-copy-of-macos-from-apple-catalog/
direct_download_10_13_10_15() {
local version_num="$1"
local base_url=""
local version_name=""
# Determine base URL and version name
case "$version_num" in
"10.13")
base_url="$HIGH_SIERRA_BASE_URL"
version_name="High Sierra"
;;
"10.14")
base_url="$MOJAVE_BASE_URL"
version_name="Mojave"
;;
"10.15")
base_url="$CATALINA_BASE_URL"
version_name="Catalina"
;;
*)
return 1
;;
esac
log_info "Downloading macOS $(get_codename $version_num) installer using direct Apple URLs..."
echo ""
# Required files for 10.13-10.15
local files=(
"BaseSystem.dmg"
"BaseSystem.chunklist"
"InstallInfo.plist"
"InstallESDDmg.pkg"
"AppleDiagnostics.dmg"
"AppleDiagnostics.chunklist"
)
# Download all required files
for filename in "${files[@]}"; do
log_info "Downloading ${filename}..."
curl --retry 5 --retry-all-errors --max-time 1800 --connect-timeout 10 --progress-bar \
-L "${base_url}${filename}" -o "$WORK_DIR/${filename}"
if [ $? -ne 0 ]; then
log_error "Failed to download ${filename}"
return 1
fi
done
echo ""
log_info "All files downloaded. Building macOS $(get_codename $version_num) installer app..."
# Mount BaseSystem.dmg to extract the app
hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/BaseSystem_mnt" "$WORK_DIR/BaseSystem.dmg"
# Copy installer app to /Applications
local installer_app="$WORK_DIR/BaseSystem_mnt/$(get_installer_app_name $version_num).app"
sudo cp -Rp "$installer_app" "/Applications/"
# Create SharedSupport directory
local shared_support="/Applications/$(get_installer_app_name $version_num).app/Contents/SharedSupport"
sudo mkdir -p "$shared_support"
# Rename InstallESDDmg.pkg to InstallESD.dmg
mv "$WORK_DIR/InstallESDDmg.pkg" "$WORK_DIR/InstallESD.dmg"
# Fix InstallInfo.plist
sed -e "s/InstallESDDmg\.pkg/InstallESD.dmg/" \
-e "s/pkg\.InstallESDDmg/dmg.InstallESD/" \
-e "/InstallESD\.dmg/{n;N;N;N;d;}" \
"$WORK_DIR/InstallInfo.plist" > "$WORK_DIR/InstallInfo_fixed.plist"
# Copy files to SharedSupport
sudo cp -Rp "$WORK_DIR/BaseSystem.dmg" "$shared_support/"
sudo cp -Rp "$WORK_DIR/BaseSystem.chunklist" "$shared_support/"
sudo cp -Rp "$WORK_DIR/InstallInfo_fixed.plist" "$shared_support/InstallInfo.plist"
sudo cp -Rp "$WORK_DIR/InstallESD.dmg" "$shared_support/"
sudo cp -Rp "$WORK_DIR/AppleDiagnostics.dmg" "$shared_support/"
sudo cp -Rp "$WORK_DIR/AppleDiagnostics.chunklist" "$shared_support/"
# Set proper ownership
sudo chown -R root:wheel "$shared_support"
# Resign createinstallmedia and remove quarantine tag for Apple Silicon
if [ "$CPU_ARCH" == "arm64" ] && [[ "$version_num" =~ ^10\.1[3-5]$ ]]; then
sudo codesign -s - -f "/Applications/$(get_installer_app_name $version_num).app/Contents/Resources/createinstallmedia"
sudo xattr -r -d com.apple.quarantine "/Applications/$(get_installer_app_name $version_num).app"
fi
# Detach BaseSystem.dmg
sync && sleep 10 && detach_disk "$WORK_DIR/BaseSystem_mnt"
log_info "Successfully installed $(get_installer_app_name $version_num) to /Applications"
return 0
}
download_modern_macos() { download_modern_macos() {
local version_num="$1" local version_num="$1"
version_name=$(get_codename $version_num) version_name=$(get_codename $version_num)
version_name="${version_name/_/ }" version_name="${version_name/_/ }"
# Get CPU architecture
local cpu_arch=$(uname -m)
# Get current macOS kernel version # Get current macOS kernel version
local kernel_version=$(uname -r | cut -d'.' -f1) local kernel_version=$(uname -r | cut -d'.' -f1)
# Extract major version from version_num for comparison # Use direct download when softwareupdate is not available
local requested_major_version if [[ "$version_num" =~ ^10\.1[345]$ ]]; then
if [[ "$version_num" =~ ^10\.([0-9]+)$ ]]; then # For Apple silicon: always use direct download for 10.13-10.15
requested_major_version="${version_num}" if [ "$CPU_ARCH" == "arm64" ]; then
else log_info "Apple silicon detected"
requested_major_version="$version_num" echo ""
# Show warning on Apple silicon
log_warn "╔═════════════════════════════════════════════════════════════════╗"
log_warn "║ Apple silicon Limitation ║"
log_warn "╠═════════════════════════════════════════════════════════════════╣"
log_warn "║ On Apple silicon, softwareupdate cannot download macOS versions ║"
log_warn "║ older than the one that originally shipped with your device. ║"
log_warn "╚═════════════════════════════════════════════════════════════════╝"
echo ""
direct_download_10_13_10_15 "$version_num"
return $?
fi
# For Intel: use direct download if running kernel < 20 (pre-Big Sur)
if [ "$CPU_ARCH" == "x86_64" ]; then
log_info "Intel CPU detected"
if [ "$kernel_version" -lt 20 ]; then
log_info "This Mac is running a version older than Big Sur, will attempt direct download"
direct_download_10_13_10_15 "$version_num"
return $?
fi
fi
fi fi
# Check CPU architecture compatibility # For macOS 11+ or when running Big Sur+, use softwareupdate
if [ "$cpu_arch" == "x86_64" ]; then # Check CPU architecture compatibility for softwareupdate
if [ "$CPU_ARCH" == "x86_64" ]; then
log_info "Intel CPU detected" log_info "Intel CPU detected"
# Intel Macs require macOS 11 or newer for softwareupdate # Intel Macs require macOS 11 or newer for softwareupdate
# Check if current system is at least macOS 11 (kernel 20)
if [ "$kernel_version" -lt 20 ]; then if [ "$kernel_version" -lt 20 ]; then
log_error "Intel Macs must be running macOS 11 (Big Sur) or newer to download macOS using softwareupdate" log_error "Intel Macs must be running macOS 11 (Big Sur) or newer to download macOS using softwareupdate"
log_error "Please upgrade your macOS to version 11 or newer" log_error "Please upgrade your macOS to version 11 or newer"
return 1 return 1
fi fi
elif [ "$cpu_arch" == "arm64" ]; then elif [ "$CPU_ARCH" == "arm64" ]; then
log_info "Apple silicon detected" log_info "Apple silicon detected"
# Show warning on Apple silicon # Show warning on Apple silicon
@@ -712,14 +856,6 @@ download_modern_macos() {
log_warn "║ On Apple silicon, softwareupdate cannot download macOS versions ║" log_warn "║ On Apple silicon, softwareupdate cannot download macOS versions ║"
log_warn "║ older than the one that originally shipped with your device. ║" log_warn "║ older than the one that originally shipped with your device. ║"
log_warn "╚═════════════════════════════════════════════════════════════════╝" log_warn "╚═════════════════════════════════════════════════════════════════╝"
# Check if requested version is older than macOS 11
if [[ "$version_num" =~ ^10\. ]]; then
log_error "Apple silicon Macs cannot download macOS 10.13 - 10.15 using softwareupdate."
log_error "Please use gibMacOS to download macOS $version_name, or request macOS 11 (Big Sur) or a newer version."
log_error "Requested version: $version_name"
return 1
fi
fi fi
log_info "Fetching available macOS installers..." log_info "Fetching available macOS installers..."
@@ -761,52 +897,42 @@ download_modern_macos() {
done done
} }
create_iso_10_7_10_8() { create_iso_dmg_10_7_10_8() {
local installer_path="$1" local installer_path="$1"
local output_file="$2" local output_file="$2"
local volume_name="$3" local volume_name="$3"
local version_num="$4" local version_num="$4"
local image_format=$(echo "$IMAGE_FORMAT" | tr '[:lower:]' '[:upper:]')
log_info "Creating macOS $(get_codename $version_num) ISO image..." log_info "Creating macOS $(get_codename $version_num) $image_format image..."
echo ""
# Mount InstallESD.dmg for version extraction
hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/InstallESD_mnt" "$installer_path/Contents/SharedSupport/InstallESD.dmg"
# Extract the exact version number and append it to the file name
exact_version_number=$(defaults read "$WORK_DIR/InstallESD_mnt/System/Library/CoreServices/SystemVersion" ProductVersion)
FINAL_OUTPUT_PATH="${output_file%.iso}_$exact_version_number.iso"
# Unmount
sync && detach_disk "$WORK_DIR/InstallESD_mnt"
# Create ISO directly from InstallESD.dmg
sudo hdiutil makehybrid -ov -hfs -udf -default-volume-name "$volume_name" \
"$installer_path/Contents/SharedSupport/InstallESD.dmg" -o "$FINAL_OUTPUT_PATH"
}
create_dmg_10_7_10_8() {
local installer_path="$1"
local output_file="$2"
local volume_name="$3"
local version_num="$4"
log_info "Creating macOS $(get_codename $version_num) DMG image..."
echo "" echo ""
# Mount InstallESD.dmg # Mount InstallESD.dmg
hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/InstallESD_mnt" "$installer_path/Contents/SharedSupport/InstallESD.dmg" hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/InstallESD_mnt" "$installer_path/Contents/SharedSupport/InstallESD.dmg"
# Extract the exact version number and append it to the file name # Extract the exact version number and append it to the file name
exact_version_number=$(defaults read "$WORK_DIR/InstallESD_mnt/System/Library/CoreServices/SystemVersion" ProductVersion) local exact_version_number=$(defaults read "$WORK_DIR/InstallESD_mnt/System/Library/CoreServices/SystemVersion" ProductVersion)
FINAL_OUTPUT_PATH="${output_file%.dmg}_$exact_version_number.dmg" FINAL_OUTPUT_PATH="${output_file%.${IMAGE_FORMAT}}_$exact_version_number.${IMAGE_FORMAT}"
# Create DMG with GUID Partition Table from mounted InstallESD.dmg # Create final image
sudo hdiutil create -layout GPTSPUD -format UDRW -ov \ if [ "$IMAGE_FORMAT" == "dmg" ]; then
-volname "$volume_name" -srcdir "$WORK_DIR/InstallESD_mnt" "$FINAL_OUTPUT_PATH" # Create DMG with GUID Partition Table from mounted InstallESD.dmg
sudo hdiutil create -quiet -layout GPTSPUD -format UDRW -ov -volname "$volume_name" -srcdir "$WORK_DIR/InstallESD_mnt" "$FINAL_OUTPUT_PATH"
# Unmount # Append .iso extension
sync && detach_disk "$WORK_DIR/InstallESD_mnt" mv -f "$FINAL_OUTPUT_PATH" "${FINAL_OUTPUT_PATH}.iso"
# Unmount
sync && detach_disk "$WORK_DIR/InstallESD_mnt"
FINAL_OUTPUT_PATH="${FINAL_OUTPUT_PATH}.iso"
else
# Unmount
sync && detach_disk "$WORK_DIR/InstallESD_mnt"
log_info "Converting to ISO format..."
sudo hdiutil makehybrid -quiet -ov -hfs -udf -default-volume-name "$volume_name" "$installer_path/Contents/SharedSupport/InstallESD.dmg" -o "$FINAL_OUTPUT_PATH"
fi
} }
create_iso_10_9_10_11() { create_iso_10_9_10_11() {
@@ -816,7 +942,6 @@ create_iso_10_9_10_11() {
local version_num="$4" local version_num="$4"
log_info "Creating macOS $(get_codename $version_num) ISO image..." log_info "Creating macOS $(get_codename $version_num) ISO image..."
echo ""
# Mount InstallESD.dmg # Mount InstallESD.dmg
local installesd_path="$installer_path/Contents/SharedSupport/InstallESD.dmg" local installesd_path="$installer_path/Contents/SharedSupport/InstallESD.dmg"
@@ -824,13 +949,13 @@ create_iso_10_9_10_11() {
hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/InstallESD_mnt" "$installesd_path" hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/InstallESD_mnt" "$installesd_path"
# Convert BaseSystem.dmg # Convert BaseSystem.dmg
hdiutil convert "$WORK_DIR/InstallESD_mnt/BaseSystem.dmg" -format UDRW -o "$WORK_DIR/BaseSystem" >/dev/null 2>&1 hdiutil convert -quiet "$WORK_DIR/InstallESD_mnt/BaseSystem.dmg" -format UDRW -o "$WORK_DIR/BaseSystem_converted.dmg" >/dev/null 2>&1
# Resize # Increase size
sudo hdiutil resize -size 8g "$WORK_DIR/BaseSystem.dmg" sudo hdiutil resize -size 7.1g "$WORK_DIR/BaseSystem_converted.dmg"
# Mount the converted DMG # Mount the converted DMG
DISK_ID=$(hdiutil attach -nobrowse -mountpoint "$WORK_DIR/BaseSystem_mnt" "$WORK_DIR/BaseSystem.dmg" | grep -o '/dev/disk[0-9]*' | head -1) DISK_ID=$(hdiutil attach -nobrowse -mountpoint "$WORK_DIR/BaseSystem_mnt" "$WORK_DIR/BaseSystem_converted.dmg" | grep -o '/dev/disk[0-9]*' | head -1)
# Remove Packages symlink and copy actual Packages # Remove Packages symlink and copy actual Packages
rm "$WORK_DIR/BaseSystem_mnt/System/Installation/Packages" rm "$WORK_DIR/BaseSystem_mnt/System/Installation/Packages"
@@ -847,7 +972,7 @@ create_iso_10_9_10_11() {
fi fi
# Extract the exact version number and append it to the file name # Extract the exact version number and append it to the file name
exact_version_number=$(defaults read "$WORK_DIR/BaseSystem_mnt/System/Library/CoreServices/SystemVersion" ProductVersion) local exact_version_number=$(defaults read "$WORK_DIR/BaseSystem_mnt/System/Library/CoreServices/SystemVersion" ProductVersion)
FINAL_OUTPUT_PATH="${output_file%.iso}_$exact_version_number.iso" FINAL_OUTPUT_PATH="${output_file%.iso}_$exact_version_number.iso"
# Unmount # Unmount
@@ -855,11 +980,12 @@ create_iso_10_9_10_11() {
detach_disk "$DISK_ID" && DISK_ID="" detach_disk "$DISK_ID" && DISK_ID=""
# Create ISO # Create ISO
sudo hdiutil makehybrid -ov -hfs -udf -default-volume-name "$volume_name" \ log_info "Converting to ISO format..."
"$WORK_DIR/BaseSystem.dmg" -o "$FINAL_OUTPUT_PATH" sudo hdiutil makehybrid -quiet -ov -hfs -udf -default-volume-name "$volume_name" \
"$WORK_DIR/BaseSystem_converted.dmg" -o "$FINAL_OUTPUT_PATH"
} }
create_dmg_10_9() { create_dmg_10_9_to_10_12_alt_method() {
local installer_path="$1" local installer_path="$1"
local output_file="$2" local output_file="$2"
local volume_name="$3" local volume_name="$3"
@@ -873,21 +999,41 @@ create_dmg_10_9() {
hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/InstallESD_mnt" "$installesd_path" hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/InstallESD_mnt" "$installesd_path"
# Attach BaseSystem.dmg if [[ "$version_num" =~ ^(10\.9|10\.10)$ ]]; then
BaseSystem_DISK_ID=$(hdiutil attach "$WORK_DIR/InstallESD_mnt/BaseSystem.dmg" -nomount | grep -o '/dev/disk[0-9]*' | head -1) # Attach BaseSystem.dmg
BaseSystem_DISK_ID=$(hdiutil attach "$WORK_DIR/InstallESD_mnt/BaseSystem.dmg" -nomount | grep -o '/dev/disk[0-9]*' | head -1)
# Create a DMG with GUID Partition Table and attach it # Create a DMG with GUID Partition Table and attach it
hdiutil create -ov -fs hfs+ -size 1.4g "$WORK_DIR/installer_gpt.dmg" >/dev/null 2>&1 hdiutil create -quiet -ov -fs hfs+ -size 1400m "$WORK_DIR/installer_gpt.dmg"
DISK_ID=$(hdiutil attach "$WORK_DIR/installer_gpt.dmg" -nomount | grep -o '/dev/disk[0-9]*' | head -1) DISK_ID=$(hdiutil attach "$WORK_DIR/installer_gpt.dmg" -nomount | grep -o '/dev/disk[0-9]*' | head -1)
# Write the bootable recovery partition to the first partition on the DMG image # Write the bootable recovery partition to the first partition on the DMG image
sudo dd if="${BaseSystem_DISK_ID}s2" of="${DISK_ID}s1" bs=1m && detach_disk "$BaseSystem_DISK_ID" sudo dd if="${BaseSystem_DISK_ID}s2" of="${DISK_ID}s1" bs=1m && detach_disk "$BaseSystem_DISK_ID"
# Unmount # Unmount
detach_disk "$DISK_ID" && DISK_ID="" detach_disk "$DISK_ID" && DISK_ID=""
# Increase size # Increase size
sudo hdiutil resize -size 8g "$WORK_DIR/installer_gpt.dmg" sudo hdiutil resize -size 7g "$WORK_DIR/installer_gpt.dmg"
elif [[ "$version_num" =~ ^(10\.11|10\.12)$ ]]; then
local dmg_size
case "$version_num" in
"10.11")
dmg_size="7.1"
;;
*)
dmg_size="5.9"
;;
esac
# El Capitan and Sierra BaseSystem.dmg already use a GUID Partition Table
# Convert BaseSystem.dmg
hdiutil convert -quiet "$WORK_DIR/InstallESD_mnt/BaseSystem.dmg" -format UDRW -o "$WORK_DIR/installer_gpt.dmg"
# Increase size
sudo hdiutil resize -size ${dmg_size}g "$WORK_DIR/installer_gpt.dmg"
fi
# Mount DMG image and change volume name # Mount DMG image and change volume name
DISK_ID=$(hdiutil attach -nobrowse -mountpoint "$WORK_DIR/installer_mnt" "$WORK_DIR/installer_gpt.dmg" | grep -o '/dev/disk[0-9]*' | head -1) DISK_ID=$(hdiutil attach -nobrowse -mountpoint "$WORK_DIR/installer_mnt" "$WORK_DIR/installer_gpt.dmg" | grep -o '/dev/disk[0-9]*' | head -1)
@@ -895,15 +1041,15 @@ create_dmg_10_9() {
# Remove Packages symlink and copy actual Packages # Remove Packages symlink and copy actual Packages
rm "$WORK_DIR/installer_mnt/System/Installation/Packages" rm "$WORK_DIR/installer_mnt/System/Installation/Packages"
cp -R "$WORK_DIR/InstallESD_mnt/Packages" "$WORK_DIR/installer_mnt/System/Installation/" ditto "$WORK_DIR/InstallESD_mnt/Packages" "$WORK_DIR/installer_mnt/System/Installation/Packages"
# Copy required files # Copy required files
cp "$WORK_DIR/InstallESD_mnt/BaseSystem.dmg" "$WORK_DIR/installer_mnt/" cp -R "$WORK_DIR/InstallESD_mnt/BaseSystem.dmg" "$WORK_DIR/installer_mnt/"
cp "$WORK_DIR/InstallESD_mnt/BaseSystem.chunklist" "$WORK_DIR/installer_mnt/" cp -R "$WORK_DIR/InstallESD_mnt/BaseSystem.chunklist" "$WORK_DIR/installer_mnt/"
# Extract the exact version number and append it to the file name # Extract the exact version number and append it to the file name
exact_version_number=$(defaults read "$WORK_DIR/installer_mnt/System/Library/CoreServices/SystemVersion" ProductVersion) local exact_version_number=$(defaults read "$WORK_DIR/installer_mnt/System/Library/CoreServices/SystemVersion" ProductVersion)
FINAL_OUTPUT_PATH="${output_file%.dmg}_$exact_version_number.dmg" FINAL_OUTPUT_PATH="${output_file%.dmg}_$exact_version_number.dmg.iso"
sync && sleep 5 sync && sleep 5
@@ -916,19 +1062,102 @@ create_dmg_10_9() {
sudo hdiutil resize -size min "$WORK_DIR/installer_gpt.dmg" sudo hdiutil resize -size min "$WORK_DIR/installer_gpt.dmg"
# Move to output # Move to output
log_info "Move to $FINAL_OUTPUT_PATH"
mv -f "$WORK_DIR/installer_gpt.dmg" "$FINAL_OUTPUT_PATH" mv -f "$WORK_DIR/installer_gpt.dmg" "$FINAL_OUTPUT_PATH"
} }
create_iso_dmg_10_15_alt_method() {
local installer_path="$1"
local output_file="$2"
local volume_name="$3"
local version_num="$4"
local image_format=$(echo "$IMAGE_FORMAT" | tr '[:lower:]' '[:upper:]')
log_info "Apple Silicon detected. Using alternative method for Catalina instead of 'createinstallmedia'"
echo ""
log_info "Creating macOS $(get_codename $version_num) $image_format image..."
echo ""
# Mount InstallESD.dmg
local installesd_path="$installer_path/Contents/SharedSupport/InstallESD.dmg"
hdiutil attach -nobrowse -quiet -mountpoint "$WORK_DIR/InstallESD_mnt" "$installesd_path"
# Convert BaseSystem.dmg
local basesystem_path="$installer_path/Contents/SharedSupport/BaseSystem.dmg"
hdiutil convert -quiet "$basesystem_path" -format UDRW -o "$WORK_DIR/BaseSystem_converted.dmg"
# Increase size
sudo hdiutil resize -size 9g "$WORK_DIR/BaseSystem_converted.dmg"
# Mount the converted DMG
DISK_ID=$(hdiutil attach -nobrowse -mountpoint "$WORK_DIR/BaseSystem_mnt" "$WORK_DIR/BaseSystem_converted.dmg" | grep -o '/dev/disk[0-9]*' | head -1)
diskutil rename "${DISK_ID}s1" "$volume_name"
# Remove the stub installer app
rm -rf "$WORK_DIR/BaseSystem_mnt/$(get_installer_app_name $version_num).app"
# Copy actual installer app from /Applications
cp -R "$installer_path" "$WORK_DIR/BaseSystem_mnt/"
# Extract the exact version number and append it to the file name
local exact_version_number=$(defaults read "$WORK_DIR/BaseSystem_mnt/System/Library/CoreServices/SystemVersion" ProductVersion)
if [ "$IMAGE_FORMAT" == "dmg" ]; then
FINAL_OUTPUT_PATH="${output_file%.dmg}_$exact_version_number.dmg.iso"
else
FINAL_OUTPUT_PATH="${output_file%.iso}_$exact_version_number.iso"
fi
# Unmount
detach_disk "$WORK_DIR/InstallESD_mnt"
detach_disk "$DISK_ID" && DISK_ID=""
# Create final image
if [ "$IMAGE_FORMAT" == "dmg" ]; then
# Optimize DMG file size
log_info "Optimizing DMG file size..."
sudo hdiutil resize -size min "$WORK_DIR/BaseSystem_converted.dmg"
# Move to output
log_info "Move to $FINAL_OUTPUT_PATH"
mv -f "$WORK_DIR/BaseSystem_converted.dmg" "$FINAL_OUTPUT_PATH"
else
log_info "Converting to ISO format..."
sudo hdiutil makehybrid -quiet -ov -hfs -udf -default-volume-name "$volume_name" "$WORK_DIR/BaseSystem_converted.dmg" -o "$FINAL_OUTPUT_PATH"
fi
}
create_iso_10_12_and_later() { create_iso_10_12_and_later() {
local installer_path="$1" local installer_path="$1"
local output_file="$2" local output_file="$2"
local version_num="$3" local version_num="$3"
# macOS Sierra and Catalina 'createinstallmedia' fails when running on Apple silicon
# Redirecting to alternative method
if [[ "$CPU_ARCH" == "arm64" ]]; then
if [[ "$version_num" == "10.12" ]]; then
create_iso_10_9_10_11 \
"$installer_path" \
"$output_file" \
"$(get_installer_app_name "$version_num")" \
"$version_num"
return $?
elif [[ "$version_num" == "10.15" ]]; then
create_iso_dmg_10_15_alt_method \
"$installer_path" \
"$output_file" \
"$(get_installer_app_name "$version_num")" \
"$version_num"
return $?
fi
fi
log_info "Creating macOS $(get_codename $version_num) ISO image..." log_info "Creating macOS $(get_codename $version_num) ISO image..."
echo "" echo ""
# Create sparse image # Create sparse image
hdiutil create -size 20g -volname "$(get_codename $version_num)_iso" -fs HFS+ -type SPARSE -attach "$WORK_DIR/installer.sparseimage" >/dev/null 2>&1 hdiutil create -quiet -size 20g -volname "$(get_codename $version_num)_iso" -fs HFS+ -type SPARSE -attach "$WORK_DIR/installer.sparseimage"
DISK_ID=$(diskutil list | grep $(get_codename $version_num)_iso | head -1 | awk '{print $NF}' | sed 's/s[0-9]*$//') DISK_ID=$(diskutil list | grep $(get_codename $version_num)_iso | head -1 | awk '{print $NF}' | sed 's/s[0-9]*$//')
# Prepare createinstallmedia command # Prepare createinstallmedia command
@@ -948,7 +1177,7 @@ create_iso_10_12_and_later() {
sync && sleep 5 sync && sleep 5
# Extract the exact version number and append it to the file name # Extract the exact version number and append it to the file name
exact_version_number=$(defaults read "/Volumes/$(get_installer_app_name "$version_num")/System/Library/CoreServices/SystemVersion" ProductVersion) local exact_version_number=$(defaults read "/Volumes/$(get_installer_app_name "$version_num")/System/Library/CoreServices/SystemVersion" ProductVersion)
FINAL_OUTPUT_PATH="${output_file%.iso}_$exact_version_number.iso" FINAL_OUTPUT_PATH="${output_file%.iso}_$exact_version_number.iso"
# Restore Info.plist # Restore Info.plist
@@ -962,13 +1191,34 @@ create_iso_10_12_and_later() {
# Create ISO from sparse image # Create ISO from sparse image
log_info "Converting to ISO format..." log_info "Converting to ISO format..."
sudo hdiutil makehybrid -ov -hfs -udf "$WORK_DIR/installer.sparseimage" -o "$FINAL_OUTPUT_PATH" sudo hdiutil makehybrid -quiet -ov -hfs -udf "$WORK_DIR/installer.sparseimage" -o "$FINAL_OUTPUT_PATH"
} }
create_dmg_10_10_and_later() { create_dmg_10_10_and_later() {
local installer_path="$1" local installer_path="$1"
local output_file="$2" local output_file="$2"
local version_num="$3" local version_num="$3"
# macOS Catalina, Sierra, El Capitan, and Yosemite 'createinstallmedia' fails when running on Apple silicon
# Redirecting to alternative method
if [[ "$CPU_ARCH" == "arm64" ]]; then
if [[ "$version_num" =~ ^10\.1[012]$ ]]; then
create_dmg_10_9_to_10_12_alt_method \
"$installer_path" \
"$output_file" \
"$(get_installer_app_name "$version_num")" \
"$version_num"
return $?
elif [[ "$version_num" = "10.15" ]]; then
create_iso_dmg_10_15_alt_method \
"$installer_path" \
"$output_file" \
"$(get_installer_app_name "$version_num")" \
"$version_num"
return $?
fi
fi
log_info "Creating macOS $(get_codename $version_num) DMG image..." log_info "Creating macOS $(get_codename $version_num) DMG image..."
echo "" echo ""
@@ -993,7 +1243,7 @@ create_dmg_10_10_and_later() {
esac esac
# Create DMG disk image # Create DMG disk image
hdiutil create -size $dmg_size -volname "$(get_codename $version_num)_dmg" -fs HFS+ -type UDIF -attach "$WORK_DIR/installer.dmg" >/dev/null 2>&1 hdiutil create -quiet -size $dmg_size -volname "$(get_codename $version_num)_dmg" -fs HFS+ -type UDIF -attach "$WORK_DIR/installer.dmg"
DISK_ID=$(diskutil list | grep $(get_codename $version_num)_dmg | head -1 | awk '{print $NF}' | sed 's/s[0-9]*$//') DISK_ID=$(diskutil list | grep $(get_codename $version_num)_dmg | head -1 | awk '{print $NF}' | sed 's/s[0-9]*$//')
# Prepare createinstallmedia command # Prepare createinstallmedia command
@@ -1054,8 +1304,8 @@ create_dmg_10_10_and_later() {
done done
# Extract the exact version number and append it to the file name # Extract the exact version number and append it to the file name
exact_version_number=$(defaults read "/Volumes/$(get_installer_app_name "$version_num")/System/Library/CoreServices/SystemVersion" ProductVersion) local exact_version_number=$(defaults read "/Volumes/$(get_installer_app_name "$version_num")/System/Library/CoreServices/SystemVersion" ProductVersion)
FINAL_OUTPUT_PATH="${output_file%.dmg}_$exact_version_number.dmg" FINAL_OUTPUT_PATH="${output_file%.dmg}_$exact_version_number.dmg.iso"
# Unmount # Unmount
detach_disk "$DISK_ID" && DISK_ID="" detach_disk "$DISK_ID" && DISK_ID=""
@@ -1064,7 +1314,7 @@ create_dmg_10_10_and_later() {
log_info "Final optimization..." log_info "Final optimization..."
sudo hdiutil resize -size min "$WORK_DIR/installer.dmg" sudo hdiutil resize -size min "$WORK_DIR/installer.dmg"
# Move to output # Move to output and append .iso extension
mv -f "$WORK_DIR/installer.dmg" "$FINAL_OUTPUT_PATH" mv -f "$WORK_DIR/installer.dmg" "$FINAL_OUTPUT_PATH"
} }
@@ -1138,17 +1388,6 @@ main() {
log_info "Output path:${GREEN} $OUTPUT_PATH ${NC}" log_info "Output path:${GREEN} $OUTPUT_PATH ${NC}"
echo "" echo ""
# Check if trying to install legacy macOS on ARM64
# if [[ "$VERSION_NUM" =~ ^10\.(7|8|9|10|11|12)$ ]]; then
# local cpu_arch=$(uname -m)
# if [ "$cpu_arch" == "arm64" ]; then
# log_error "Cannot create installer for macOS $VERSION_NUM on Apple silicon"
# log_error "Legacy macOS installers (10.7-10.12) require Intel (x86_64) Macs"
# log_error "Please use an Intel Mac to create installers for these versions"
# exit 1
# fi
# fi
# Create work directory # Create work directory
WORK_DIR=$(mktemp -d) WORK_DIR=$(mktemp -d)
log_info "Working directory:${CYAN} $WORK_DIR ${NC}" log_info "Working directory:${CYAN} $WORK_DIR ${NC}"
@@ -1185,7 +1424,7 @@ main() {
if [ "$IMAGE_FORMAT" == "iso" ]; then if [ "$IMAGE_FORMAT" == "iso" ]; then
case "$VERSION_NUM" in case "$VERSION_NUM" in
"10.7"|"10.8") "10.7"|"10.8")
create_iso_10_7_10_8 "$INSTALLER_PATH" "$OUTPUT_PATH" "$VOLUME_NAME" "$VERSION_NUM" ;; create_iso_dmg_10_7_10_8 "$INSTALLER_PATH" "$OUTPUT_PATH" "$VOLUME_NAME" "$VERSION_NUM" ;;
"10.9"|"10.10"|"10.11") "10.9"|"10.10"|"10.11")
create_iso_10_9_10_11 "$INSTALLER_PATH" "$OUTPUT_PATH" "$VOLUME_NAME" "$VERSION_NUM" ;; create_iso_10_9_10_11 "$INSTALLER_PATH" "$OUTPUT_PATH" "$VOLUME_NAME" "$VERSION_NUM" ;;
*) *)
@@ -1194,9 +1433,9 @@ main() {
else else
case "$VERSION_NUM" in case "$VERSION_NUM" in
"10.7"|"10.8") "10.7"|"10.8")
create_dmg_10_7_10_8 "$INSTALLER_PATH" "$OUTPUT_PATH" "$VOLUME_NAME" "$VERSION_NUM" ;; create_iso_dmg_10_7_10_8 "$INSTALLER_PATH" "$OUTPUT_PATH" "$VOLUME_NAME" "$VERSION_NUM" ;;
"10.9") "10.9")
create_dmg_10_9 "$INSTALLER_PATH" "$OUTPUT_PATH" "$VOLUME_NAME" "$VERSION_NUM" ;; create_dmg_10_9_to_10_12_alt_method "$INSTALLER_PATH" "$OUTPUT_PATH" "$VOLUME_NAME" "$VERSION_NUM" ;;
*) *)
create_dmg_10_10_and_later "$INSTALLER_PATH" "$OUTPUT_PATH" "$VERSION_NUM" ;; create_dmg_10_10_and_later "$INSTALLER_PATH" "$OUTPUT_PATH" "$VERSION_NUM" ;;
esac esac
@@ -1232,7 +1471,7 @@ main() {
else else
log_info "This DMG image is intended for:" log_info "This DMG image is intended for:"
log_info " - Flash to USB drive using Rufus (Windows) or dd (Linux)" log_info " - Flash to USB drive using Rufus (Windows) or dd (Linux)"
log_info " - Can also be used with virtual machines (requires conversion to .vhdx for Hyper-V or .vmdk for VMware)" log_info " - Can also be used with virtual machines (requires conversion to .vhd for Hyper-V or .vmdk for VMware)"
log_info " - Add to the VM as a virtual hard drive" log_info " - Add to the VM as a virtual hard drive"
echo "" echo ""
fi fi
@@ -1244,53 +1483,50 @@ main() {
# Show usage if -h or --help is passed # Show usage if -h or --help is passed
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "╔══════════════════════════════════════════════════════════════════════════════╗" cat << 'EOF'
echo "║ mkmaciso – the ultimate tool for creating macOS installer ISO and DMG images ║" ╔══════════════════════════════════════════════════════════════════════════════╗"
echo "╚══════════════════════════════════════════════════════════════════════════════╝" ║ mkmaciso – the ultimate tool for creating macOS installer ISO and DMG images ║"
echo "" ╚══════════════════════════════════════════════════════════════════════════════╝"
echo "Usage: $0 [VERSION] [FORMAT] [OUTPUT_PATH]"
echo " $0 # Run with no arguments to enter interactive mode" Usage:
echo "" mkmaciso [VERSION] [FORMAT] [OUTPUT_PATH]
echo "Parameters:" mkmaciso # Interactive mode
echo " VERSION - macOS version (number or codename), default: 26 (Tahoe)"
echo "" Parameters:
echo " FORMAT - Image format: iso or dmg, default: iso" VERSION macOS version number or codename, e.g. 26 or Tahoe
echo "" FORMAT iso or dmg (default: iso)
echo " OUTPUT_PATH - Output file path, default: ./macOS_<version>.<format>" OUTPUT_PATH Output file path (default: ./macOS_<version>.<format>)
echo ""
echo "Interactive Mode:" Supported versions:
echo " Run without any parameters to use the interactive menu." 10.7 Lion 10.14 Mojave
echo "" 10.8 Mountain Lion 10.15 Catalina
echo "Supported versions:" 10.9 Mavericks 11 Big Sur
echo " 10.7 (Lion) 10.14 (Mojave)" 10.10 Yosemite 12 Monterey
echo " 10.8 (Mountain Lion) 10.15 (Catalina)" 10.11 El Capitan 13 Ventura
echo " 10.9 (Mavericks) 11 (Big Sur)" 10.12 Sierra 14 Sonoma
echo " 10.10 (Yosemite) 12 (Monterey)" 10.13 High Sierra 15 Sequoia
echo " 10.11 (El Capitan) 13 (Ventura)" 26 Tahoe
echo " 10.12 (Sierra) 14 (Sonoma)"
echo " 10.13 (High Sierra) 15 (Sequoia)" Examples:
echo " 26 (Tahoe)" mkmaciso Interactive mode
echo "" mkmaciso 14 Create Sonoma ISO
echo "Examples:" mkmaciso 14 dmg Create Sonoma DMG
echo " $0 # Interactive mode" mkmaciso sonoma dmg ~/Desktop/out.dmg Create Sonoma DMG at specified path
echo " $0 14 # Create macOS Sonoma ISO in current directory"
echo " $0 14 dmg # Create macOS Sonoma DMG in current directory" Requirements:
echo " $0 sonoma dmg ~/Desktop/Sonoma.dmg # Create Sonoma DMG on Desktop" - macOS 11 (Big Sur) or later for create macOS 10.13+ image
echo "" - Internet connection for downloading installers
echo "Requirements:" - Sufficient disk space (~20-40GB temporary, final size varies)
echo " - macOS 11 (Big Sur) or later for create macOS 10.13+ image" - Administrator privileges (sudo)
echo " - Internet connection for downloading installers" - For best results, run this on Intel Macs
echo " - Sufficient disk space (~20-30GB temporary, final size varies)" EOF
echo " - Administrator privileges (sudo)"
echo " - Note: On Apple silicon Macs only the macOS version that originally"
echo " shipped with your device (or newer) can be download using this script"
echo ""
exit 0 exit 0
fi fi
# Check if running in interactive mode (no parameters) # Check if running in interactive mode with piped (no parameters)
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
if [ -p /dev/stdin ] || [ ! -t 0 ]; then if [ -p /dev/stdin ] || [ ! -t 0 ]; then
clear
log_error "Interactive mode unavailable when piped" log_error "Interactive mode unavailable when piped"
log_info "Usage: curl -sL <URL> | bash -s <VERSION> [FORMAT] [OUTPUT]" log_info "Usage: curl -sL <URL> | bash -s <VERSION> [FORMAT] [OUTPUT]"
echo "" echo ""