-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathCreate_Recovery_ISO.command
More file actions
executable file
·281 lines (242 loc) · 7.29 KB
/
Create_Recovery_ISO.command
File metadata and controls
executable file
·281 lines (242 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/bash
# Copyright (c) 2024-2025, LongQT-sea
# macOS Recovery ISO Creator
# Downloads macOS recovery images from Apple and converts them to bootable DVD ISO files
set -e
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if running as root, if not, re-execute with sudo
if [ "$EUID" -ne 0 ]; then
echo ""
echo -e "${YELLOW}[INFO]${NC} Administrator privileges required..."
exec sudo "$0" "$@"
exit
fi
# Function to get version info by key
get_version_info() {
local key=$1
case $key in
high_sierra) echo "Mac-7BA5B2D9E42DDD94:00000000000J80300:High_Sierra:" ;;
mojave) echo "Mac-7BA5B2DFE22DDD8C:00000000000KXPG00:Mojave:" ;;
catalina) echo "Mac-CFF7D910A743CAAF:00000000000PHCD00:Catalina:" ;;
big_sur) echo "Mac-2BD1B31983FE1663:00000000000000000:Big_Sur:" ;;
monterey) echo "Mac-E43C1C25D4880AD6:00000000000000000:Monterey:" ;;
ventura) echo "Mac-B4831CEBD52A0C4C:00000000000000000:Ventura:" ;;
sonoma) echo "Mac-827FAC58A8FDFA22:00000000000000000:Sonoma:" ;;
sequoia) echo "Mac-7BA5B2D9E42DDD94:00000000000000000:Sequoia:" ;;
tahoe) echo "Mac-CFF7D910A743CAAF:00000000000000000:Tahoe:latest" ;;
*) echo "" ;;
esac
}
# Function to print colored messages
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Function to check if Python 3 is available
check_python() {
if ! command -v python3 &> /dev/null; then
print_error "Python3 is not installed on your system."
echo "Please install Python3:"
echo "Download it from: https://www.python.org/downloads/"
echo "Or use Install_Python3.command to do it automatically"
exit 1
fi
}
# Function to download macrecovery.py
download_macrecovery() {
local url="https://raw.githubusercontent.com/acidanthera/OpenCorePkg/master/Utilities/macrecovery/macrecovery.py"
if [ -f "macrecovery.py" ]; then
rm -f macrecovery.py
fi
print_info "Downloading macrecovery.py from acidanthera/OpenCorePkg..."
if curl -sL "$url" -o macrecovery.py; then
chmod +x macrecovery.py
else
print_error "Failed to download macrecovery.py"
exit 1
fi
}
# Function to cleanup
cleanup_recovery() {
if [ -d "com.apple.recovery.boot" ]; then
print_info "Cleaning up..."
rm -rf com.apple.recovery.boot
rm -rf macrecovery.py
fi
}
# Function to download macOS recovery
download_recovery() {
local board_id=$1
local model=$2
local os_flag=$3
print_info "Downloading macOS recovery..."
print_info "Board ID: $board_id"
if [ -n "$os_flag" ]; then
python3 macrecovery.py -b "$board_id" -m "$model" -os "$os_flag" download
else
python3 macrecovery.py -b "$board_id" -m "$model" download
fi
# Check if BaseSystem.dmg was downloaded (all versions 10.13+ use BaseSystem.dmg)
if [ ! -f "com.apple.recovery.boot/BaseSystem.dmg" ]; then
print_error "Failed to download recovery image"
exit 1
fi
print_info "Recovery image downloaded successfully"
}
# Function to create ISO
create_iso() {
local version_name=$1
local output_path="$HOME/Desktop/macOS_${version_name}_Recovery.iso"
local recovery_path="com.apple.recovery.boot/BaseSystem.dmg"
# Check if the recovery file exists
if [ ! -f "$recovery_path" ]; then
print_error "Recovery image not found at: $recovery_path"
# List available files for debugging
print_info "Available files in com.apple.recovery.boot/:"
ls -la com.apple.recovery.boot/
exit 1
fi
print_info "Creating bootable ISO..."
# All versions 10.13+ use -hfs -udf options
hdiutil makehybrid -ov -hfs -udf \
-default-volume-name "${version_name}_Recovery" \
-o "$output_path" \
"$recovery_path"
if [ -f "$output_path" ]; then
print_info "ISO created successfully at: $output_path"
else
print_error "Failed to create ISO"
exit 1
fi
}
# Function to display available versions
show_versions() {
echo ""
echo "Available macOS versions:"
echo "========================="
echo " 1. High Sierra (10.13)"
echo " 2. Mojave (10.14)"
echo " 3. Catalina (10.15)"
echo " 4. Big Sur (11)"
echo " 5. Monterey (12)"
echo " 6. Ventura (13)"
echo " 7. Sonoma (14)"
echo " 8. Sequoia (15)"
echo " 9. Tahoe (Latest)"
echo ""
}
# Function to process version selection
process_version() {
local version=$1
case $version in
1|high_sierra)
key="high_sierra"
;;
2|mojave)
key="mojave"
;;
3|catalina)
key="catalina"
;;
4|big_sur)
key="big_sur"
;;
5|monterey)
key="monterey"
;;
6|ventura)
key="ventura"
;;
7|sonoma)
key="sonoma"
;;
8|sequoia)
key="sequoia"
;;
9|tahoe)
key="tahoe"
;;
*)
print_error "Invalid version selection"
exit 1
;;
esac
local version_info="$(get_version_info "$key")"
if [ -z "$version_info" ]; then
print_error "Invalid version selection"
exit 1
fi
IFS=':' read -r board_id model version_name os_flag <<< "$version_info"
print_info "Selected: $version_name"
cleanup_recovery
download_recovery "$board_id" "$model" "$os_flag"
create_iso "$version_name"
cleanup_recovery
}
# Function to show usage
show_usage() {
cat << EOF
Usage: $0 [OPTIONS]
Options:
-v, --version <number|name> macOS version to download (1-9 or name)
-h, --help Show this help message
Examples:
$0 # Interactive mode
$0 -v 3 # Download Catalina
$0 -v catalina # Download Catalina by name
$0 -v sonoma # Download Sonoma by name
EOF
show_versions
}
# Main script
main() {
print_info "macOS Recovery ISO Creator"
print_info "=========================="
# Check for macOS
if [[ "$OSTYPE" != "darwin"* ]]; then
print_error "This script must be run on macOS"
exit 1
fi
# Check Python
check_python
# Download macrecovery.py
download_macrecovery
# Parse arguments
if [ $# -eq 0 ]; then
# Interactive mode
show_versions
read -p "Select version (1-9): " version_choice
echo ""
process_version "$version_choice"
else
# Non-interactive mode
while [[ $# -gt 0 ]]; do
case $1 in
-v|--version)
process_version "$2"
shift 2
;;
-h|--help)
show_usage
exit 0
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
fi
}
# Run main function
main "$@"