-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OS X Patcher.sh
executable file
·391 lines (338 loc) · 17.4 KB
/
OS X Patcher.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#!/bin/bash
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 -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Checking system environment."${erase_style}
if [ -d /Install\ *.app ]; then
environment="installer"
fi
if [ ! -d /Install\ *.app ]; then
environment="system"
fi
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Checked system environment."${erase_style}
}
Check_Root()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Checking for root permissions."${erase_style}
if [[ $environment == "installer" ]]; then
root_check="passed"
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Root permissions check passed."${erase_style}
else
if [[ $(whoami) == "root" && $environment == "system" ]]; then
root_check="passed"
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Root permissions check passed."${erase_style}
fi
if [[ ! $(whoami) == "root" && $environment == "system" ]]; then
root_check="failed"
echo -e $(date "+%b %m %H:%M:%S") ${text_error}"- Root permissions check failed."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ Run this tool with root permissions."${erase_style}
Input_On
exit
fi
fi
}
Check_Resources()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Checking for resources."${erase_style}
if [[ -d "$resources_path" ]]; then
resources_check="passed"
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Resources check passed."${erase_style}
fi
if [[ ! -d "$resources_path" ]]; then
resources_check="failed"
echo -e $(date "+%b %m %H:%M:%S") ${text_error}"- Resources check failed."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ Run this tool with the required resources."${erase_style}
Input_On
exit
fi
}
Input_Operation()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ What operation would you like to run?"${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ Input an operation number."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ 1 - Patch installer"${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ 2 - Patch update"${erase_style}
Input_On
read -e -p "$(date "+%b %m %H:%M:%S") / " operation
Input_Off
if [[ $operation == "1" ]]; then
Input_Installer
Check_Installer_Stucture
Check_Installer_Version
Check_Installer_Support
Installer_Variables
Input_Volume
Create_Installer
Patch_Installer
fi
if [[ $operation == "2" ]]; then
Input_Package
Patch_Package
fi
}
Input_Installer()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ What installer would you like to use?"${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ Input an installer path."${erase_style}
Input_On
read -e -p "$(date "+%b %m %H:%M:%S") / " installer_application_path
Input_Off
installer_sharedsupport_path="$installer_application_path/Contents/SharedSupport"
}
Check_Installer_Stucture()
{
Output_Off hdiutil attach "$installer_sharedsupport_path"/InstallESD.dmg -mountpoint /tmp/InstallESD -nobrowse -noverify
installer_images_path="/tmp/InstallESD"
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Mounting installer disk images."${erase_style}
Output_Off hdiutil attach "$installer_images_path"/BaseSystem.dmg -mountpoint /tmp/Base\ System -nobrowse -noverify
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Mounted installer disk images."${erase_style}
}
Check_Installer_Version()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Checking installer version."${erase_style}
installer_version="$(defaults read /tmp/Base\ System/System/Library/CoreServices/SystemVersion.plist ProductVersion)"
installer_version_short="$(defaults read /tmp/Base\ System/System/Library/CoreServices/SystemVersion.plist ProductVersion | cut -c-5)"
if [[ ${#installer_version} == "6" ]]; then
installer_version_short="$(defaults read /tmp/Base\ System/System/Library/CoreServices/SystemVersion.plist ProductVersion | cut -c-4)"
fi
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Checked installer version."${erase_style}
}
Check_Installer_Support()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Checking installer support."${erase_style}
if [[ $installer_version_short == "10."[8-9] || $installer_version_short == "10.1"[0-1] ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Installer support check passed."${erase_style}
else
echo -e $(date "+%b %m %H:%M:%S") ${text_error}"- Installer support check failed."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ Run this tool with a supported installer."${erase_style}
Input_On
exit
fi
}
Installer_Variables()
{
if [[ 1 == 1 ]]; then
installer_prelinkedkernel="$installer_version_short"
fi
}
Input_Volume()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ What volume would you like to use?"${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ Input a volume name."${erase_style}
for volume_path in /Volumes/*; do
volume_name="${volume_path#/Volumes/}"
if [[ ! "$volume_name" == com.apple* ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ ${volume_name}"${erase_style} | sort
fi
done
Input_On
read -e -p "$(date "+%b %m %H:%M:%S") / " installer_volume_name
Input_Off
installer_volume_path="/Volumes/$installer_volume_name"
}
Create_Installer()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Restoring installer disk image."${erase_style}
Output_Off asr restore -source "$installer_images_path"/BaseSystem.dmg -target "$installer_volume_path" -noprompt -noverify -erase
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Restored installer disk image."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Renaming installer volume."${erase_style}
Output_Off diskutil rename /Volumes/*Base\ System "$installer_volume_name"
bless --folder "$installer_volume_path"/System/Library/CoreServices --label "$installer_volume_name"
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Renamed installer volume."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Copying installer packages."${erase_style}
rm "$installer_volume_path"/System/Installation/Packages
cp -R /tmp/InstallESD/Packages "$installer_volume_path"/System/Installation/
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Copied installer packages."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Copying installer disk images."${erase_style}
cp "$installer_images_path"/BaseSystem.dmg "$installer_volume_path"/
cp "$installer_images_path"/BaseSystem.chunklist "$installer_volume_path"/
if [[ -e "$installer_images_path"/AppleDiagnostics.dmg ]]; then
cp "$installer_images_path"/AppleDiagnostics.dmg "$installer_volume_path"/
cp "$installer_images_path"/AppleDiagnostics.chunklist "$installer_volume_path"/
fi
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Copied installer disk images."${erase_style}
if [[ $installer_version_short == "10.8" ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Copying installer mach_kernel."${erase_style}
cp /tmp/InstallESD/mach_kernel "$installer_volume_path"/
chflags hidden "$installer_volume_path"/mach_kernel
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Copied installer mach_kernel."${erase_style}
fi
if [[ $installer_version_short == "10.9" ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Copying installer mach_kernel."${erase_style}
cp "$resources_path"/Kernels/"$installer_version_short"/mach_kernel "$installer_volume_path"/
chflags hidden "$installer_volume_path"/mach_kernel
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Copied installer mach_kernel."${erase_style}
fi
if [[ $installer_version_short == "10.1"[0-1] ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Copying installer kernel."${erase_style}
mkdir -p "$installer_volume_path"/System/Library/Kernels
cp "$resources_path"/Kernels/"$installer_version_short"/kernel "$installer_volume_path"/System/Library/Kernels
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Copied installer kernel."${erase_style}
fi
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Unmounting installer disk images."${erase_style}
Output_Off hdiutil detach /tmp/Base\ System
Output_Off hdiutil detach /tmp/InstallESD
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Unmounted installer disk images."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Replacing installer utilities menu."${erase_style}
cp "$resources_path"/InstallerMenuAdditions.plist "$installer_volume_path"/System/Installation/CDIS/OS\ X\ Installer.app/Contents/Resources
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Replacing installer utilities menu."${erase_style}
}
Patch_Installer()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching installer package."${erase_style}
cp "$installer_volume_path"/System/Installation/Packages/OSInstall.mpkg "$installer_volume_path"/tmp
pkgutil --expand "$installer_volume_path"/tmp/OSInstall.mpkg "$installer_volume_path"/tmp/OSInstall
sed -i '' 's/cpuFeatures\[i\] == "VMM"/1 == 1/' "$installer_volume_path"/tmp/OSInstall/Distribution
sed -i '' 's/boardID == platformSupportValues\[i\]/1 == 1/' "$installer_volume_path"/tmp/OSInstall/Distribution
sed -i '' 's/!boardID || platformSupportValues.length == 0/1 == 0/' "$installer_volume_path"/tmp/OSInstall/Distribution
pkgutil --flatten "$installer_volume_path"/tmp/OSInstall "$installer_volume_path"/tmp/OSInstall.mpkg
cp "$installer_volume_path"/tmp/OSInstall.mpkg "$installer_volume_path"/System/Installation/Packages
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched installer package."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching boot.efi."${erase_style}
if [[ $installer_version_short == "10."[8-9] || $installer_version_short == "10.10" ]]; then
chflags nouchg "$installer_volume_path"/System/Library/CoreServices/boot.efi
cp "$resources_path"/patch/EFI/10.8/boot.efi "$installer_volume_path"/System/Library/CoreServices
chflags uchg "$installer_volume_path"/System/Library/CoreServices/boot.efi
fi
if [[ $installer_version_short == "10.11" ]]; then
chflags nouchg "$installer_volume_path"/System/Library/CoreServices/boot.efi
cp "$resources_path"/patch/EFI/10.11/boot.efi "$installer_volume_path"/System/Library/CoreServices
cp "$resources_path"/patch/EFI/10.11/boot.efi "$installer_volume_path"/System/Library/CoreServices/bootbase.efi
chflags uchg "$installer_volume_path"/System/Library/CoreServices/boot.efi
chflags uchg "$installer_volume_path"/System/Library/CoreServices/bootbase.efi
fi
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched boot.efi."${erase_style}
if [[ $installer_version_short == "10.11" ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching drivers."${erase_style}
rm -R "$installer_volume_path"/System/Library/Extensions/IOUSBHostFamily.kext
cp -R "$resources_path"/patch/AppleHIDMouse.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/AppleIRController.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/AppleTopCase.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/AppleUSBMultitouch.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/AppleUSBTopCase.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/IOBDStorageFamily.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/IOBluetoothFamily.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/IOBluetoothHIDDriver.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/IOSerialFamily.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/IOUSBFamily.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/IOUSBHostFamily.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/IOUSBMassStorageClass.kext "$installer_volume_path"/System/Library/Extensions/
cp -R "$resources_path"/patch/SIPManager.kext "$installer_volume_path"/System/Library/Extensions/
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched drivers."${erase_style}
fi
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching platform support check."${erase_style}
rm "$installer_volume_path"/System/Library/CoreServices/PlatformSupport.plist
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched platform support check."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching kernel flags."${erase_style}
sed -i '' 's|<string></string>|<string>kext-dev-mode=1 mbasd=1</string>|' "$installer_volume_path"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched kernel flags."${erase_style}
if [[ $installer_version_short == "10.11" ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching kernel cache."${erase_style}
rm "$installer_volume_path"/System/Library/PrelinkedKernels/prelinkedkernel
cp "$resources_path"/PrelinkedKernel/10.11/prelinkedkernel "$installer_volume_path"/System/Library/PrelinkedKernels
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched kernel cache."${erase_style}
fi
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Copying patcher utilities."${erase_style}
cp -R "$resources_path"/patch "$installer_volume_path"/
cp "$resources_path"/dm "$installer_volume_path"/usr/bin
cp "$resources_path"/patch.sh "$installer_volume_path"/usr/bin/patch
cp "$resources_path"/restore.sh "$installer_volume_path"/usr/bin/restore
chmod +x "$installer_volume_path"/usr/bin/dm
chmod +x "$installer_volume_path"/usr/bin/patch
chmod +x "$installer_volume_path"/usr/bin/restore
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Copied patcher utilities."${erase_style}
}
Input_Package()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ What update would you like to use?"${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ Input an update path."${erase_style}
Input_On
read -e -p "$(date "+%b %m %H:%M:%S") / " package_path
Input_Off
package_folder="${package_path%.*}"
}
Patch_Package()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Expanding update package."${erase_style}
pkgutil --expand "$package_path" "$package_folder"
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Expanded update package."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching update package."${erase_style}
sed -i '' 's|<pkg-ref id="com\.apple\.pkg\.FirmwareUpdate" auth="Root" packageIdentifier="com\.apple\.pkg\.FirmwareUpdate">#FirmwareUpdate\.pkg<\/pkg-ref>||' "$package_folder"/Distribution
sed -i '' 's/cpuFeatures\[i\] == "VMM"/1 == 1/' "$package_folder"/Distribution
sed -i '' 's/nonSupportedModels.indexOf(currentModel)>= 0/1 == 0/' "$package_folder"/Distribution
sed -i '' 's/boardIds.indexOf(boardId)== -1/1 == 0/' "$package_folder"/Distribution
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched update package."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Preparing update package."${erase_style}
pkgutil --flatten "$package_folder" "$package_path"
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Prepared update package."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Removing temporary files."${erase_style}
Output_Off rm -R "$package_folder"
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Removed temporary files."${erase_style}
}
End()
{
if [[ $operation == "1" ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Removing temporary files."${erase_style}
Output_Off rm -R "$installer_volume_path"/tmp/*
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Removed temporary files."${erase_style}
fi
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ Thank you for using OS X Patcher."${erase_style}
Input_On
exit
}
Input_Off
Escape_Variables
Parameter_Variables
Path_Variables
Check_Environment
Check_Root
Check_Resources
Input_Operation
End