forked from toleda/audio_RealtekALC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio_realtekALC-100.sh
executable file
·1148 lines (965 loc) · 35.2 KB
/
audio_realtekALC-100.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
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/sh
# Maintained by: toleda for: github.com/toleda/audio_realtekALC
gFile="File: audio_realtekALC-110.command_v1.0e"
# Credit: bcc9, RevoGirl, PikeRAlpha, SJ_UnderWater, RehabMan, TimeWalker, lisai9093
#
# OS X Realtek ALC Onboard Audio
#
# Enables OS X Realtek ALC onboard audio in 10.11, 10.10, 10.9 and 10.8, all versions
# 1. Supports Realtek ALC885, 887, 888, 889, 892, 898 and 1150
# 2. Patches native AppleHDA.kext installed in System/Library/Extensions
#
# Requirements
# 1. OS X: 10.11/10.10/10.9/10.8, all versions
# 2. Native AppleHDA.kext (If not installed, run Mavericks installer)
# 3. Supported Realtek ALC on board audio codec (see above)
# 4. Audio ID: 1, 2 or 3 Injection, see https://github.com/toleda/audio_ALCinjection
#
# Installation
# 1. Double click audio_cloverALC-110.command
# 2. Enter password at prompt
# 3. Confirm Realtek ALC . . . (y/n): (885, 887, 888, 889, 892, 898, 1150 only)
# 4. Enable HD4600 HDMI audio (y/n): (887, 892, 898, 1150 only)
# 5. Restart
#
# Change log:
# v1.0a - 6/15/15: 1. Initial 10.11 support
# v1.0b - 6/17/15: file name typo
# v1.0c - not applicable
# v1.0d - 7/31/15: add SID verification, fix copy extended attributes error
#
echo " "
echo "Agreement"
echo "The audio_realtekALC-110 script is for personal use only. Do not distribute"
echo "the patch, any or all of the files or the resulting patched AppleHDA.kext"
echo "for any reason without permission. The audio_realtekALC-110 script is"
echo "provided as is and without any kind of warranty."
echo " "
# set initial variables
gSysVer=`sw_vers -productVersion`
gSysName="Mavericks"
gStartupDisk=EFI
gCloverDirectory="/Volumes/$gStartupDisk/EFI/CLOVER"
gDesktopDirectory=/Users/$(whoami)/Desktop
gExtensionsDirectory=/System/Library/Extensions
gHDAContentsDirectory=$gExtensionsDirectory/AppleHDA.kext/Contents
gHDAHardwarConfigDirectory=$gHDAContentsDirectory/Plugins/AppleHDAHardwareConfigDriver.kext/Contents
gHDAControllerbinaryDirectory=$gHDAContentsDirectory/Plugins/AppleHDAController.kext/Contents/MacOS
gAudioid=1
gLayoutid=1
gPatch="-toledaALC"
gCodec=892
gLegacy=n
gController=n
gMake=0
gDebug=0
# gCodecsinstalled
# gCodecVendor
# gCodecDevice
# gCodecName
# gCodec
gCloverALC=0
gRealtekALC=1
gAudioidvalid=n
gCodecvalid=n
# debug
if [ $gDebug = 1 ]; then
echo "gMake = $gMake"
echo "gCloverALC = $gCloverALC"
echo "gRealtekALC = $gRealtekALC"
# while true
# do
# read -p "OK (y/n): " choice3
# case "$choice3" in
# [yY]* ) break;;
# [nN]* ) exit;;
# * ) echo "Try again...";;
# esac
# done
fi
# verify system version
case ${gSysVer} in
10.11* ) gSysName="El Capitan"
gSysFolder=kexts/10.11
gSID=$(csrutil status)
;;
10.10* ) gSysName="Yosemite"
gSysFolder=kexts/10.10
;;
10.9* ) gSysName="Mavericks"
gSysFolder=kexts/10.9
;;
10.8* ) gSysName="Mountain Lion"
gSysFolder=kexts/10.8
;;
* )
echo "OS X Version: $gSysVer is not supported"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
;;
esac
# debug
if [ $gDebug = 1 ]; then
# gSysVer=10.9
echo "System version: supported"
echo "gSysVer = $gSysVer"
fi
echo "File: $gFile"
# debug
if [ $gMake = 1 ]; then
if [ -d "$gDesktopDirectory/AppleHDA.kext" ]; then
sudo rm -R $gExtensionsDirectory/AppleHDA.kext
case $gSysName in
"El Capitan" )
sudo cp -X $gDesktopDirectory/AppleHDA.kext $gExtensionsDirectory/AppleHDA.kext
;;
"Yosemite"|"Mavericks"|"Mountain Lion" )
sudo cp -R $gDesktopDirectory/AppleHDA.kext $gExtensionsDirectory/AppleHDA.kext
;;
esac
else
echo "Error, no Desktop/AppleHDA.kext (native)"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
sudo chown -R root:wheel $gExtensionsDirectory/AppleHDA.kext
sudo touch $gExtensionsDirectory
gHDAversioninstalled=$(sudo /usr/libexec/PlistBuddy -c "Print ':CFBundleShortVersionString'" $gHDAContentsDirectory/Info.plist)
echo "Desktop/AppleHDA.kext installed in $gExtensionsDirectory"
fi
# credit: mfram, http://forums.macrumors.com/showpost.php?p=18302055&postcount=6
# get startup disk name
gStartupDevice=$(mount | grep "on / " | cut -f1 -d' ')
gStartupDisk=$(mount | grep "on / " | cut -f1 -d' ' | xargs diskutil info | grep "Volume Name" | perl -an -F'/:\s+/' -e 'print "$F[1]"')
# debug
if [ $gDebug = 1 ]; then
echo "Boot device: $gStartupDevice"
echo "Boot volume: $gStartupDisk"
fi
# if [ $gCloverALC = 1 ]; then
# echo "Verify EFI partition mounted, Finder/Devices/EFI"
# echo "If not set, Terminal/Quit"
# fi
if [ $gRealtekALC = 1 ]; then
gChameleonDirectory=/Volumes/"$gStartupDisk"/Extra
# debug
if [ $gDebug = 1 ]; then
echo "gChameleonDirectory = $gChameleonDirectory"
echo "gSysName = $gSysName"
fi
if [ -d $gChameleonDirectory ]; then
if [ -f "$gChameleonDirectory/org.chameleon.Boot.plist" ]; then
cp -p $gChameleonDirectory/org.chameleon.Boot.plist /tmp/org.chameleon.Boot.txt
# debug
if [ $gDebug = 1 ]; then
echo "$gChameleonDirectory/org.chameleon.Boot.plist found"
fi
else
echo "$$gChameleonDirectory/org.chameleon.Boot.plist not found"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
case $gSysName in
"El Capitan" )
echo $gSID > /tmp/gsid.txt
if [[ $(cat /tmp/gsid.txt | grep -c "disabled") = 0 ]]; then
rm -R /tmp/gsid.txt
echo "$gSID NOK to patch"
echo "Add org.chameleon.Boot.plist/Kernel Flags = CsrActiveConfig=0x3 and restart"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
else
rm -R /tmp/gsid.txt
echo "$gSID OK to patch"
fi
;;
"Yosemite" )
if [[ $(cat /tmp/org.chameleon.Boot.txt | grep -c "kext-dev-mode=1") = 0 ]]; then
rm -R /tmp/org.chameleon.Boot.txt
echo "Kernel Flags = kext-dev-mode=1 not found; patching not possible"
echo "Add org.chameleon.Boot.plist/Kernel Flags = kext-dev-mode=1 and restart"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
else
echo "Kernel Flags = kext-dev-mode=1 found"
fi ;;
esac
fi
rm -R /tmp/org.chameleon.Boot.txt
fi
# get password
gHDAversioninstalled=$(sudo /usr/libexec/PlistBuddy -c "Print ':CFBundleShortVersionString'" $gHDAContentsDirectory/Info.plist)
# exit if error
if [ "$?" != "0" ]; then
echo "Error occurred, AppleHDA.kext/Contents/Info.plist/BundleShortVersionString not found"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
# set up clover (efi or legacy)
if [ $gCloverALC = 1 ]; then
# initialize variable
choice8=n
# check for debug (debug=1 does not touch CLOVER folder)
case $gDebug in
0 )
if [ -d $gCloverDirectory ]; then
echo "EFI partition is mounted"
if [ -f "$gCloverDirectory/config.plist" ]; then
cp -p $gCloverDirectory/config.plist /tmp/config.txt
case $gSysName in
"El Capitan" )
echo $gSID > /tmp/gsid.txt
if [[ $(cat /tmp/gsid.txt | grep -c "disabled") = 0 ]]; then
rm -R /tmp/gsid.txt
echo "$gSID NOK to patch"
echo "Add config.plist/RtVariables/CsrActiveConfig=0x3 and restart"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
else
rm -R /tmp/gsid.txt
echo "$gSID OK to patch"
fi
;;
"Yosemite" )
if [[ $(cat /tmp/config.txt | grep -c "kext-dev-mode=1") = 0 ]]; then
rm -R /tmp/config.txt
echo "Boot/Arguments/kext-dev-mode=1 not found; patching not possible"
echo "Add config.plist/Boot/Arguments/kext-dev-mode=1 and restart"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
else
echo "Boot/Arguments = kext-dev-mode=1 found"
fi
;;
esac
rm -R /tmp/config.txt
cp -p $gCloverDirectory/config.plist /tmp/config.plist
if [ -f "$gCloverDirectory/config-backup.plist" ]; then
rm -R $gCloverDirectory/config-backup.plist
fi
cp -p $gCloverDirectory/config.plist $gCloverDirectory/config-backup.plist
else
echo "$gCloverDirectory/config.plist is missing"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
else
echo "EFI partition is not mounted"
# confirm Clover Legacy install
while true
do
read -p "Confirm Clover Legacy Install (y/n): " choice8
case "$choice8" in
[yY]* )
gCloverDirectory=/Volumes/"$gStartupDisk"/EFI/CLOVER
if [ -d $gCloverDirectory ]; then
echo "$gStartupDisk/EFI folder found"
if [ -f "$gCloverDirectory/config.plist" ]; then
cp -p $gCloverDirectory/config.plist /tmp/config.txt
case $gSysName in
"El Capitan" )
echo $gSID > /tmp/gsid.txt
if [[ $(cat /tmp/gsid.txt | grep -c "disabled") = 0 ]]; then
rm -R /tmp/gsid.txt
echo "$gSID NOK to patch"
echo "Add config.plist/RtVariables/CsrActiveConfig=0x3 and restart"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
else
rm -R /tmp/gsid.txt
echo "$gSID OK to patch"
fi
;;
"Yosemite" )
if [[ $(cat /tmp/config.txt | grep -c "kext-dev-mode=1") = 0 ]]; then
rm -R /tmp/config.txt
echo "Boot/Arguments/kext-dev-mode=1 not found; patching not possible"
echo "Add config.plist/Boot/Arguments/kext-dev-mode=1 and restart"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
else
echo "Boot/Arguments = kext-dev-mode=1 found"
fi
;;
esac
rm -R /tmp/config.txt
sudo cp -p $gCloverDirectory/config.plist /tmp/config.plist
if [ -f "$gCloverDirectory/config-backup.plist" ]; then
rm -R $gCloverDirectory/config-backup.plist
fi
sudo cp -p $gCloverDirectory/config.plist $gCloverDirectory/config-backup.plist
else
echo "$gCloverDirectory/config.plist is missing"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
else
echo "$gCloverDirectory not found"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
break
;;
[nN]* )
echo "User terminated, EFI partition/folder not mounted"
echo “Mount EFI partition and Restart“
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
;;
* ) echo "Try again...";;
esac
done
fi
;;
1 )
echo "gHDAversioninstalled = $gHDAversioninstalled"
echo "Desktop/config-basic.plist copied to /tmp/config.plist"
sudo cp -X config-basic.plist /tmp/config.plist
;;
* )
echo "gDebug = $gDebug, fix"
exit 1
;;
esac
fi
# exit if error
if [ "$?" != "0" ]; then
if [ $choice8 != “y” ]; then
echo "Error, $gStartupDisk/EFI not found"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
echo "Error, EFI partition not mounted"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
# debug
if [ $gDebug = 1 ]; then
echo "EFI: success"
fi
# verify ioreg/HDEF
ioreg -rw 0 -p IODeviceTree -n HDEF > /tmp/HDEF.txt
if [[ $(cat /tmp/HDEF.txt | grep -o "HDEF@1B") = "HDEF@1B" ]]; then
gLayoutidioreg=$(cat /tmp/HDEF.txt | grep layout-id | sed -e 's/.*<//' -e 's/>//')
gLayoutidhex="0x${gLayoutidioreg:6:2}${gLayoutidioreg:4:2}${gLayoutidioreg:2:2}${gLayoutidioreg:0:2}"
let gAudioid=$gLayoutidhex
sudo rm -R /tmp/HDEF.txt
else
echo "Error: no IOReg/HDEF; BIOS/audio/disabled or ACPI problem"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
# debug
if [ $gDebug = 1 ]; then
echo "gLayoutidioreg = $gLayoutidioreg"
echo "gLayoutidihex = $gLayoutidhex"
echo "gAudioid = $gAudioid"
echo "HDEF/Audio ID: success"
fi
# verify native s/l/e/applehda.kext
if [ $gMake = 0 ]; then
if [[ $(perl -le "print scalar grep /\x8b\x19\xd4\x11/, <>;" $gHDAContentsDirectory/MacOS/AppleHDA) = 0 ]]; then
echo "codec: 8b19d411 is missing"
echo "S/L/E/AppleHDA.kext is not native"
echo "Install native AppleHDA.kext"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
if [[ $(perl -le "print scalar grep /\x84\x19\xd4\x11/, <>;" $gHDAContentsDirectory/MacOS/AppleHDA) = 0 ]]; then
echo "codec: 8419d411 is missing"
echo "S/L/E/AppleHDA.kext is not native"
echo "Install native AppleHDA.kext"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
if [[ $(perl -le "print scalar grep /\x62\x02\xec\x10/, <>;" $gHDAContentsDirectory/MacOS/AppleHDA) = 0 ]]; then
echo "codec: 6202ec10 is missing"
echo "S/L/E/AppleHDA.kext is not native"
echo "Install native AppleHDA.kext"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
case $gSysName in
"Mountain Lion" )
if [[ $(perl -le "print scalar grep /\xff\x87\xec\x1a/, <>;" $gHDAContentsDirectory/MacOS/AppleHDA) = 0 ]]; then
echo "codec: ff87ec10 is missing"
echo "S/L/E/AppleHDA.kext is not native"
echo "Install native AppleHDA.kext"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
;;
esac
fi
# debug
if [ $gDebug = 1 ]; then
echo "Native AppleHDA: success"
fi
# get installed codec/revision
gCodecsInstalled=$(ioreg -rxn IOHDACodecDevice | grep VendorID | awk '{ print $4 }' | sed -e 's/ffffffff//')
gCodecsVersion=$(ioreg -rxn IOHDACodecDevice | grep RevisionID| awk '{ print $4 }')
# debug
if [ $gDebug = 1 ]; then
gCodecsInstalled=0x10ec0887
gCodecsVersion=0x100101
# gCodecsVersion=0x100202
# gCodecsVersion=0x100302
# gCodecsInstalled=0x10ec0900
# gCodecsVersion=0x100001
# gCodecsInstalled=0x10134206
# gCodecsVersion=0x100302
echo "gCodecsInstalled = $gCodecsInstalled"
echo "gCodecsVersion = $gCodecsVersion"
fi
# no codecs detected
if [ -z "${gCodecsInstalled}" ]; then
echo ""
echo "No audio codec detected"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
# initialize variables
intel=n
amd=n
nvidia=n
realtek=n
unknown=n
alternate=n
# find realtek codecs
index=0
version=($gCodecsVersion)
for codec in $gCodecsInstalled
do
# debug
if [ $gDebug = 1 ]; then
echo "Index = $index, Codec = $codec, Version = ${version[$index]}"
fi
# sort vendors and devices
case ${codec:2:4} in
8086 ) Codecintelhdmi=$codec; intel=y
;;
1002 ) Codecamdhdmi=$codec; amd=y
;;
10de ) Codecnvidiahdmi=$codec; nvidia=y
;;
10ec ) Codecrealtekaudio=$codec; Versionrealtekaudio=${version[$index]}; realtek=y
;;
*) Codecunknownaudio=$codec; unknown=y
;;
esac
index=$((index + 1))
done
# debug
if [ $gDebug = 1 ]; then
echo "HDMI audio codec(s)"
if [ $intel = y ]; then
echo "Intel: $Codecintelhdmi"
fi
if [ $amd = y ]; then
echo "AMD: $Codecamdhdmi"
fi
if [ $nvidia = y ]; then
echo "Nvidia: $Codecnvidiahdmi"
fi
echo ""
echo "Onboard audio codec"
if [ $realtek = y ]; then
echo "Realtek: $Codecrealtekaudio"
echo "Version: $Versionrealtekaudio"
fi
if [ $unknown = y ]; then
echo "Unknown: $Codecunknownaudio"
fi
fi
if [ $unknown = y ]; then
while true
do
read -p "Codec $Codecunknownaudio is not supported, continue (y/n): " choice7
case "$choice7" in
[yY]* ) break;;
[nN]* ) echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1;;
* ) echo "Try again..."
;;
esac
done
fi
# special names
if [ $realtek = y ]; then
gCodecVendor=${Codecrealtekaudio:2:4}
gCodecDevice=${Codecrealtekaudio:6:4}
# debug
if [ $gDebug = 1 ]; then
echo "gCodecVendor = $gCodecVendor"
echo "gCodecDevice = $gCodecDevice"
fi
if [ ${gCodecDevice:0:1} = 0 ]; then
gCodecName=${gCodecDevice:1:3}
fi
if [ $gCodecDevice = "0899" ]; then
gCodecName=898
fi
if [ $gCodecDevice = "0900" ]; then
gCodecName=1150
fi
# debug
if [ $gDebug = 1 ]; then
echo "Codec identification: success"
fi
# validate_realtek codec
case "$gCodecName" in
269|283|885|887|888|889|892|898|1150 )
# confirm codec, go button
while true
do
read -p "Confirm Realtek ALC$gCodecName (y/n): " choice3
case "$choice3" in
[yY]* ) gCodec=$gCodecName; gCodecvalid=y; break;;
[nN]* ) break;;
* ) echo "Try again...";;
esac
done
;;
* ) echo "Realtek ALC$gCodecName is not supported with $gFile"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
;;
esac
# exit if error
if [ "$?" != "0" ]; then
echo Error: ??
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
fi
if [ $gCodecvalid != y ]; then
# get supported codec
echo "Supported RealtekALC codecs: 885, 887, 888, 889, 892, 898 or 1150"
while true
do
read -p "Enter codec: " choice0
case "$choice0" in
269|283|885|887|888|889|892|898|1150 ) gCodec=$choice0; break;;
* ) echo "Try again...";;
esac
done
# Versionrealtekaudio=0x100302
fi
# legacy
case "$gCodec" in
887|888 )
if [ $gMake = 0 ]; then
case "$Versionrealtekaudio" in
0x100302 ) echo "ALC$gCodec v_$Versionrealtekaudio (Current)"; gLegacy=n ;;
0x100202 ) echo "ALC$gCodec v_$Versionrealtekaudio (Legacy)"; gLegacy=y ;;
* ) echo "ALC$gCodec v_$Versionrealtekaudio not supported"
while true
do
read -p "Use Legacy (v100202) Patch (y/n): " choice1
case "$choice1" in
[yY]* ) gLegacy=y; break;;
[nN]* ) echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit;;
* ) echo "Try again...";;
esac
done
esac
else
while true
do
read -p "887/888 Legacy (v100202) Patch (y/n): " choice1
case "$choice1" in
[yY]* ) gLegacy=y; break;;
[nN]* ) gLegacy=n; break;;
* ) echo "Try again...";;
esac
done
fi
esac
# HD4600 HDMI audio patch
# if [ $gRealtekALC = 1 ]; then
if [ $gCodec = 887 -a $gLegacy = y ]; then gController=n; else
case "$gCodec" in
887|892|898|1150 )
while true
do
read -p "Enable HD4600 HDMI audio (y/n): " choice2
case "$choice2" in
[yY]* ) gController=y; break;;
[nN]* ) gController=n; break;;
* ) echo "Try again...";;
esac
done
esac
fi
# fi
# validate audio id
case $gAudioid in
# 0|1|2|3 ) gAudioidvalid=y;;
1|2|3 ) gAudioidvalid=y;;
* )
while true
do
read -p "Audio ID: $gAudioid is not supported, continue (y/n): " choice9
case "$choice9" in
[yY]* ) gAudioid=0; gAudioidvalid=n break;;
[nN]* ) echo "No system files were changed"; exit;;
* ) echo "Try again..."
;;
esac
done
;;
esac
if [ $gRealtekALC = 1 ]; then
if [ $gAudioidvalid = n ]; then
echo ""
echo "Note"
echo "Set Audio ID injection before restart; valid IDs are:"
# echo "0 - dsdt/ssdt HDMI audio (AMD/Nvidia/Intel)"
echo "1 - 3/5/6 port Realtek ALCxxx audio"
echo "2 - 3 port (5.1) Realtek ALCxxx audio (n/a 885)"
echo "3 - HD3000/HD4000 HDMI and Realtek ALCxxx audio (n/a 885/1150 & 887/888 Legacy)"
echo "Caution: if Audio ID: $gAudioid is not fixed, no audio after restart"
fi
fi
if [ $gCloverALC = 1 ]; then
while true
do
read -p "Clover Audio ID Injection (y/n): " choice4
case "$choice4" in
[yY]* ) choice4=y; break;;
[nN]* ) gAudioid=1; choice5=y; break;;
* ) echo "Try again...";;
esac
done
if [ $choice4 = y ]; then
while true
do
read -p "Use Audio ID: $gAudioid (y/n): " choice5
case "$choice5" in
[yY]* ) break;;
[nN]* ) choice5=n; break;;
* ) echo "Try again...";;
esac
done
fi
if [ $choice5 = n ]; then
echo "Audio IDs:"
# echo "0 - dsdt/ssdt HDMI audio (AMD/Nvidia/Intel)"
echo "1 - 3/5/6 port Realtek ALCxxx audio"
echo "2 - 3 port (5.1) Realtek ALCxxx audio (n/a 885)"
echo "3 - HD3000/HD4000 HDMI and Realtek ALCxxx audio (n/a 885/1150 & 887/888 Legacy)"
while true
do
# read -p "Select Audio ID? (0, 1, 2 or 3): " choice6
read -p "Select Audio ID: " choice6
case "$choice6" in
# 0* ) gAudioid=0; break;;
1* ) gAudioid=1; break;;
2* ) gAudioid=2; if [ $gCodec = 885 ]; then echo "ID: 2 n/a, try again..."; else break; fi;;
3* ) gAudioid=3; valid=y;
if [ $gCodec = 885 ]; then valid=n; fi;
if [ $gCodec = 1150 ]; then valid=n; fi;
if [ $gLegacy = y ]; then valid=n; fi;
if [ $valid = n ]; then echo "ID: 3 n/a, try again..."; else break; fi;;
* ) echo "Try again...";;
esac
done
fi
fi
# debug
if [ $gDebug = 1 ]; then
echo "gCodec = $gCodec"
echo "gAudioid = $gAudioid"
echo "gLegacy = $gLegacy"
echo "gController = $gController"
echo "Codec configuration: success"
fi
echo ""
echo "Download ALC$gCodec files ..."
gDownloadLink="https://raw.githubusercontent.com/toleda/audio_ALC$gCodec/master/$gCodec.zip"
if [ $gLegacy = y ]; then
Legacy=_v100202
gDownloadLinkLegacy="https://raw.githubusercontent.com/toleda/audio_ALC$gCodec/master/$gCodec$Legacy.zip"
sudo curl -o "/tmp/ALC$gCodec.zip" $gDownloadLinkLegacy
else
sudo curl -o "/tmp/ALC$gCodec.zip" $gDownloadLink
fi
unzip -qu "/tmp/ALC$gCodec.zip" -d "/tmp/"
# exit if error
if [ "$?" != "0" ]; then
echo "Error: Download failure, verify network"
echo "No system files were changed"
echo "To save a Copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
# debug
if [ $gDebug = 1 ]; then
echo "gCloverALC = $gCloverALC"
echo "gRealtekALC = $gRealtekALC"
fi
######################
if [ $gRealtekALC = 1 ]; then # main loop
######################
echo " "
echo "Preparing $gSysVer ALC$gCodec AppleHDA.kext_v$gHDAversioninstalled"
# manage backup folders
if [ -d "$gDesktopDirectory/audio_ALC$gCodec-$gSysVer-archive" ]; then
sudo rm -R $gDesktopDirectory/audio_ALC$gCodec-$gSysVer-archive
echo "$gDesktopDirectory/audio_ALC$gCodec-$gSysVer-archive deleted, too late"
fi
if [ -d "$gDesktopDirectory/audio_ALC$gCodec-$gSysVer" ]; then
sudo mv -f $gDesktopDirectory/audio_ALC$gCodec-$gSysVer $gDesktopDirectory/audio_ALC$gCodec-$gSysVer-archive
echo "$gDesktopDirectory/audio_ALC$gCodec-$gSysVer-archive created, max 1 archive"
fi
sudo mkdir -p $gDesktopDirectory/audio_ALC$gCodec-$gSysVer
sudo chown $(whoami) $gDesktopDirectory/audio_ALC$gCodec-$gSysVer
case $gSysName in
"El Capitan" )
sudo cp -X $gExtensionsDirectory/AppleHDA.kext $gDesktopDirectory/audio_ALC$gCodec-$gSysVer/AppleHDA-orig.kext
;;
"Yosemite"|"Mavericks"|"Mountain Lion" )
sudo cp -R $gExtensionsDirectory/AppleHDA.kext $gDesktopDirectory/audio_ALC$gCodec-$gSysVer/AppleHDA-orig.kext
;;
esac
# exit if error
if [ "$?" != "0" ]; then
echo "Error: Backup failed"
echo "No system files were changed"
echo "To save a copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
echo "Patch binaries ..."
if [ $gController = y ]; then
case $gSysVer in
10.10*|10.11* )
echo "$gSysVer controller patch"
# HD4600/0c0c HDMI audio patch (10.10)
sudo xxd -ps $gHDAControllerbinaryDirectory/AppleHDAController | tr -d '\n' > /tmp/AppleHDAController.txt
sudo /usr/bin/perl -pi -e 's|3d0c0a0000|3d0c0c0000|g' /tmp/AppleHDAController.txt
sudo /usr/bin/perl -pi -e 's|3d0b0c0000|3d0c0c0000|g' /tmp/AppleHDAController.txt
sudo xxd -r -p /tmp/AppleHDAController.txt $gHDAControllerbinaryDirectory/AppleHDAController
sudo rm -R /tmp/AppleHDAController.txt
;;
10.9* )
echo "$gSysVer controller patch"
# HD4600/0c0c HDMI audio patch (10.9)
sudo xxd -ps $gHDAControllerbinaryDirectory/AppleHDAController | tr -d '\n' > /tmp/AppleHDAController.txt
sudo /usr/bin/perl -pi -e 's|0b0c0000|0c0c0000|g' /tmp/AppleHDAController.txt
sudo /usr/bin/perl -pi -e 's|0c0a0000|0c0c0000|g' /tmp/AppleHDAController.txt
sudo xxd -r -p /tmp/AppleHDAController.txt $gHDAControllerbinaryDirectory/AppleHDAController
sudo rm -R /tmp/AppleHDAController.txt
;;
* ) echo "OS X Version: $gSysVer does not support HD46000 HDMI audio"
echo "No system files were changed"
echo "To save a copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
;;
esac
fi
# exit if error
if [ "$?" != "0" ]; then
echo "Error: $gCodec controller patch failure"
sudo cp -X $gDesktopDirectory/audio_ALC$gCodec-$gSysVer/AppleHDA-orig.kext $gExtensionsDirectory/AppleHDA.kext
sudo chown -R root:wheel $gExtensionsDirectory/AppleHDA.kext
sudo touch $gExtensionsDirectory
echo "Original S/L/E/AppleHDA.kext restored"
echo "To save a copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
fi
# codec binary patch
case $gSysVer in
10.8.5|10.9*|10.10*|10.11* )
echo "$gSysVer codec patch"
# patch out codec, el capitan only/credit lisai9093
case $gSysName in
"El Capitan" ) sudo perl -pi -e 's|\x83\x19\xd4\x11|\x00\x00\x00\x00|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
esac
# patch codec
case $gCodec in
269 ) sudo perl -pi -e 's|\x62\x02\xec\x10|\x69\x02\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
283 ) sudo perl -pi -e 's|\x62\x02\xec\x10|\x83\x02\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
885 ) echo “No patch, native ALC885”
# Optional patch, remove "# " from the following two lines
# sudo perl -pi -e 's|\x85\x08\xec\x10|\x80\x08\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
# sudo perl -pi -e 's|\x8b\x19\xd4\x11|\x85\x08\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
887 ) sudo perl -pi -e 's|\x8b\x19\xd4\x11|\x87\x08\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
888 ) sudo perl -pi -e 's|\x8b\x19\xd4\x11|\x88\x08\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
889 ) sudo perl -pi -e 's|\x8b\x19\xd4\x11|\x89\x08\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
892 ) sudo perl -pi -e 's|\x8b\x19\xd4\x11|\x92\x08\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
898 ) sudo perl -pi -e 's|\x8b\x19\xd4\x11|\x99\x08\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
1150 ) sudo perl -pi -e 's|\x8b\x19\xd4\x11|\x00\x09\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;
* )
echo "$gCodec not supported with this script"
echo "No system files were changed"
echo "To save a copy of this Terminal session: Terminal/Shell/Export Text As ..."
exit 1
;;
esac
;;
10.8|10.8.*[1-4] )
echo "$gSysVer codec patch"
# patch codec
case $gCodec in
885 ) echo “No patch, native ALC885, optional patch available, see script”
# Optional patch, remove "# " from the following 3 lines
# sudo perl -pi -e 's|\x85\x08\xec\x10|\x80\x08\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
# sudo perl -pi -e 's|\xff\x87\xec\x1a\x0f\x8f\x53\x01\x00\x00|\x99\x08\xec\x10\x0f\x84\x2a\x01\x00\x00|g' $gHDAContentsDirectory/MacOS/AppleHDA/AppleHDA
# sudo perl -pi -e 's|\xff\x87\xec\x1a\x0f\x8f\x2f\x01\x00\x00|\x99\x08\xec\x10\x0f\x84\x06\x01\x00\x00|g' $gHDAContentsDirectory/MacOS/AppleHDA/MacOS/AppleHDA
;;
887 ) sudo perl -pi -e 's|\xff\x87\xec\x1a\x0f\x8f\x53\x01\x00\x00|\x87\x08\xec\x10\x0f\x84\x2a\x01\x00\x00|g' $gHDAContentsDirectory/MacOS/AppleHDA/AppleHDA
sudo perl -pi -e 's|\xff\x87\xec\x1a\x0f\x8f\x2f\x01\x00\x00|\x87\x08\xec\x10\x0f\x84\x06\x01\x00\x00|g' $gHDAContentsDirectory/MacOS/AppleHDA/MacOS/AppleHDA-pi -e 's|\x8b\x19\xd4\x11|\x87\x08\xec\x10|g' $gHDAContentsDirectory/MacOS/AppleHDA
;;