forked from os-x-hackers/macos-patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacOS Patcher.sh
executable file
·721 lines (493 loc) · 29.4 KB
/
macOS 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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
#!/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"
else
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}
else
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}
else
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}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ 3 - Update patched installer"${erase_style}
if [[ "$operation" ]]; then
echo -e $(date "+%b %m %H:%M:%S") "/ $operation"${erase_style}
else
Input_On
read -e -p "$(date "+%b %m %H:%M:%S") / " operation
Input_Off
fi
if [[ $operation == "1" ]]; then
Input_Installer
Check_Installer_Stucture
Check_Installer_Version
Check_Installer_Support
Installer_Variables
Input_Volume
if [[ $installer_version_short == "10.1"[2-4] ]]; then
Create_Installer
Patch_Installer
fi
if [[ $installer_version_short == "10.15" ]]; then
Modern_Installer
fi
fi
if [[ $operation == "2" ]]; then
Input_Package
Patch_Package
fi
if [[ $operation == "3" ]]; then
Input_Volume
Update_Patched_Installer
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}
if [[ "$installer_application_path" ]]; then
echo -e $(date "+%b %m %H:%M:%S") "/ $installer_application_path"${erase_style}
else
Input_On
read -e -p "$(date "+%b %m %H:%M:%S") / " installer_application_path
Input_Off
fi
installer_application_name="${installer_application_path##*/}"
installer_application_name_partial="${installer_application_name%.app}"
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
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Checking installer structure."${erase_style}
if [[ -e /tmp/InstallESD/BaseSystem.dmg ]]; then
installer_images_path="/tmp/InstallESD"
fi
if [[ -e "$installer_sharedsupport_path"/BaseSystem.dmg ]]; then
installer_images_path="$installer_sharedsupport_path"
fi
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Checked installer structure."${erase_style}
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="$(/usr/libexec/PlistBuddy -c "Print ProductVersion" /tmp/Base\ System/System/Library/CoreServices/SystemVersion.plist)"
installer_version_short="$(/usr/libexec/PlistBuddy -c "Print ProductVersion" /tmp/Base\ System/System/Library/CoreServices/SystemVersion.plist | cut -c-5)"
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.1"[2-4] || $installer_version == "10.15" || $installer_version == "10.15."[1-7] ]]; 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 [[ $installer_version_short == "10.1"[2-5] || $installer_version == "10.13."[1-3] ]]; then
installer_prelinkedkernel="$installer_version_short"
fi
if [[ $installer_version == "10.12."[1-3] || $installer_version == "10.14."[1-3] ]]; then
installer_prelinkedkernel="$installer_version_short.1"
fi
if [[ $installer_version == "10.12."[4-6] || $installer_version == "10.13."[4-6] || $installer_version == "10.14."[4-6] ]]; then
installer_prelinkedkernel="$installer_version_short.4"
fi
installer_prelinkedkernel_path="$resources_path/prelinkedkernel/$installer_prelinkedkernel"
}
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 number."${erase_style}
for volume_path in /Volumes/*; do
volume_name="${volume_path#/Volumes/}"
if [[ ! "$volume_name" == com.apple* ]]; then
volume_number=$(($volume_number + 1))
declare volume_$volume_number="$volume_name"
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ ${volume_number} - ${volume_name}"${erase_style} | sort
fi
done
if [[ "$installer_volume_name" ]]; then
for volume_path in /Volumes/*; do
volume_name="${volume_path#/Volumes/}"
if [[ ! "$volume_name" == com.apple* ]]; then
volumes_number=$(($volumes_number + 1))
for volume_number in $volumes_number; do
installer_volume="volume_$volume_number"
if [[ "${!installer_volume}" == "$installer_volume_name" ]]; then
installer_volume_number="$volume_number"
fi
done
fi
done
echo -e $(date "+%b %m %H:%M:%S") "/ $installer_volume_number"${erase_style}
else
Input_On
read -e -p "$(date "+%b %m %H:%M:%S") / " installer_volume_number
Input_Off
installer_volume="volume_$installer_volume_number"
installer_volume_name="${!installer_volume}"
fi
installer_volume_path="/Volumes/$installer_volume_name"
installer_volume_identifier="$(diskutil info "$installer_volume_name"|grep "Device Identifier"|sed 's/.*\ //')"
}
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 "$installer_volume_identifier" "$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}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Unmounting installer disk images."${erase_style}
Output_Off hdiutil detach /tmp/InstallESD
Output_Off hdiutil detach /tmp/Base\ System
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Unmounted installer disk images."${erase_style}
}
Patch_Installer()
{
if [[ $installer_version_short == "10.1"[3-4] ]]; then
Patch_Supported
fi
Patch_Unsupported
}
Patch_Supported()
{
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/*Installer.app/Contents/Resources
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Replacing installer utilities menu."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching installer app."${erase_style}
cp -R "$installer_volume_path"/System/Installation/CDIS/macOS\ Installer.app "$installer_volume_path"/tmp/macOS\ Installer-original.app
cp -R "$resources_path"/macOS\ Installer.app "$installer_volume_path"/tmp/macOS\ Installer-patched.app
cp "$installer_volume_path"/tmp/macOS\ Installer-original.app/Contents/Resources/X.tiff "$installer_volume_path"/tmp/macOS\ Installer-patched.app/Contents/Resources/
cp "$installer_volume_path"/tmp/macOS\ Installer-original.app/Contents/Resources/OSXTheme.car "$installer_volume_path"/tmp/macOS\ Installer-patched.app/Contents/Resources/
cp "$installer_volume_path"/tmp/macOS\ Installer-original.app/Contents/Resources/ReleaseNameTheme.car "$installer_volume_path"/tmp/macOS\ Installer-patched.app/Contents/Resources/
cp "$installer_volume_path"/tmp/macOS\ Installer-original.app/Contents/Resources/InstallerMenuAdditions.plist "$installer_volume_path"/tmp/macOS\ Installer-patched.app/Contents/Resources/
rm -R "$installer_volume_path"/System/Installation/CDIS/macOS\ Installer.app
cp -R "$installer_volume_path"/tmp/macOS\ Installer-patched.app "$installer_volume_path"/System/Installation/CDIS/macOS\ Installer.app
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched installer app."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching installer framework."${erase_style}
rm -R "$installer_volume_path"/System/Library/PrivateFrameworks/OSInstaller.framework
cp -R "$resources_path"/OSInstaller.framework "$installer_volume_path"/System/Library/PrivateFrameworks/
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched installer framework."${erase_style}
if [[ $installer_version_short == "10.1"[4-5] ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching system migration frameworks."${erase_style}
rm -R "$installer_volume_path"/System/Library/PrivateFrameworks/SystemMigration.framework
rm -R "$installer_volume_path"/System/Library/PrivateFrameworks/SystemMigrationUtils.framework
cp -R "$resources_path"/SystemMigration.framework "$installer_volume_path"/System/Library/PrivateFrameworks/
cp -R "$resources_path"/SystemMigrationUtils.framework "$installer_volume_path"/System/Library/PrivateFrameworks/
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched system migration frameworks."${erase_style}
fi
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching graphics driver."${erase_style}
cp -R "$installer_volume_path"/System/Library/Frameworks/Quartz.framework "$installer_volume_path"/tmp/Quartz-original.framework
cp -R "$resources_path"/Quartz.framework "$installer_volume_path"/tmp/Quartz-patched.framework
rm -R "$installer_volume_path"/tmp/Quartz-patched.framework/Versions/A/Frameworks/QuickLookUI.framework
cp -R "$installer_volume_path"/tmp/Quartz-original.framework/Versions/A/Frameworks/QuickLookUI.framework "$installer_volume_path"/tmp/Quartz-patched.framework/Versions/A/Frameworks/
rm -R "$installer_volume_path"/System/Library/Frameworks/Quartz.framework
cp -R "$installer_volume_path"/tmp/Quartz-patched.framework "$installer_volume_path"/System/Library/Frameworks/Quartz.framework
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched graphics driver."${erase_style}
}
Patch_Unsupported()
{
if [[ $installer_version_short == "10.12" ]]; then
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching installer framework."${erase_style}
rm -R "$installer_volume_path"/System/Library/PrivateFrameworks/OSInstaller.framework
cp -R "$resources_path"/OSInstaller.framework "$installer_volume_path"/System/Library/PrivateFrameworks/
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched installer framework."${erase_style}
fi
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/nonSupportedModels.indexOf(currentModel)>= 0/1 == 0/' "$installer_volume_path"/tmp/OSInstall/Distribution
sed -i '' 's/boardIds.indexOf(boardId)== -1/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 input drivers."${erase_style}
cp -R "$resources_path"/patch/LegacyUSBInjector.kext "$installer_volume_path"/System/Library/Extensions
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched input drivers."${erase_style}
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 cache."${erase_style}
chflags nouchg "$installer_volume_path"/System/Library/PrelinkedKernels/prelinkedkernel
rm "$installer_volume_path"/System/Library/PrelinkedKernels/prelinkedkernel
cp "$installer_prelinkedkernel_path"/prelinkedkernel "$installer_volume_path"/System/Library/PrelinkedKernels
chflags uchg "$installer_volume_path"/System/Library/PrelinkedKernels/prelinkedkernel
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched kernel cache."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching System Integrity Protection."${erase_style}
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 System Integrity Protection."${erase_style}
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"/patch.sh "$installer_volume_path"
cp "$resources_path"/restore.sh "$installer_volume_path"
cp "$resources_path"/runpatch.sh "$installer_volume_path"/usr/bin/patch
cp "$resources_path"/runrestore.sh "$installer_volume_path"/usr/bin/restore
chmod +x "$installer_volume_path"/patch.sh
chmod +x "$installer_volume_path"/restore.sh
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}
}
Modern_Installer()
{
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}"> Creating installer disk."${erase_style}
export installer_application_path
export installer_volume_name
chmod +x "$resources_path"/openinstallmedia.sh
Output_Off "$resources_path"/openinstallmedia.sh -v
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Created installer disk."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Mounting BaseSystem disk image."${erase_style}
Output_Off hdiutil attach -owners on "$installer_sharedsupport_path"/BaseSystem.dmg -mountpoint /tmp/Base\ System -nobrowse -noverify -shadow
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Mounting BaseSystem disk image."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching installer files."${erase_style}
cp "$resources_path"/brtool /tmp/Base\ System/usr/libexec
cp "$resources_path"/OSInstaller /tmp/Base\ System/System/Library/PrivateFrameworks/OSInstaller.framework/Versions/A
cp "$resources_path"/OSInstallerSetupInternal /tmp/Base\ System/"$installer_application_name"/Contents/Frameworks/OSInstallerSetup.framework/Versions/A/Frameworks/OSInstallerSetupInternal.framework/Versions/A
cp "$resources_path"/OSInstallerSetupInternal "$installer_volume_path"/"$installer_application_name"/Contents/Frameworks/OSInstallerSetup.framework/Versions/A/Frameworks/OSInstallerSetupInternal.framework/Versions/A
cp "$resources_path"/osishelperd /tmp/Base\ System/"$installer_application_name"/Contents/Frameworks/OSInstallerSetup.framework/Versions/A/Resources
cp "$resources_path"/osishelperd "$installer_volume_path"/"$installer_application_name"/Contents/Frameworks/OSInstallerSetup.framework/Versions/A/Resources
cp -R "$resources_path"/DisableLibraryValidation.kext /tmp/Base\ System/System/Library/Extensions
cp "$resources_path"/apfsprep.sh /tmp/Base\ System/sbin/apfsprep
chmod +x /tmp/Base\ System/sbin/apfsprep
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched installer files."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching input drivers."${erase_style}
cp -R "$resources_path"/patch/LegacyUSBInjector.kext /tmp/Base\ System/System/Library/Extensions
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched input drivers."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching platform support check."${erase_style}
Output_Off sed -i '' 's|BaseSystem.dmg</string>|BaseSystem.dmg -no_compat_check</string>|' /tmp/Base\ System/Library/Preferences/SystemConfiguration/com.apple.Boot.plist
Output_Off sed -i '' 's|BaseSystem.dmg</string>|BaseSystem.dmg -no_compat_check</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 platform support check."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching kernel cache."${erase_style}
chflags nouchg /tmp/Base\ System/System/Library/PrelinkedKernels/prelinkedkernel
rm /tmp/Base\ System/System/Library/PrelinkedKernels/prelinkedkernel
cp "$installer_prelinkedkernel_path"/prelinkedkernel /tmp/Base\ System/System/Library/PrelinkedKernels
chflags uchg /tmp/Base\ System/System/Library/PrelinkedKernels/prelinkedkernel
chflags nouchg "$installer_volume_path"/System/Library/PrelinkedKernels/prelinkedkernel
rm "$installer_volume_path"/System/Library/PrelinkedKernels/prelinkedkernel
cp "$installer_prelinkedkernel_path"/prelinkedkernel "$installer_volume_path"/System/Library/PrelinkedKernels
chflags uchg "$installer_volume_path"/System/Library/PrelinkedKernels/prelinkedkernel
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched kernel cache."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching System Integrity Protection."${erase_style}
cp -R "$resources_path"/patch/SIPManager.kext /tmp/Base\ System/System/Library/Extensions
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Patched System Integrity Protection."${erase_style}
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"/patch.sh "$installer_volume_path"
cp "$resources_path"/restore.sh "$installer_volume_path"
cp "$resources_path"/runpatch.sh /tmp/Base\ System/usr/bin/patch
cp "$resources_path"/runrestore.sh /tmp/Base\ System/usr/bin/restore
chmod +x "$installer_volume_path"/patch.sh
chmod +x "$installer_volume_path"/restore.sh
chmod +x /tmp/Base\ System/usr/bin/patch
chmod +x /tmp/Base\ System/usr/bin/restore
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Copied patcher utilities."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Unmounting BaseSystem disk image."${erase_style}
Output_Off hdiutil detach /tmp/Base\ System
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Unmounted BaseSystem disk image."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Converting BaseSystem disk image."${erase_style}
mv "$installer_volume_path"/"$installer_application_name"/Contents/SharedSupport/BaseSystem.dmg "$installer_volume_path"/"$installer_application_name"/Contents/SharedSupport/BaseSystem-stock.dmg
Output_Off hdiutil convert -format UDZO "$installer_sharedsupport_path"/BaseSystem.dmg -o "$installer_volume_path"/"$installer_application_name"/Contents/SharedSupport/BaseSystem.dmg -shadow
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Converted BaseSystem disk image."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Mounting InstallESD disk image."${erase_style}
Output_Off hdiutil attach -owners on "$installer_sharedsupport_path"/InstallESD.dmg -mountpoint /tmp/InstallESD -nobrowse -noverify -shadow
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Mounted InstallESD disk image."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Patching installer package."${erase_style}
cp /tmp/InstallESD/Packages/OSInstall.mpkg /tmp
pkgutil --expand /tmp/OSInstall.mpkg /tmp/OSInstall
sed -i '' 's/cpuFeatures\[i\] == "VMM"/1 == 1/' /tmp/OSInstall/Distribution
sed -i '' 's/nonSupportedModels.indexOf(currentModel)>= 0/1 == 0/' /tmp/OSInstall/Distribution
sed -i '' 's/boardIds.indexOf(boardId)== -1/1 == 0/' /tmp/OSInstall/Distribution
pkgutil --flatten /tmp/OSInstall /tmp/OSInstall.mpkg
cp /tmp/OSInstall.mpkg /tmp/InstallESD/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}"> Unmounting InstallESD disk image."${erase_style}
Output_Off hdiutil detach /tmp/InstallESD
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Unmounted InstallESD disk image."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Converting InstallESD disk image."${erase_style}
rm "$installer_volume_path"/"$installer_application_name"/Contents/SharedSupport/InstallESD.dmg
Output_Off hdiutil convert -format UDZO "$installer_sharedsupport_path"/InstallESD.dmg -o "$installer_volume_path"/"$installer_application_name"/Contents/SharedSupport/InstallESD.dmg -shadow
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Converting InstallESD disk image."${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/my.target.filesystem && my.target.filesystem.type == 'hfs'/1 == 0/" "$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}
}
Update_Patched_Installer()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Updating patcher utilities."${erase_style}
rm -R "$installer_volume_path"/patch
cp -R "$resources_path"/patch "$installer_volume_path"/
cp "$resources_path"/patch.sh "$installer_volume_path"
cp "$resources_path"/restore.sh "$installer_volume_path"
chmod +x "$installer_volume_path"/patch.sh
chmod +x "$installer_volume_path"/restore.sh
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Updating patcher utilities."${erase_style}
}
End()
{
echo -e $(date "+%b %m %H:%M:%S") ${text_progress}"> Removing temporary files."${erase_style}
Output_Off rm -R "$installer_volume_path"/tmp/macOS\ Installer-original.app
Output_Off rm -R "$installer_volume_path"/tmp/macOS\ Installer-patched.app
Output_Off rm -R "$installer_volume_path"/tmp/Quartz-original.framework
Output_Off rm -R "$installer_volume_path"/tmp/Quartz-patched.framework
Output_Off rm -R "$installer_volume_path"/tmp/OSInstall
Output_Off rm -R "$installer_volume_path"/tmp/OSInstall.mpkg
if [[ $installer_version_short == "10.15" ]]; then
Output_Off rm -R /tmp/OSInstall
Output_Off rm -R /tmp/OSInstall.mpkg
rm "$installer_sharedsupport_path"/BaseSystem.dmg.shadow
rm "$installer_sharedsupport_path"/InstallESD.dmg.shadow
fi
echo -e $(date "+%b %m %H:%M:%S") ${move_up}${erase_line}${text_success}"+ Removed temporary files."${erase_style}
echo -e $(date "+%b %m %H:%M:%S") ${text_message}"/ Thank you for using macOS Patcher."${erase_style}
Input_On
exit
}
Input_Off
Escape_Variables
Parameter_Variables
Path_Variables
Check_Environment
Check_Root
Check_Resources
Input_Operation
End