-
Notifications
You must be signed in to change notification settings - Fork 33
/
macOS Downloader.sh
executable file
·295 lines (257 loc) · 9.52 KB
/
macOS Downloader.sh
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/sh
parameters="${1}${2}${3}${4}${5}${6}${7}${8}${9}"
Escape_Variables()
{
text_progress="\033[38;5;113m"
text_success="\033[38;5;113m"
text_warning="\033[38;5;221m"
text_error="\033[38;5;203m"
text_message="\033[38;5;75m"
text_bold="\033[1m"
text_faint="\033[2m"
text_italic="\033[3m"
text_underline="\033[4m"
erase_style="\033[0m"
erase_line="\033[0K"
move_up="\033[1A"
move_down="\033[1B"
move_foward="\033[1C"
move_backward="\033[1D"
}
Parameter_Variables()
{
if [[ $parameters == *"-v"* || $parameters == *"-verbose"* ]]; then
verbose="1"
set -x
fi
}
Path_Variables()
{
script_path="${0}"
directory_path="${0%/*}"
resources_path="$directory_path/resources"
}
Input_Off()
{
stty -echo
}
Input_On()
{
stty echo
}
Output_Off() {
if [[ $verbose == "1" ]]; then
"$@"
else
"$@" &>/dev/null
fi
}
Check_Environment()
{
echo ${text_progress}"> Checking system environment."${erase_style}
if [ -d /Install\ *.app ]; then
environment="installer"
fi
if [ ! -d /Install\ *.app ]; then
environment="system"
fi
echo ${move_up}${erase_line}${text_success}"+ Checked system environment."${erase_style}
}
Check_Root()
{
echo ${text_progress}"> Checking for root permissions."${erase_style}
if [[ $environment == "installer" ]]; then
root_check="passed"
echo ${move_up}${erase_line}${text_success}"+ Root permissions check passed."${erase_style}
else
if [[ $(whoami) == "root" && $environment == "system" ]]; then
root_check="passed"
echo ${move_up}${erase_line}${text_success}"+ Root permissions check passed."${erase_style}
fi
if [[ ! $(whoami) == "root" && $environment == "system" ]]; then
root_check="failed"
echo ${text_error}"- Root permissions check failed."${erase_style}
echo ${text_message}"/ Run this tool with root permissions."${erase_style}
Input_On
exit
fi
fi
}
Check_Resources()
{
echo ${text_progress}"> Checking for resources."${erase_style}
if [[ -d "$resources_path" ]]; then
resources_check="passed"
echo ${move_up}${erase_line}${text_success}"+ Resources check passed."${erase_style}
fi
if [[ ! -d "$resources_path" ]]; then
resources_check="failed"
echo ${text_error}"- Resources check failed."${erase_style}
echo ${text_message}"/ Run this tool with the required resources."${erase_style}
Input_On
exit
fi
}
Check_Internet()
{
echo ${text_progress}"> Checking for internet conectivity."${erase_style}
if [[ $(ping -c 5 www.google.com) == *transmitted* && $(ping -c 5 www.google.com) == *received* ]]; then
echo ${move_up}${erase_line}${text_success}"+ Integrity conectivity check passed."${erase_style}
else
echo ${text_error}"- Integrity conectivity check failed."${erase_style}
echo ${text_message}"/ Run this tool while connected to the internet."${erase_style}
Input_On
exit
fi
}
Input_Folder()
{
echo ${text_message}"/ What save folder would you like to use?"${erase_style}
echo ${text_message}"/ Input a save folder path."${erase_style}
Input_On
read -e -p "/ " save_folder
Input_Off
}
Input_Operation_Version()
{
echo ${text_message}"/ What operation would you like to run?"${erase_style}
echo ${text_message}"/ Input an operation number."${erase_style}
echo ${text_message}"/ 1 - Catalina"${erase_style}
echo ${text_message}"/ 2 - Mojave"${erase_style}
echo ${text_message}"/ 3 - High Sierra"${erase_style}
Input_On
read -e -p "/ " operation_version
Input_Off
if [[ $operation_version == "1" ]]; then
installer_choice="c"
fi
if [[ $operation_version == "2" ]]; then
installer_choice="m"
fi
if [[ $operation_version == "3" ]]; then
installer_choice="hs"
fi
}
Import_Variables()
{
curl -L -s -o /tmp/resources.zip https://github.com/rmc-team/macos-downloader-resources/archive/master.zip
unzip -q /tmp/resources.zip -d /tmp
chmod +x /tmp/macos-downloader-resources-master/resources/var.sh
source /tmp/macos-downloader-resources-master/resources/var.sh
installer_url="${installer_choice}_installer_url"
installer_key="${!installer_url#*/*/}"
installer_key="${installer_key%/*}"
update_key="${update_url#*/*/}"
update_key="${update_key%/*}"
combo_update_key="${combo_update_url#*/*/}"
combo_update_key="${combo_update_key%/*}"
curl -L -s -o /tmp/$installer_key.dist https://swdist.apple.com/content/downloads/${!installer_url}/$installer_key.English.dist
curl -L -s -o /tmp/$update_key.dist https://swdist.apple.com/content/downloads/$update_url/$update_key.English.dist
installer_name="$(grep "\"SU_TITLE\"\ =" /tmp/$installer_key.dist)"
installer_name="${installer_name#*SU_TITLE*=*\"}"
installer_name="${installer_name%\"*}"
update_version="$(grep -A1 "ProductVersion" /tmp/$update_key.dist)"
update_version="${update_version#*<string>}"
update_version="${update_version%</string>*}"
}
Input_Operation_Download()
{
echo ${text_message}"/ What operation would you like to run?"${erase_style}
echo ${text_message}"/ Input an operation number."${erase_style}
echo ${text_message}"/ 1 - Installer"${erase_style}
if [[ $update_option == "1" && $installer_choice == "m" ]]; then
echo ${text_message}"/ 2 - Update"${erase_style}
fi
if [[ $combo_update_option == "1" && $installer_choice == "m" ]]; then
echo ${text_message}"/ 3 - Combo Update"${erase_style}
fi
Input_On
read -e -p "/ " operation_download
Input_Off
if [[ $operation_download == "1" ]]; then
Download_Installer
Prepare_Installer
fi
if [[ $operation_download == "2" ]]; then
update_name="macOSUpd"
update_url="$update_url"
update_key="$update_key"
Download_Update
Prepare_Update
fi
if [[ $operation_download == "3" ]]; then
update_name="macOSUpdCombo"
update_url="$combo_update_url"
update_key="$combo_update_key"
Download_Update
Prepare_Update
fi
}
Download_Installer()
{
echo ${text_progress}"> Downloading installer files."${erase_style}
mkdir /tmp/"Install $installer_name"
installer_folder="/tmp/Install $installer_name"
curl -L -s -o "$installer_folder"/InstallAssistantAuto.pkg http://swcdn.apple.com/content/downloads/${!installer_url}/InstallAssistantAuto.pkg
curl -L -s -o "$installer_folder"/InstallESDDmg.pkg http://swcdn.apple.com/content/downloads/${!installer_url}/InstallESDDmg.pkg
curl -L -s -o "$installer_folder"/RecoveryHDMetaDmg.pkg http://swcdn.apple.com/content/downloads/${!installer_url}/RecoveryHDMetaDmg.pkg
echo ${move_up}${erase_line}${text_success}"+ Downloaded installer files."${erase_style}
}
Prepare_Installer()
{
echo ${text_progress}"> Preparing installer."${erase_style}
cd "$save_folder"
chmod +x "$resources_path"/pbzx
"$resources_path"/pbzx "$installer_folder"/InstallAssistantAuto.pkg | Output_Off cpio -i
cp "$installer_folder"/InstallESDDmg.pkg "$save_folder"/"Install $installer_name.app"/Contents/SharedSupport/InstallESD.dmg
mv "$installer_folder"/RecoveryHDMetaDmg.pkg "$installer_folder"/RecoveryHDMeta.dmg
Output_Off hdiutil attach "$installer_folder"/RecoveryHDMeta.dmg -mountpoint /tmp/RecoveryHDMeta -nobrowse
cp -R /tmp/RecoveryHDMeta/ "$save_folder"/"Install $installer_name.app"/Contents/SharedSupport/
Output_Off hdiutil detach /tmp/RecoveryHDMeta
touch "$save_folder"/"Install $installer_name.app"
echo ${move_up}${erase_line}${text_success}"+ Prepared installer."${erase_style}
}
Download_Update()
{
echo ${text_progress}"> Downloading update files."${erase_style}
mkdir /tmp/"$update_name$update_version"
update_folder="/tmp/$update_name$update_version"
curl -L -s -o "$update_folder"/macOSBrain.pkg http://swcdn.apple.com/content/downloads/$update_url/macOSBrain.pkg
curl -L -s -o "$update_folder"/SecureBoot.pkg http://swcdn.apple.com/content/downloads/$update_url/SecureBoot.pkg
curl -L -s -o "$update_folder"/EmbeddedOSFirmware.pkg http://swcdn.apple.com/content/downloads/$update_url/EmbeddedOSFirmware.pkg
curl -L -s -o "$update_folder"/FirmwareUpdate.pkg http://swcdn.apple.com/content/downloads/$update_url/FirmwareUpdate.pkg
curl -L -s -o "$update_folder"/FullBundleUpdate.pkg http://swcdn.apple.com/content/downloads/$update_url/FullBundleUpdate.pkg
curl -L -s -o "$update_folder"/$update_name$update_version.pkg http://swcdn.apple.com/content/downloads/$update_url/$update_name$update_version.pkg
curl -L -s -o "$update_folder"/$update_name$update_version.RecoveryHDUpdate.pkg http://swcdn.apple.com/content/downloads/$update_url/$update_name$update_version.RecoveryHDUpdate.pkg
curl -L -s -o "$update_folder"/$update_key.dist https://swdist.apple.com/content/downloads/$update_url/$update_key.English.dist
echo ${move_up}${erase_line}${text_success}"+ Downloaded update files."${erase_style}
}
Prepare_Update()
{
echo ${text_progress}"> Preparing update."${erase_style}
sed -i '' 's|<pkg-ref id="com\.apple\.pkg\.update\.os\.10\.14\.[0-9]\{1,\}Patch\.[a-zA-Z0-9]\{1,\}" auth="Root" packageIdentifier="com\.apple\.pkg\.update\.os\.10\.14\.[0-9]\{1,\}\.[a-zA-Z0-9]\{1,\}" onConclusion="RequireRestart">macOSUpd10\.14\.[0-9]\{1,\}Patch\.pkg<\/pkg-ref>||' "$update_folder"/$update_key.dist
Output_Off productbuild --distribution "$update_folder"/$update_key.dist --package-path "$update_folder" "$save_folder/$update_name$update_version.pkg"
echo ${move_up}${erase_line}${text_success}"+ Prepared update."${erase_style}
}
End()
{
echo ${text_progress}"> Removing temporary files."${erase_style}
Output_Off rm -R /tmp/*
echo ${move_up}${erase_line}${text_success}"+ Removed temporary files."${erase_style}
echo ${text_message}"/ Thank you for using macOS Downloader."${erase_style}
Input_On
exit
}
Input_Off
Escape_Variables
Parameter_Variables
Path_Variables
Check_Environment
Check_Root
Check_Resources
Check_Internet
Input_Folder
Input_Operation_Version
Import_Variables
Input_Operation_Download
End