-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathmacOS-eGPU.sh
More file actions
4966 lines (4355 loc) · 158 KB
/
macOS-eGPU.sh
File metadata and controls
4966 lines (4355 loc) · 158 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
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# macOS-eGPU.sh
#
# This script handles installation, updating and uninstallation of eGPU support for Mac.
# AMD and NVIDIA cards, TI82 and T83 enclosures, TB 1/2 and 3, and CUDA are supported.
#
# Created by learex on 05.04.18.
#
# Authors: learex
# Homepage: https://github.com/learex/macOS-eGPU
# License: https://github.com/learex/macOS-eGPU/blob/master/License.txt
#
# USAGE TERMS of macOS-eGPU.sh
# 1. You may use this script for personal use.
# 2. You may continue development of this script at it's GitHub homepage.
# 3. You may not redistribute this script or portions thereof from outside of it's GitHub homepage without explicit written permission.
# 4. You may not compile, assemble or in any other way make the source code unreadable by a human.
# 5. You may not implement this script or portions thereof into other scripts and/or applications without explicit written permission.
# 6. You may not use this script, or portions thereof, for any commercial purposes.
# 7. You accept the license terms of all downloaded and/or executed content, even content that has only indirectly been been downloaded and/or executed by macOS-eGPU.sh.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# beginning of the script
# It is forbidden to execute any code until the very last subroutine. The only execption is to parse incoming options.
# Global variables are created as needed.
# script specific information
branch="master"
warningOS="10.13.7"
currentOS="10.13.6"
gitPath="https://raw.githubusercontent.com/learex/macOS-eGPU/""$branch"
scriptVersion="v1.6"
debug=false
# external programs
pbuddy="/usr/libexec/PlistBuddy"
# sudo override
sudoActive=false
function sudov {
if "$sudoActive"
then
sudo "$@"
else
"$@"
fi
}
# Subroutine A: Basic functions ##############################################################################################################
## Subroutine A1: Directory handling
dirName="$(uuidgen)"
dirName="/var/tmp/""macOS.eGPU.""$dirName"
## tmpdir creator
function mktmpdir {
if ! [ -d "$dirName" ]
then
mkdir -p "$dirName"
fi
}
## tmpdir destructor
function cleantmpdir {
if [ -d "$dirName" ]
then
sudov rm -rf "$dirName"
fi
}
## Subroutine A2: Cleanup
# DMG detachment
attachedDMGVolumes=""
function dmgDetatch {
while read -r DMGVolumeToDetachTemp
do
if [ -d "$DMGVolumeToDetachTemp" ]
then
hdiutil detach "$DMGVolumeToDetachTemp" -quiet
fi
done <<< "$attachedDMGVolumes"
}
# system cleanup
function systemClean {
echoing " cleaning system"
cleantmpdir
dmgDetatch
echoend "done"
}
# quit all running apps
function quitAllApps {
ret=0
if ! "$debug"
then
appsToQuitTemp=""
appsToQuitTemp=$(osascript -e 'tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder" and name is not "Terminal"' -e 'return quitapps') &>/dev/null
if ( ! [[ "$appsToQuitTemp" == "" ]] ) || [[ `ps -A | grep "\-bash" | grep -v "grep" | wc -l | xargs` > 1 ]]
then
if [[ "$appsToQuitTemp" =~ "iTerm" ]]
then
echo
echo "An open session of iTerm is detected. The script won't run with iTerm. Please use the Terminal app for now."
irupt
fi
if [[ `ps -A | grep "\-bash" | grep -v "grep" | wc -l | xargs` > 1 ]]
then
echo
echo
echo `ps -A | grep "\-bash" | grep -v "grep" | wc -l | xargs`" Terminal sessions have been detected. Please only leave one open with which the script is executed."
echo
irupt
fi
appsToQuitTemp="${appsToQuitTemp//, /\n}"
appsToQuitTemp="$(echo -e $appsToQuitTemp)"
while read -r appNameToQuitTemp
do
killall "$appNameToQuitTemp"
if [ "$?" != 0 ]
then
ret=1
fi
done <<< "$appsToQuitTemp"
fi
fi
return "$ret"
}
## Subroutine A3: Print functions
# print the whole help manual
function printUsage {
printVariableTemp=`cat <<EOF
bash <(curl -s https://raw.githubusercontent.com/learex/macOS-eGPU/master/macOS-eGPU.sh) [parameter]
Parameters are optional. If none are provided, the script will self determine what to do.
--- Basic ---
--install | -i
Tells the script to install/update eGPU software. (internet may be required)
The install parameter tells the script to fetch your Mac’s parameters
(such as installed software, installed patches, macOS version etc.)
and to fetch the newest software versions. It then cross-references and
deducts what needs to be done. This includes all packages listed below.
This works best on new systems or systems that have been updated.
Deductions on corrupt systems are limited.
Note that earlier enablers for 10.12 won’t be touched.
If you have used such software you must uninstall it yourself.
To override deductions use the #Package parameters below.
--uninstall | -U
Tells the script to uninstall eGPU software.
The uninstall parameter tells the script to search for eGPU software and
fully uninstall it. Note that earlier enablers for 10.12 won’t be touched.
If you have used such software you must uninstall it yourself. Note that
only one thing won’t be uninstalled: The short command.
To uninstall this one as well execute: sudo rm /usr/local/bin/macos-egpu
To override deductions use the #Package parameters below.
--checkSystem | -C
Tells the script to gather system information.
The check system command outputs basic information about eGPU software
as well as basic system information.
--checkSystemFull
Tells the script to gather all available system information.
The check full system command outputs all possible information about
eGPU software as well as system information.
--- Packages ---
--nvidiaDriver [revision] | -n [revision]
Specify that the NVIDIA drivers shall be touched.
The NVIDIA driver parameter tells the script to perform either an install
or uninstall of the NVIDIA drivers. If the script determines that the
currently installed NVIDIA driver shall be used after an update it will
patch it. One can optionally specify a custom driver revision.
The specified revision will automatically be patched, if necessary.
--amdLegacyDriver | -a
Specify that the AMD legacy drivers shall be touched. (drivers by @goalque)
The AMD legacy driver parameter tells the script to make older AMD graphics
cards compatible with macOS 10.13.X
These include:
Polaris - RX: 460, 560 | Radeon Pro: WX5100, WX4100
Fiji - R9: Fury X, Fury, Nano
Hawaii - R9: 390X, 390, 290X, 290
Tonga - R9: 380X, 380, 285
Pitcairn - R9: 370X, 270X, 270 | R7: 370, 265 | FirePro: W7000
Tahiti - R9: 280x, 280 | HD: 7970, 7870, 7850
--nvidiaEGPUsupport | -e
Specify that the NVIDIA eGPU support shall be touched. (kext by yifanlu)
The NVIDIA eGPU support parameter tells the script to make the
NVIDIA drivers compatible with an NVIDIA eGPU. Therefore NVIDIA drivers
must be installed in order to be applied.
This command is for 10.13.5≤ only.
On macOS 10.13.4/10.13.5 an additional patch is necessary.
See --unlockNvidia.
--deactivateNvidiaDGPU | -d
Not yet available. Only for AMD eGPU users. patch by @mac_editor
--unlockThunderboltV12 | -V
Specify that thunderbolt versions 1 and 2 shall be unlocked
for use of an eGPU. (patch by @mac_editor, @fricorico)
The unlock thunderbolt v1, v2 parameter tells the script to make older Macs
with thunderbolt ports of version 1 or 2 compatible for eGPU use.
For NVIDIA users this is required only for macOS 10.13.4/10.13.5.
For AMD users this is required for macOS 10.13.4+.
--thunderboltDaemon | -A
Specify that thunderbolt options shall be applied.
The thunderbolt daemon parameter tells the script to create a launch daemon
including the thunderbolt arguments. These arguments are reset after each
boot which is why a daemon is necessary to keep them up to date. This is
beneficial for NVIDIA dGPUs and multi eGPU setups.
--unlockNvidia | -N
Specify that NVIDIA eGPU support shall be unlocked.
(patch by @fr34k, @goalque)
The unlock NVIDIA parameter tells the script to make the Mac
compatible with NVIDIA eGPUs.
This is only required for macOS 10.13.4 and macOS 10.13.5.
This might cause issues/crashes with AMD graphics cards (external).
--iopcieTunneledPatch | -l
Specify that NVIDIA eGPU support shall be unlocked. (patch by @goalque)
The IOPCITunnelled Patch tells the script to make the Mac
compatible with NVIDIA eGPUs.
This is only required for macOS 10.3.6+.
This might cause issues/crashes with AMD graphics cards (external).
--unlockT82 | -T
Specify that the T82 chipsets shall be unlocked.
The unlock T82 parameter tells the script to make the Mac compatible
with T82 eGPU enclosures. This is not reduced to eGPU enclosures all
thunderbolt enclosures with T82 chipset will work.
--cudaDriver | -c
Specify that CUDA drivers shall be touched.
The CUDA driver parameter tells the script to perform either an install
or uninstall of the CUDA drivers. Note that the CUDA driver is dependent
on the NVIDIA drivers and cannot be installed without latter.
Note that the toolkit and samples are dependent on the drivers.
Uninstalling them will cause the script
to uninstall the toolkit and samples as well.
--cudaDeveloperDriver | -D
Specify that CUDA developer drivers shall be touched.
The CUDA developer drivers parameter tells the script to perform either
an install or uninstall of the CUDA developer drivers. Note that the
CUDA driver is dependent on the NVIDIA drivers and cannot be installed
without latter. Note that the toolkit and samples are dependent on the
developer/drivers. Uninstalling them will cause the script
to uninstall the toolkit and samples as well.
This should theoretically be identical to --cudaDriver
--cudaToolkit | -t
Specify that CUDA toolkit shall be touched.
The CUDA toolkit parameter tells the script to perform either an install
or uninstall of the CUDA toolkit. Note that the samples are dependent on
the toolkit and the toolkit itself depends on the drivers. Uninstalling the
toolkit will cause the script to uninstall the samples as well. Installing
the toolkit will cause the script to install the drivers as well.
--cudaSamples | -s
Specify that CUDA samples shall be touched.
The CUDA samples parameter tells the script to perform either an install or
uninstall of the CUDA samples. Note that the samples are dependent on the
toolkit and drivers. Installing the samples will cause the script to
install the drivers and toolkit as well.
--- Advanced ---
--fullInstall | -F
Select all #Packages. This might cause issues.
Read the descriptions of the #Packages as well.
--forceReinstall | -R
Specify that the script shall reinstall already installed software.
The force reinstall parameter tells the script to reinstall all software
regardless if it already is up to date.
This does not influence deductions or other installations.
--useForce | -o
Specify that force shall be used.
In some rare cases the script might not detect the presence of
installed software. This is most likely due to faulty installations. Using
force skips security checks for uninstalls.
Therefore use with highest caution.
It must be used in conjunction with a package name and --uninstall.
--forceNewest | -f
Specify that the script shall install only newest software.
The force newest parameter tells the script to prefer newer instead of more
stable software. This might resolve and/or cause issues.
--forceCacheRebuild | -E
Specify that the caches shall be rebuild.
The force cache rebuild flag rebuilds the kext, system and dyld cache.
This option cannot be paired with other options.
--noReboot | -r
Specify that even if something has been done no reboot shall be performed.
--acceptLicenseTerms
Specify that the question of whether the license terms have been accepted
shall be automatically answered with yes and then skipped.
--skipWarnings | -k
Specify that the initial warnings of the script shall be skipped.
--beta
Specify that an unsupported version of macOS in use.
The beta flag removes checks for script requirements. Therefore, it is
useful for beta testers. However, since these versions weren't checked by
experienced users, the risk of damaging the system is extremely high.
Only use with caution and backup.
--help | -h
Print this help document
--- Example with parameters ---
bash <(curl -s https://raw.githubusercontent.com/learex/macOS-eGPU/master/macOS-eGPU.sh) --install --nvidiaDriver 387.10.10.10.30.106
macos-egpu --install --nvidiaDriver 387.10.10.10.30.106
--- Issues ---
Please visit https://github.com/learex/macOS-eGPU#problems
EOF
`
echo "$printVariableTemp"
}
# print the short instructions for pro users
function printShortHelp {
printVariableTemp=`cat <<EOF
bash <(curl -s https://raw.githubusercontent.com/learex/macOS-eGPU/master/macOS-eGPU.sh) [parameter]
parameter:
--install | -i | --uninstall | -U
--checkSystem | -C | --checkSystemFull
--nvidiaDriver [rev] | -n [rev] | --amdLegacyDriver | -a
--nvidiaEGPUsupport | -e | --deactivateNvidiaDGPU | -d
--unlockThunderboltV12 | -V | --unlockNvidia | -N
--unlockT82 | -T | --iopcieTunneledPatch | -l
--cudaDriver | -c | --cudaDeveloperDriver | -D
--cudaToolkit | -t | --cudaSamples | -s
--thunderboltDaemon | -A
--fullInstall | -F | --forceReinstall | -R
--forceNewest | -f | --useForce | -o
--noReboot | -r | --acceptLicenseTerms
--skipWarnings | -k | --help | -h
--beta | --forceCacheRebuild | -E
EOF
`
echo "$printVariableTemp"
}
# print license
function printLicense {
printVariableTemp=`cat <<EOF
USAGE TERMS of macOS-eGPU.sh
# 1. You may use this script for personal use.
# 2. You may continue development of this script at it's GitHub homepage.
# 3. You may not redistribute this script or portions thereof from outside of it's GitHub homepage without explicit written permission.
# 4. You may not compile, assemble or in any other way make the source code unreadable by a human.
# 5. You may not implement this script or portions thereof into other scripts and/or applications without explicit written permission.
# 6. You may not use this script, or portions thereof, for any commercial purposes.
# 7. You accept the license terms of all downloaded and/or executed content, even content that has only indirectly been been downloaded and/or executed by macOS-eGPU.sh.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
EOF
`
echo "$printVariableTemp"
}
## Subroutine A4: Waiter
function waiter {
for i in `seq "$1" 1`
do
echo -n "$i"".."
sleep 1
done
echo "0"
}
## Subroutine A5: Aquire elevated privileges
function elevatePrivileges {
if "$sudoActive" || [ "$(id -u)" == 0 ]
then
sudo -v
if [ "$?" != 0 ]
then
echoend "FAILURE" 1
echo "Elevated privileges could not be aquired. The script will now stop."
irupt
fi
else
sudo -k
echo " elevating privileges"
echo -n " "
lastLength=12
sudo -v
if [ "$?" != 0 ]
then
echoing " checking for elevated privileges"
echoend "FAILURE" 1
echo "Elevated privileges could not be aquired. The script will now stop."
irupt
fi
echoing " checking for elevated privileges"
echoend "OK" 2
fi
sudoActive=true
}
## Subroutine A6: Restore privileges
function restorePrivileges {
sudo -k
}
## Subroutine A7: Reboot
scheduleReboot=false
noReboot=false
function rebootSystem {
if ! "$scheduleReboot" || "$noReboot" || "$debug"
then
echo "A reboot of the system is recommended."
else
echo "A reboot will soon be performed..."
elevatePrivileges
trap '{ echo; echo "Abort..."; systemClean; restorePrivileges; exit 1; }' INT
waiter 5
echo "reboot: / is busy updating, waiting for lock (this might take approx 15-30s)..."
sudo reboot & &>/dev/null
sleep 1
fi
echo
restorePrivileges
exit
}
## Subroutine A8: Rebuild Kexts
scheduleKextTouch=false
forceCacheRebuild=false
function rebuildKextCache {
if "$scheduleKextTouch"
then
echo "Rebuilding caches"
elevatePrivileges
trapWithWarning2
echoing " kext cache"
sudo touch /System/Library/Extensions &>/dev/null
sudo kextcache -q -update-volume / &>/dev/null
echoend "done"
echoing " system cache"
sudo touch /System/Library/Extensions &>/dev/null
sudo kextcache -system-caches &>/dev/null
sudo kextcache -clear-staging
echoend "done"
if "$forceCacheRebuild"
then
echoing " dyld cache"
sudo update_dyld_shared_cache -root / -force &>/dev/null
sudo update_dyld_shared_cache -debug &>/dev/null
sudo update_dyld_shared_cache &>/dev/null
echoend "done"
fi
fi
}
## Subroutine A9: Finish
doneSomething=false
function finish {
createSpace 2
echo "Finish..."
systemClean
if "$doneSomething"
then
rebuildKextCache
rebootSystem
else
echo "Nothing has been changed."
fi
restorePrivileges
echo
exit
}
## Subroutine A10: Interrupt
function irupt {
echo "Interrupt..."
systemClean
restorePrivileges
echo "The script has failed."
if "$doneSomething"
then
rebuildKextCache
else
echo "Nothing has been changed."
fi
echo
exit 1
}
## Subroutine A11: Trap functions
exitScript=false
function trapIrupt {
if ! "$exitScript"
then
exitScript=true
echo "You pressed ^C. Exiting the script during execution might render your system unrepairable."
echo "Recommendation: Let the script finish and then run again with uninstall parameter."
echo "Press again to force quit. Beware of the consequenses."
sleep 5
else
irupt
fi
}
function trapIrupt2 {
if ! "$exitScript"
then
exitScript=true
echo "You pressed ^C. Exiting the script during execution might render your system unrepairable."
echo "Recommendation: Let the script finish and then run again with uninstall parameter."
echo "Press again to force quit. Beware of the consequenses."
sleep 5
else
trap '{ echo; echo "Abort..."; systemClean; restorePrivileges; exit 1; }' INT
fi
}
function trapWithWarning {
trap trapIrupt INT
}
function trapWithWarning2 {
trap trapIrupt2 INT
}
function trapWithoutWarning {
trap '{ echo; echo "Abort..."; irupt; }' INT
}
function trapLock {
trap '' INT
}
## Subroutine A12: Custom uninstaller
function genericUninstaller {
fileListUninstallTemp="$1"
genericUninstalledTemp=false
if [ "$fileListUninstallTemp" != "" ]
then
elevatePrivileges
while read -r genericFileTemp
do
if [ -e "$genericFileTemp" ]
then
genericUninstalledTemp=true
sudo rm -r -f "$genericFileTemp" &>/dev/null
fi
done <<< "$fileListUninstallTemp"
if "$genericUninstalledTemp"
then
return 0
else
return 1
fi
fi
}
## Subroutine A13: Binary Hasher
binaryHashReturn=""
function binaryHasher {
testDump=$(hexdump -ve '1/1 "%.2X"' "$1" &>/dev/null)
if [ $? != 0 ]
then
echo
echo "iterupting execution flow..."
echo "--- incorrect permissions detected ---"
elevatePrivileges
sudo chmod 755 "$1"
echo "--- incorrect permissions fixed ---"
echo "continuing execution flow..."
echo
fi
hashval1Temp=$(hexdump -ve '1/1 "%.2X"' "$1" | sed "s/.*3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D225554462D38223F3E0A3C21444F435459504520706C697374205055424C494320222D2F2F4170706C652F2F44544420504C49535420312E302F2F454E222022687474703A2F2F7777772E6170706C652E636F6D2F445444732F50726F70657274794C6973742D312E302E647464223E0A3C706C6973742076657273696F6E3D22312E30223E0A3C646963743E0A093C6B65793E63646861736865733C2F6B65793E//g")
hashval2Temp=$(xxd -s -128 "$1")
hashvalTemp=$(echo "$hashval1Temp""$hashval2Temp" | shasum -a 512 -b | awk '{ print $1 }')
binaryHashReturn="$hashvalTemp"
}
## Subroutine A14: Flow hex editor
function genericHexEditor {
elevatePrivileges
(sudo hexdump -ve '1/1 "%.2X"' "$3" | sed "s/$1/$2/g" | xxd -r -p )> "$4"
}
## Subroutine A15: Inplace hex editor
function inPlaceEditor {
elevatePrivileges
mktmpdir
tempBinaryPath="$dirName""/binFile"
filePermissionsTemp=$(stat -f "%A" "$3")
fileOwnershipTemp=$(stat -f "%Su:%Sg" "$3")
genericHexEditor "$1" "$2" "$3" "$tempBinaryPath"
sudo rm "$3"
sudo cp "$tempBinaryPath" "$3"
sudo chmod "$filePermissionsTemp" "$3"
sudo chown "$fileOwnershipTemp" "$3"
sudo rm "$tempBinaryPath"
}
## Subroutine A16: Echo helpers
lastLength=0
doneLine=`expr $(tput cols)`
function echoing {
echo -n "$1"
lastLength=`echo -n "$1" | wc -c | xargs`
}
function echoend {
lenTemp=`echo -n "$1" | wc -c | xargs`
for i in `seq 1 $(expr "$doneLine" - $lenTemp - 2 - "$lastLength")`
do
echo -n " "
done
if [ "$2" != "" ]
then
tput setaf "$2"
fi
echo "[$1]"
if [ "$2" != "" ]
then
tput sgr0
fi
}
function createSpace {
for i in `seq 1 $1`
do
echo
done
}
## Subroutine A17: binary parser
function binaryParser {
nbitTemp=`dc -e "$1 2 $2 ^ / 2 % n"`
if [ "$nbitTemp" != "$3" ]
then
if [ "$nbitTemp" == 1 ]
then
dc -e "$1 2 $2 ^ - n"
else
dc -e "$1 2 $2 ^ + n"
fi
else
echo "$1"
fi
}
# Subroutine B: System checks ##############################################################################################################
os=""
build=""
function fetchOSinfo {
os="$(sw_vers -productVersion)"
build="$(sw_vers -buildVersion)"
}
# 0: completely disabled, 127: fully enabled, 128: error, 31: --without KEXT
# Binary of: Apple Internal | Kext Signing | Filesystem Protections | Debugging Restrictions | DTrace Restrictions | NVRAM Protections | BaseSystem Verification
statSIP=128
function fetchSIPstat {
SIPTemp="$(csrutil status)"
if [[ "$SIPTemp[@]" =~ "Custom Configuration" ]]
then
appleInternalTemp=`echo "$SIPTemp" | sed -n 4p`
kextSigningTemp=`echo "$SIPTemp" | sed -n 5p`
fileSystemProtectionsTemp=`echo "$SIPTemp" | sed -n 6p`
debuggingRestrictionsTemp=`echo "$SIPTemp" | sed -n 7p`
dTraceRestrictionsTemp=`echo "$SIPTemp" | sed -n 8p`
nvramProtectionsTemp=`echo "$SIPTemp" | sed -n 9p`
baseSystemVerificationTemp=`echo "$SIPTemp" | sed -n 10p`
appleInternalTemp="${appleInternalTemp##*: }"
kextSigningTemp="${appleInternalTemp##*: }"
fileSystemProtectionsTemp="${fileSystemProtectionsTemp##*: }"
debuggingRestrictionsTemp="${debuggingRestrictionsTemp##*: }"
dTraceRestrictionsTemp="${dTraceRestrictionsTemp##*: }"
nvramProtectionsTemp="${nvramProtectionsTemp##*: }"
baseSystemVerificationTemp="${baseSystemVerificationTemp##*: }"
pTemp=1
statSIP=0
for SIPXTemp in "$baseSystemVerificationTemp" "$nvramProtectionsTemp" "$dTraceRestrictionsTemp" "$debuggingRestrictionsTemp" "$fileSystemProtectionsTemp" "$kextSigningTemp" "$appleInternalTemp"
do
if [ "$SIPXTemp" == "enabled" ]
then
statSIP="$(expr $statSIP + $pTemp)"
fi
pTemp="$(expr $pTemp \* 2)"
done
else
keywordTemp="${SIPTemp#*: }"
if [[ "${keywordTemp%% *}" =~ "enabled" ]]
then
statSIP=127
else
statSIP=0
fi
fi
}
thunderboltInterface=0
function fetchThunderboltInterface {
thunderboltTemp=`ioreg | grep AppleThunderboltNHIType | sed -n 1p`
thunderboltTemp="${thunderboltTemp##*+-o AppleThunderboltNHIType}"
thunderboltInterface="${thunderboltTemp::1}"
if [ "$thunderboltInterface" == "" ]
then
thunderboltInterface=0
fi
}
nvidiaDGPU=false
function fetchNvidiaDGPU {
nvidiaDGPU=false
displayListTemp=$(system_profiler SPDisplaysDataType | grep -v ": " | grep " " | xargs)
displayListTemp="$displayListTemp"" "
displayListTemp="${displayListTemp//: /\n}"
displayListTemp=$(echo -e -n "$displayListTemp")
pcieListTemp=$(system_profiler SPPCIDataType | grep -v ": " | grep " " | xargs)
pcieListTemp="$pcieListTemp"" "
pcieListTemp="${pcieListTemp//: /\n}"
pcieListTemp=$(echo -e -n "$pcieListTemp")
listOfPossibleDGPUTemp=""
while read -r displayTemp
do
matchTemp=false
while read -r pcieTemp
do
if [[ "$displayTemp" == "$pcieTemp" ]]
then
matchTemp=true
fi
done <<< "$pcieListTemp"
if ! "$matchTemp"
then
listOfPossibleDGPUTemp="$listOfPossibleDGPUTemp""$displayTemp""\n"
fi
done <<< "$displayListTemp"
listOfPossibleDGPUTemp=$(echo -e -n "$listOfPossibleDGPUTemp")
if [[ "$listOfPossibleDGPUTemp[@]" =~ "NVIDIA" ]]
then
nvidiaDGPU=true
fi
}
connectedEGPU=false
connectedEGPUVendor=""
eGPUdriverInstalled=""
function fetchConnectedEGPU {
ret=0
connectedEGPU=false
pciTemp=`system_profiler SPPCIDataType`
vendorsTemp=`echo "$pciTemp" | grep "Vendor" | grep -v "Subsystem"`
usedSlotsTemp=`echo "$pciTemp" | grep "Slot"`
countTemp=`echo "$vendorsTemp" | wc -l | xargs`
countTemp2=`echo "$usedSlotsTemp" | wc -l | xargs`
if [ "$countTemp" == "$countTemp2" ]
then
for i in `seq 1 "$countTemp"`
do
usedSlotTemp=`echo "$usedSlotsTemp" | sed -n "$i"p`
vendorTemp=`echo "$vendorsTemp" | sed -n "$i"p`
if [[ "$usedSlotTemp" =~ "Thunderbolt" ]]
then
case "$vendorTemp"
in
*"0x10de"*)
connectedEGPU=true
connectedEGPUVendor="NVIDIA"
;;
*"0x1002"*)
connectedEGPU=true
connectedEGPUVendor="AMD"
;;
*)
;;
esac
fi
done
else
ret=1
fi
return "$ret"
}
appleGPUWranglerVersion=""
function translateAppleGPUWranglerVersionHash {
appleGPUWranglerVersion=""
case "$1"
in
"6606536cd546fbaf6571e3f6e0a815e4e9b06e135812322c7d2a899cffb42ca3a3fc7ef248cb81ae82c558a761bb75c9d852c38e744686ce1b38ad108d269c51")
appleGPUWranglerVersion="10.13.2:17C88,17C89,17C205,17C2120,17C2205"
;;
"ea9dc6330ba9be64e0403e1b2d30db5483ff117ea2ceb37d90ce6671768a3d13200ceb29f2336a4a908e7665a461187ee3afc214fea4bc01ae2bbfd1b3dfe231")
appleGPUWranglerVersion="10.13.3:17D47,17D102"
;;
"c13a0bf6c3215b65430242b588f2039f5943c97ada42b3a176de30417b2ab79f3996401e60cbd956b8de63303c282ded8fa1667c64ec3eb241dcc84d86b33241")
appleGPUWranglerVersion="10.13.3:17D2047,17D2102,17D2104"
;;
"5cecaea9a06812f195e9c6ce6f755a20c623dc8e12222eaee0118c8f8a0fe42e3167d206eb85d5a55ceeeaa9aa55cd9b13433294a3d5de4f9d24f93e07dd67f6")
appleGPUWranglerVersion="10.13.4:17E199"
;;
"459cba0c4c96cd751ff5d69857901a550ebcd99929d75860d864ae3950a6a1250e30d88ebae0823dfc1544b05b94c3b9b0c1cdfaeb74735d8c69a9438ddf66b4")
appleGPUWranglerVersion="10.13.4:17E202"
;;
"88411a9cb7d0949fb2eb688281729edbd06f34e41e051a5fb37bf31bd3dbfe6f3d36bfb8917249a4717409417e761b588e7cabad0944602255836b2c1cce4849")
appleGPUWranglerVersion="10.13.5:17F77"
;;
"51b5608fc6918f7a3b7edc263e721199109663739be260481ef9b6c14747736407cdfc61290f5ae9030aff35718944777828e5fdd0bb5da2674e998ea534f47c")
appleGPUWranglerVersion="10.13.6:17G65"
;;
"379e758646c6000fc337ff6b8d88db82eb45d321a6f36e40dfa3354755504abcc7460ff0fe96a97aa2ae58ffce6b4cf5ea98f3ba008900591e481692547956e6")
appleGPUWranglerVersion="10.13.6:17G2112"
;;
"befcbf75dbb4f0c3a9e79d333fef6b6c25a42b929878a572c73c448c01ff8dfdb66eabd02397e9fd1f8f3d4c0fc0c844f7cd0b29e4730314814f657fd20f544e")
appleGPUWranglerVersion="10.13.6:17G2208"
;;
esac
}
appleGraphicsControlPath="/System/Library/Extensions/AppleGraphicsControl.kext"
appleGPUwranglerPath="$appleGraphicsControlPath""/Contents/PlugIns/AppleGPUWrangler.kext"
appleGPUwranglerBinaryPath="$appleGPUwranglerPath""/Contents/MacOS/AppleGPUWrangler"
function fetchAppleGPUWranglerVersion {
binaryHasher "$appleGPUwranglerBinaryPath"
translateAppleGPUWranglerVersionHash "$binaryHashReturn"
}
programList=""
function fetchInstalledPrograms {
appListPathsTemp="$(find /Applications -iname *.app -maxdepth 3)"
appListTemp=""
while read -r appTemp
do
appTemp="${appTemp##*/}"
appListTemp="$appListTemp""${appTemp%.*}""\n"
done <<< "$appListPathsTemp"
programList="$(echo -e -n $appListTemp)"
}
internet=false
function checkInternetConnection {
internet=false
/sbin/ping 1.1.1.1 -c 1 -t 3 &> /dev/null
if [ "$?" == 0 ]
then
internet=true
fi
}
# Subroutine C: NVIDIA drivers ##############################################################################################################
## Subroutine C1: Global variables
nvidiaDriversInstalled=false
nvidiaDriverVersion=""
nvidiaDriverBuildVersion=""
nvidiaDriverUnInstallPKG="/Library/PreferencePanes/NVIDIA Driver Manager.prefPane/Contents/MacOS/NVIDIA Web Driver Uninstaller.app/Contents/Resources/NVUninstall.pkg"
nvidiaDriverVersionPath="/Library/Extensions/NVDAStartupWeb.kext/Contents/Info.plist"
nvidiaDriverNListOnline="https://gfe.nvidia.com/mac-update"
nvidiaDriverListOnline="$gitPath""/Data/nvidiaDriver.plist"
foundMatchNvidiaDriver=false
customNvidiaDriver=false
forceNewest=false
omitNvidiaDriver=false
nvidiaDriverDownloadVersion=""
nvidiaDriverDownloadLink=""
nvidiaDriverDownloadChecksum=""
## Subroutine C2: Check functions
function checkNvidiaDriverInstallReset {
nvidiaDriversInstalled=false
nvidiaDriverVersion=""
nvidiaDriverBuildVersion=""
}
function checkNvidiaDriverInstall {