-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathosxiso
executable file
·205 lines (163 loc) · 5.23 KB
/
osxiso
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
#!/usr/bin/env bash
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|macOS Mojave|macOS Catalina|macOS Big Sur|macOS Monterey|"
apps_large="|macOS Big Sur|macOS Monterey|"
apps=(
"macOS Monterey"
"macOS Big Sur"
"macOS Catalina"
"macOS Mojave"
"macOS High Sierra"
"macOS Sierra"
"OS X El Capitan"
"OS X Yosemite"
"OS X Mavericks"
)
apps_available=()
function log_warning() {
echo "$(tput setab 3)$(tput setaf 0)>> $* $(tput sgr0)"
}
function log_error() {
>&2 echo "$(tput setab 1)$(tput setaf 7)>> $* $(tput sgr0)"
}
function log_success() {
echo "$(tput setab 2)$(tput setaf 7)$*$(tput sgr0)"
}
function detach_mounts() {
# Unmount OS
[[ ! -d "/Volumes/Install $1" ]] || hdiutil detach -force "/Volumes/Install $1"
# Unmount the installer image
[[ ! -d "$app_mount" ]] || hdiutil detach -force "$app_mount"
# Unmount the sparse bundle
[[ ! -d "$base_mount" ]] || hdiutil detach -force "$base_mount"
# Unmount temporary build path
[[ ! -d "$build_mount" ]] || hdiutil detach -force "$build_mount"
}
function cleanup() {
detach_mounts "$1"
# Remove temp directory
rm -rf "$temp"
}
function abort() {
echo
log_error "Command returned with error, aborting ..."
echo
exit 2
}
function prep_build() {
# Attempt cleanup of any failed previous attempts
cleanup "$1"
# Prepare to do work
mkdir -p "$temp"
mkdir -p "$dist"
}
function build_v1() {
trap cleanup EXIT
trap abort ERR
local app_file="/Applications/Install $1.app"
prep_build
# Mount the installer image
hdiutil attach "$app_file/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 "$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
echo "ISO is located at:"
echo
echo "$dist/$1.iso"
}
function build_v2() {
trap cleanup EXIT
trap abort ERR
local app_file="/Applications/Install $1.app"
prep_build "$1"
iso_size="8125m"
if [[ "$apps_large" == *"|$1|"* ]]; then
iso_size="13750m"
fi
# Create a blank ISO with a Single Partition
hdiutil create -o "$temp/$1.cdr" -size "$iso_size" -layout SPUD -fs HFS+J
# Mount the blank ISO
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
echo "ISO is located at:"
echo
echo "$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
log_error "You must select a valid option *number* from the list."
choose
fi
break
;;
esac
done
}
function main() {
for app in "${apps[@]}"; do
if [[ -d "/Applications/Install $app.app" ]]; then
apps_available+=("$app")
else
log_warning "Missing /Applications/Install $app.app"
fi
done
[[ ${#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
apps_available+=("Quit")
choose
}
main
}
## Export or run
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
export -f osxiso
else
osxiso
fi