forked from daliansky/XiaoMi-Pro-Hackintosh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·708 lines (590 loc) · 25.6 KB
/
install.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
#!/bin/bash
#set -x # for DEBUGGING
# Created by stevezhengshiqi on 9 Jun, 2019
# Reference:
# https://github.com/black-dragon74/OSX-Debug/blob/master/gen_debug.sh by black-dragon74
# https://github.com/RehabMan/hack-tools/blob/master/mount_efi.sh by Rehabman
# https://github.com/syscl/Fix-usb-sleep/blob/master/fixUSB.sh by syscl
# https://github.com/xzhih/one-key-hidpi/blob/master/hidpi.sh by xzhih
# Only support Xiaomi NoteBook Pro.
# Display style setting
BOLD="\033[1m"
RED="\033[1;31m"
GREEN="\033[1;32m"
BLUE="\033[1;34m"
OFF="\033[m"
pledit=/usr/libexec/PlistBuddy
# Exit in case of network failure
function networkWarn() {
echo -e "[ ${RED}ERROR${OFF} ]: Fail to download resources from ${repoURL}, please check your connection!"
clean
exit 1
}
# Check Mainboard
function checkMainboard() {
local MODEL_MX150="TM1701"
local MODEL_GTX="TM1707"
# new folder for work
WORK_DIR="$HOME/Desktop/EFI_XIAOMI-PRO"
[[ -d "${WORK_DIR}" ]] && rm -rf "${WORK_DIR}"
mkdir -p "${WORK_DIR}" && cd "${WORK_DIR}"
local repoURL="https://raw.githubusercontent.com/daliansky/Hackintosh/master/Tools/bdmesg"
curl --silent -O "${repoURL}" || networkWarn
sudo chmod +x bdmesg
MAINBOARD="$( "${WORK_DIR}/bdmesg" | grep Running | awk '{print $5}' | sed "s/\'//g" | tr -d "''")"
if [ "${MAINBOARD}" != "${MODEL_MX150}" ] && [ "${MAINBOARD}" != "${MODEL_GTX}" ]; then
echo "Your mainboard is ${MAINBOARD}"
echo -e "[ ${RED}ERROR${OFF} ]:Not a XiaoMi-Pro, please check your model!"
clean
exit 1
fi
}
# Check kexts with invalid signature by rebuilding kextcache
function checkSystemIntegrity() {
echo
echo "Rebuilding kextcache..."
sudo kextcache -i / &> kextcache_log.txt
echo -e "[ ${GREEN}OK${OFF} ]Rebuild complete"
# check total line number of kextcache_log.txt
local KEXT_LIST=$(cat "kextcache_log.txt" |wc -l)
# check if apple kexts have been modified
local APPLE_KEXT=$(grep 'com.apple' kextcache_log.txt)
# check FakeSMC in S/L/E and L/E
local FakeSMC=$(grep 'FakeSMC' kextcache_log.txt)
# check VirtualSMC in S/L/E and L/E
local VirtualSMC=$(grep 'VirtualSMC' kextcache_log.txt)
if [[ -n ${APPLE_KEXT} ]]; then
echo -e "[ ${RED}ERROR${OFF} ]:Native apple kexts have been modified, please keep S/L/E and L/E untouched!"
clean
exit 1
elif [[ -n ${FakeSMC} ]]; then
echo -e "[ ${RED}ERROR${OFF} ]:Detected FakeSMC in system partition, kexts in CLOVER folder will not work!"
clean
exit 1
elif [[ -n ${VirtualSMC} ]]; then
echo -e "[ ${BLUE}WARNING${OFF} ]:Detected VirtualSMC in system partition, kexts in CLOVER folder may not work!"
echo "Please backup EFI folder to an external device before updating EFI"
elif [ ${KEXT_LIST} -lt 1 ]; then
# if larger than one, means that native kexts may be modified, or unknown kexts are installed in /L/E or /S/L/E
echo -e "[ ${BLUE}WARNING${OFF} ]: Your system has kext(s) with invalid signature, which may cause serious trouble!"
echo "Please backup EFI folder to an external device before updating EFI"
fi
}
# Mount EFI by using mount_efi.sh, credits Rehabman
function mountEFI() {
local repoURL="https://raw.githubusercontent.com/RehabMan/hack-tools/master/mount_efi.sh"
curl --silent -O "${repoURL}" || networkWarn
echo
echo "Mounting EFI partition..."
EFI_DIR="$(sh "mount_efi.sh")"
# check whether EFI partition exists
if [[ -z "${EFI_DIR}" ]]; then
echo -e "[ ${RED}ERROR${OFF} ]: Failed to detect EFI partition"
unmountEFI
returnMenu
# check whether EFI/CLOVER exists
elif [[ ! -e "${EFI_DIR}/EFI/CLOVER" ]]; then
echo -e "[ ${RED}ERROR${OFF} ]: Failed to detect CLOVER folder"
unmountEFI
returnMenu
fi
echo -e "[ ${GREEN}OK${OFF} ]Mounted EFI at ${EFI_DIR} (credits RehabMan)"
}
# Unmount EFI for safety
function unmountEFI() {
echo
echo "Unmounting EFI partition..."
diskutil unmount "$EFI_DIR" &>/dev/null
echo -e "[ ${GREEN}OK${OFF} ]Unmount complete"
}
function getGitHubLatestRelease() {
local repoURL='https://api.github.com/repos/daliansky/XiaoMi-Pro-Hackintosh/releases/latest'
ver="$(curl --silent "${repoURL}" | grep 'tag_name' | head -n 1 | awk -F ":" '{print $2}' | tr -d '"' | tr -d ',' | tr -d ' ')"
if [[ -z "${ver}" ]]; then
echo
echo -e "[ ${RED}ERROR${OFF} ]: Failed to retrieve latest release from ${repoURL}"
returnMenu
fi
}
# Download EFI folder
function downloadEFI() {
getGitHubLatestRelease
echo
echo '--------------------------------------------------------------------------------------'
echo '|* Downloading EFI from https://github.com/daliansky/XiaoMi-Pro-Hackintosh/releases *|'
echo '--------------------------------------------------------------------------------------'
# download XiaoMi-Pro's EFI
local xmFileName="XiaoMi_Pro-${ver}.zip"
local repoURL="https://github.com/daliansky/XiaoMi-Pro-Hackintosh/releases/download/${ver}/${xmFileName}"
# GitHub's CDN is hosted on Amazon, so here we add -L for redirection support
curl -# -L -O "${repoURL}" || networkWarn
# decompress it
unzip -qu "${xmFileName}"
# remove stuffs we do not need
rm -rf "${xmFileName}"
echo -e "[ ${GREEN}OK${OFF} ]Download complete"
}
# Backup DefaultVolume, Timeout, Serial Numbers, theme, BOOT and CLOVER folder
function backupEFI() {
mountEFI
# new folder for backup
echo
echo "Creating backup..."
# generate time stamp
local DATE="$(date "+%Y-%m-%d_%H-%M-%S")"
BACKUP_DIR="$HOME/Desktop/backupEFI_${DATE}"
[[ -d "${BACKUP_DIR}" ]] && rm -rf "${BACKUP_DIR}"
mkdir -p "${BACKUP_DIR}"
cp -rf "${EFI_DIR}/EFI/BOOT" "${BACKUP_DIR}" || cp -rf "${EFI_DIR}/EFI/Boot" "${BACKUP_DIR}" || cp -rf "${EFI_DIR}/EFI/boot" "${BACKUP_DIR}"
cp -rf "${EFI_DIR}/EFI/CLOVER" "${BACKUP_DIR}"
echo -e "[ ${GREEN}OK${OFF} ]Backup complete"
echo
echo "Copying previous settings to new CLOVER..."
local DefaultVolume="$($pledit -c 'Print Boot:DefaultVolume' ${BACKUP_DIR}/CLOVER/config.plist)"
local Timeout="$($pledit -c 'Print Boot:Timeout' ${BACKUP_DIR}/CLOVER/config.plist)"
local SerialNumber="$($pledit -c 'Print SMBIOS:SerialNumber' ${BACKUP_DIR}/CLOVER/config.plist)"
local BoardSerialNumber="$($pledit -c 'Print SMBIOS:BoardSerialNumber' ${BACKUP_DIR}/CLOVER/config.plist)"
local SmUUID="$($pledit -c 'Print SMBIOS:SmUUID' ${BACKUP_DIR}/CLOVER/config.plist)"
local ROM="$($pledit -c 'Print RtVariables:ROM' ${BACKUP_DIR}/CLOVER/config.plist)"
local MLB="$($pledit -c 'Print RtVariables:MLB' ${BACKUP_DIR}/CLOVER/config.plist)"
local CustomUUID="$($pledit -c 'Print SystemParameters:CustomUUID' ${BACKUP_DIR}/CLOVER/config.plist)"
local InjectSystemID="$($pledit -c 'Print SystemParameters:InjectSystemID' ${BACKUP_DIR}/CLOVER/config.plist)"
local framebufferfbmem="$($pledit -c 'Print Devices:Properties:PciRoot(0x0)/Pci(0x2,0x0):framebuffer-fbmem' ${BACKUP_DIR}/CLOVER/config.plist)"
local framebufferstolenmem="$($pledit -c 'Print Devices:Properties:PciRoot(0x0)/Pci(0x2,0x0):framebuffer-stolenmem' ${BACKUP_DIR}/CLOVER/config.plist)"
# check whether DefaultVolume and Timeout exist, copy if yes
if [[ -n "${DefaultVolume}" ]]; then
$pledit -c "Set Boot:DefaultVolume ${DefaultVolume}" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
if [[ -n "${Timeout}" ]]; then
$pledit -c "Set Boot:Timeout ${Timeout}" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
# check whether serial numbers exist, copy if yes
if [[ -n "${SerialNumber}" ]]; then
$pledit -c "Add SMBIOS:SerialNumber string ${SerialNumber}" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
if [[ -n "${BoardSerialNumber}" ]]; then
$pledit -c "Add SMBIOS:BoardSerialNumber string ${BoardSerialNumber}" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
if [[ -n "${SmUUID}" ]]; then
$pledit -c "Add SMBIOS:SmUUID string ${SmUUID}" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
if [[ -n "${ROM}" ]]; then
$pledit -c "Set RtVariables:ROM ${ROM}" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
if [[ -n "${MLB}" ]]; then
$pledit -c "Add RtVariables:MLB string ${MLB}" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
if [[ -n "${CustomUUID}" ]]; then
$pledit -c "Add SystemParameters:CustomUUID string ${CustomUUID}" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
if [[ -n "${InjectSystemID}" ]]; then
$pledit -c "Set SystemParameters:InjectSystemID ${InjectSystemID}" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
else
$pledit -c "Set SystemParameters:InjectSystemID false" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
if [[ -z "${framebufferfbmem}" ]]; then
$pledit -c "delete Devices:Properties:PciRoot(0x0)/Pci(0x2,0x0):framebuffer-fbmem" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
if [[ -z "${framebufferstolenmem}" ]]; then
$pledit -c "delete Devices:Properties:PciRoot(0x0)/Pci(0x2,0x0):framebuffer-stolenmem" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
fi
echo -e "[ ${GREEN}OK${OFF} ]Copy complete"
echo
echo "Copying theme to new CLOVER..."
rm -rf "${BACKUP_DIR}/CLOVER/themes/Xiaomi"
cp -rf "XiaoMi_Pro-${ver}/EFI/CLOVER/themes/Xiaomi" "${BACKUP_DIR}/CLOVER/themes/"
rm -rf "XiaoMi_Pro-${ver}/EFI/CLOVER/themes"
cp -rf "${BACKUP_DIR}/CLOVER/themes" "XiaoMi_Pro-${ver}/EFI/CLOVER/"
# create a config.plist with only GUI directory inside
# TODO: use a more efficient way to copy GUI directory
cp -rf "${BACKUP_DIR}/CLOVER/config.plist" "${WORK_DIR}/GUI.plist"
$pledit -c "Delete ACPI" "${WORK_DIR}/GUI.plist"
$pledit -c "Delete Boot" "${WORK_DIR}/GUI.plist"
$pledit -c "Delete CPU" "${WORK_DIR}/GUI.plist"
$pledit -c "Delete Devices" "${WORK_DIR}/GUI.plist"
$pledit -c "Delete Graphics" "${WORK_DIR}/GUI.plist"
$pledit -c "Delete KernelAndKextPatches" "${WORK_DIR}/GUI.plist"
$pledit -c "Delete RtVariables" "${WORK_DIR}/GUI.plist"
$pledit -c "Delete SMBIOS" "${WORK_DIR}/GUI.plist"
$pledit -c "Delete SystemParameters" "${WORK_DIR}/GUI.plist"
# merge GUI.plist to config.plist to save theme settings
$pledit -c "Delete GUI" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
$pledit -c "Merge GUI.plist" "XiaoMi_Pro-${ver}/EFI/CLOVER/config.plist"
echo -e "[ ${GREEN}OK${OFF} ]Copy complete"
}
# Check whether ${BACKUP_DIR}/CLOVER exists or not
function confirmBackup() {
echo
echo "Confirming backup..."
if [[ ! -e "${BACKUP_DIR}/CLOVER" ]]; then
echo -e "[ ${RED}ERROR${OFF} ]: Failed to backup CLOVER folder!"
unmountEFI
clean
exit 1
else
echo -e "[ ${GREEN}OK${OFF} ]Confirm complete"
fi
}
# Compare new and old CLOVER folders
function compareEFI() {
echo
echo "Comparing old and new EFI folder..."
# generate tree diagram of new CLOVER folder
find "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER" -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' &> NewEFI_TREE.txt
# remove first few strings
sed -i '' 's/^.................//' NewEFI_TREE.txt
# remove lines which have DS_Store
sed -i '' '/DS_Store/d' NewEFI_TREE.txt
# generate tree diagram of old CLOVER folder
find "${BACKUP_DIR}/CLOVER" -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' &> OldEFI_TREE.txt
# remove first few strings
sed -i '' 's/^.............//' OldEFI_TREE.txt
# remove lines which have DS_Store
sed -i '' '/DS_Store/d' OldEFI_TREE.txt
diff NewEFI_TREE.txt OldEFI_TREE.txt
echo -e "${BOLD}Do you want to continue? (y/n)${OFF}"
read -rp ":" cp_selection
case ${cp_selection} in
y)
;;
n)
unmountEFI
returnMenu
;;
*)
echo -e "[ ${RED}ERROR${OFF} ]: Invalid input"
unmountEFI
returnMenu
;;
esac
}
# EFI modifications according to unique setup
function editEFI() {
# if GTX, SSDT-LGPA need to be replaced with SSDT-LGPAGTX
if [ "${MAINBOARD}" == "TM1707" ]; then
rm -f "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/ACPI/patched/SSDT-LGPA.aml"
cp -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/GTX_Users_Read_This/SSDT-LGPAGTX.aml" "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/ACPI/patched/"
fi
echo
echo "---------------------------------------------------------"
echo "|************** Choose the Bluetooth Mode **************|"
echo "---------------------------------------------------------"
echo "(1) Native Intel BT (Default)"
echo "(2) USB BT / Disable native BT / Solder BT on camera port"
echo "(3) Solder BT on WLAN_LTE port"
echo "(4) Solder BT on fingerprint port"
echo -e "${BOLD}Which option you want to choose? (1/2/3/4)${OFF}"
read -rp ":" bt_selection
case ${bt_selection} in
1)
# Keep default
;;
2)
rm -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/ACPI/patched/SSDT-USB.aml"
rm -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/kexts/Other/IntelBluetoothFirmware.kext" >/dev/null 2>&1
rm -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/kexts/Other/IntelBluetoothInjector.kext" >/dev/null 2>&1
cp -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/SSDT-USB-USBBT.aml" "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/ACPI/patched/"
;;
3)
rm -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/ACPI/patched/SSDT-USB.aml"
rm -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/kexts/Other/IntelBluetoothFirmware.kext" >/dev/null 2>&1
rm -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/kexts/Other/IntelBluetoothInjector.kext" >/dev/null 2>&1
cp -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/SSDT-USB-WLAN_LTEBT.aml" "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/ACPI/patched/"
;;
4)
rm -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/ACPI/patched/SSDT-USB.aml"
rm -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/kexts/Other/IntelBluetoothFirmware.kext" >/dev/null 2>&1
rm -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/kexts/Other/IntelBluetoothInjector.kext" >/dev/null 2>&1
cp -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/SSDT-USB-FingerBT.aml" "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER/ACPI/patched/"
;;
*)
echo -e "[ ${RED}ERROR${OFF} ]: Invalid input"
unmountEFI
returnMenu
;;
esac
echo -e "[ ${GREEN}OK${OFF} ]Change complete"
}
function restoreEFI() {
echo -e "[ ${RED}ERROR${OFF} ]: Failed to update EFI folder"
echo
echo "Restoring the EFI folder from backup..."
cp -rf "${BACKUP_DIR}/BOOT" "${EFI_DIR}/EFI/" || cp -rf "${BACKUP_DIR}/Boot" "${EFI_DIR}/EFI/" || cp -rf "${BACKUP_DIR}/boot" "${EFI_DIR}/EFI/" || echo -e "[ ${RED}ERROR${OFF} ]: Failed to restore BOOT folder, please update EFI manually before shutting down"
cp -rf "${BACKUP_DIR}/CLOVER" "${EFI_DIR}/EFI/" || echo -e "[ ${RED}ERROR${OFF} ]: Failed to restore CLOVER folder, please update EFI manually before shutting down"
echo -e "[ ${GREEN}OK${OFF} ]Restore complete"
clean
exit 1
}
# Update BOOT and CLOVER folder
function replaceEFI() {
echo
echo "Updating EFI folder..."
rm -rf "${EFI_DIR}/EFI/CLOVER" && rm -rf "${EFI_DIR}/EFI/BOOT"
cp -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/BOOT" "${EFI_DIR}/EFI/" || restoreEFI
cp -rf "${WORK_DIR}/XiaoMi_Pro-${ver}/EFI/CLOVER" "${EFI_DIR}/EFI/" || restoreEFI
echo -e "[ ${GREEN}OK${OFF} ]Update complete"
}
function updateEFI() {
checkSystemIntegrity
downloadEFI
backupEFI
confirmBackup
compareEFI
editEFI
replaceEFI
unmountEFI
}
# Delete previous Bluetooth configurations(SSDT-USB, SSDT-USB-USBBT, SSDT-SolderBT(changed to SSDT-USB-WLAN_LTEBT), SSDT-USB-WLAN_LTEBT, and SSDT-USB-FingerBT)
function deleteBT() {
mountEFI
rm -rf "${EFI_DIR}/EFI/CLOVER/ACPI/patched/SSDT-USB.aml" >/dev/null 2>&1
rm -rf "${EFI_DIR}/EFI/CLOVER/ACPI/patched/SSDT-USB-USBBT.aml" >/dev/null 2>&1
rm -rf "${EFI_DIR}/EFI/CLOVER/ACPI/patched/SSDT-USB-SolderBT.aml" >/dev/null 2>&1
rm -rf "${EFI_DIR}/EFI/CLOVER/ACPI/patched/SSDT-USB-WLAN_LTEBT.aml" >/dev/null 2>&1
rm -rf "${EFI_DIR}/EFI/CLOVER/ACPI/patched/SSDT-USB-FingerBT.aml" >/dev/null 2>&1
# need unmountEFI after calling this function
}
function changeBT() {
echo
echo "---------------------------------------------------------"
echo "|************** Choose the Bluetooth Mode **************|"
echo "---------------------------------------------------------"
echo "(1) Native Intel BT (Default)"
echo "(2) USB BT / Disable native BT / Solder BT on camera port"
echo "(3) Solder BT on WLAN_LTE port"
echo "(4) Solder BT on fingerprint port"
echo -e "${BOLD}Which option you want to choose? (1/2/3/4)${OFF}"
read -rp ":" bt_selection_new
case ${bt_selection_new} in
1)
local repoURL="https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/EFI/CLOVER/ACPI/patched/SSDT-USB.aml"
curl --silent -O "${repoURL}" || networkWarn
deleteBT
cp -rf "SSDT-USB.aml" "${EFI_DIR}/EFI/CLOVER/ACPI/patched/"
unmountEFI
;;
2)
local repoURL="https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/wiki/SSDT-USB-USBBT.aml"
curl --silent -O "${repoURL}" || networkWarn
deleteBT
rm -rf "${EFI_DIR}/EFI/CLOVER/kexts/Other/IntelBluetoothFirmware.kext" >/dev/null 2>&1
rm -rf "${EFI_DIR}/EFI/CLOVER/kexts/Other/IntelBluetoothInjector.kext" >/dev/null 2>&1
cp -rf "SSDT-USB-USBBT.aml" "${EFI_DIR}/EFI/CLOVER/ACPI/patched/"
echo
echo "If you are using Broadcom USB BT, you may need to download & install kexts from https://bitbucket.org/RehabMan/os-x-brcmpatchram/downloads"
unmountEFI
;;
3)
local repoURL="https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/wiki/SSDT-USB-WLAN_LTEBT.aml"
curl --silent -O "${repoURL}" || networkWarn
deleteBT
rm -rf "${EFI_DIR}/EFI/CLOVER/kexts/Other/IntelBluetoothFirmware.kext" >/dev/null 2>&1
rm -rf "${EFI_DIR}/EFI/CLOVER/kexts/Other/IntelBluetoothInjector.kext" >/dev/null 2>&1
cp -rf "SSDT-USB-WLAN_LTEBT.aml" "${EFI_DIR}/EFI/CLOVER/ACPI/patched/"
unmountEFI
;;
4)
local repoURL="https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/wiki/SSDT-USB-FingerBT.aml"
curl --silent -O "${repoURL}" || networkWarn
deleteBT
rm -rf "${EFI_DIR}/EFI/CLOVER/kexts/Other/IntelBluetoothFirmware.kext" >/dev/null 2>&1
rm -rf "${EFI_DIR}/EFI/CLOVER/kexts/Other/IntelBluetoothInjector.kext" >/dev/null 2>&1
cp -rf "SSDT-USB-FingerBT.aml" "${EFI_DIR}/EFI/CLOVER/ACPI/patched/"
unmountEFI
;;
*)
echo -e "[ ${RED}ERROR${OFF} ]: Invalid input"
returnMenu
;;
esac
echo -e "[ ${GREEN}OK${OFF} ]Change complete"
}
# Remove DVMT patch or 0xE2 MSR patch if scripts in https://github.com/daliansky/XiaoMi-Pro-Hackintosh/tree/master/BIOS/DVMT_and_0xE2_fix are installed, credit Menchen
function removeDVMTMSR() {
echo
echo "Before editing, please read https://github.com/daliansky/XiaoMi-Pro-Hackintosh/blob/master/BIOS/DVMT_and_0xE2_fix/README.md"
open -a "/Applications/Safari.app" https://github.com/daliansky/XiaoMi-Pro-Hackintosh/blob/master/BIOS/DVMT_and_0xE2_fix/README.md
echo
echo "---------------------------------------------------------"
echo "|**************** Choose Clover patches ****************|"
echo "---------------------------------------------------------"
echo "(1) 0xE2 MSR patch & 32mb DVMT patch (Default)"
echo "(2) 0xE2 MSR patch only, choose this if DVMT = 64mb"
echo "(3) 32mb DVMT patch only, choose this if 0xE2 MSR is unlocked"
echo "(4) No patch, choose this if you have both patches in BIOS"
echo "${BOLD}Which option you want to choose? (1/2/3/4)${OFF}"
read -rp ":" cloverpatch_selection
case ${cloverpatch_selection} in
1)
# Keep default
;;
2)
mountEFI
$pledit -c "delete Devices:Properties:PciRoot(0x0)/Pci(0x2,0x0):framebuffer-fbmem" "${EFI_DIR}/EFI/CLOVER/config.plist"
$pledit -c "delete Devices:Properties:PciRoot(0x0)/Pci(0x2,0x0):framebuffer-stolenmem" "${EFI_DIR}/EFI/CLOVER/config.plist"
unmountEFI
;;
3)
mountEFI
$pledit -c "delete KernelAndKextPatches:KernelToPatch:0" "${EFI_DIR}/EFI/CLOVER/config.plist"
unmountEFI
;;
4)
mountEFI
$pledit -c "delete KernelAndKextPatches:KernelToPatch:0" "${EFI_DIR}/EFI/CLOVER/config.plist"
$pledit -c "delete Devices:Properties:PciRoot(0x0)/Pci(0x2,0x0):framebuffer-fbmem" "${EFI_DIR}/EFI/CLOVER/config.plist"
$pledit -c "delete Devices:Properties:PciRoot(0x0)/Pci(0x2,0x0):framebuffer-stolenmem" "${EFI_DIR}/EFI/CLOVER/config.plist"
unmountEFI
;;
*)
echo -e "[ ${RED}ERROR${OFF} ]: Invalid input"
returnMenu
;;
esac
echo -e "[ ${GREEN}OK${OFF} ]Change complete"
}
function fixWindows() {
echo
echo "Make sure you can boot Windows with F12"
echo "Fixing Windows boot..."
local repoURL="https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/wiki/AptioMemoryFix.efi"
curl --silent -O "${repoURL}" || networkWarn
mountEFI
cp -rf "AptioMemoryFix.efi" "${EFI_DIR}/EFI/CLOVER/drivers/UEFI/"
echo -e "[ ${GREEN}OK${OFF} ]Fix complete"
unmountEFI
}
function fixAppleService() {
echo
echo "Fixing AppStore..."
echo "If you are signing up a new Apple account, please use another device except hackintosh"
# make Ethernet at en0, according to https://www.tonymacx86.com/threads/faq-read-first-laptop-frequent-questions.164990 by Rehabman
# backup NetworkInterfaces.plist to NetworkInterfaces_backup.plist
sudo cp -rf /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist /Library/Preferences/SystemConfiguration/NetworkInterfaces_backup.plist
# delete NetworkInterfaces.plist and let system to re-generate it
sudo rm -rf /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist
defaults delete com.apple.appstore.commerce Storefront
# Replace with random MAC address to solve some Apple services
# Idea comes from: https://github.com/daliansky/XiaoMi-Pro-Hackintosh/issues/193#issuecomment-510689917
# generate random MAC address
MAC_ADDRESS="0x$(openssl rand -hex 1), 0x$(openssl rand -hex 1), 0x$(openssl rand -hex 1), 0x$(openssl rand -hex 1), 0x$(openssl rand -hex 1), 0x$(openssl rand -hex 1)"
local repoURL="https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/EFI/CLOVER/ACPI/patched/SSDT-RMNE.dsl"
curl --silent -O "${repoURL}" || networkWarn
# change 11:22:33:44:55:66 to ${MAC_ADDRESS} in SSDT-RMNE.dsl
/usr/bin/sed -i "" "s:0x11, 0x22, 0x33, 0x44, 0x55, 0x66:${MAC_ADDRESS}:g" "${WORK_DIR}/SSDT-RMNE.dsl"
# compile SSDT-RMNE.dsl to SSDT-RMNE.aml
local repoURL="https://raw.githubusercontent.com/daliansky/Hackintosh/master/Tools/iasl63"
curl --silent -O "${repoURL}" || networkWarn
sudo chmod +x iasl63
"${WORK_DIR}/iasl63" -l "${WORK_DIR}/SSDT-RMNE.dsl"
mountEFI
cp -rf "${WORK_DIR}/SSDT-RMNE.aml" "${EFI_DIR}/EFI/CLOVER/ACPI/patched/"
unmountEFI
echo -e "[ ${GREEN}OK${OFF} ]Fix complete"
echo "Please restart your device!"
}
# Report problem and generate problem shooting by using gen_debug.sh @black-dragon74
# This function hasn't been tested yet because it takes time
function reportProblem() {
echo
echo "Collecting problem shooting file by using gen_debug.sh @black-dragon74..."
bash -c "$(curl -fsSL https://raw.githubusercontent.com/black-dragon74/OSX-Debug/master/gen_debug.sh)"
echo -e "[ ${GREEN}OK${OFF} ]Collect complete"
# open Safari
open -a "/Applications/Safari.app" https://github.com/daliansky/XiaoMi-Pro-Hackintosh/issues
echo -e "${BOLD}Please write down your model and attach full problem shooting file generated by gen_debug.sh${OFF}"
}
function returnMenu() {
echo
read -rp "Press any key to return to the main menu..."
main
}
function clean() {
rm -rf "$HOME/Desktop/EFI_XIAOMI-PRO"
}
function main() {
printf '\e[8;40;90t'
checkMainboard
clear
# Interface (ref: http://patorjk.com/software/taag/#p=display&f=Ivrit&t=X%20i%20a%20o%20M%20i%20-%20P%20r%20o)
echo
echo ' __ __ _ __ __ _ ____ '
echo ' \ \/ / (_) __ _ ___ | \/ | (_) | _ \ _ __ ___ '
echo ' \ / | | / _` | / _ \ | |\/| | | | ____ | |_) | | __| / _ \ '
echo ' / \ | | | (_| | | (_) | | | | | | | |____| | __/ | | | (_) |'
echo ' /_/\_\ |_| \__,_| \___/ |_| |_| |_| |_| |_| \___/ '
echo
echo "Your mainboard is ${MAINBOARD}"
echo '========================================================================='
echo -e "${BOLD}(1) Update EFI${OFF}"
echo "(2) Change Bluetooth mode (Only support the latest release)"
echo "(3) General audio fix (credits Menchen)"
echo "(4) Add color profile"
echo "(5) Update power management"
echo "(6) Modify TDP and CPU voltage (credits Pasi-Studio)"
echo "(7) Enable HiDPI"
echo "(8) Set DVMT to 64mb (for 4K screen) and unlock 0xE2 MSR (credit Menchen)"
echo "(9) Fix Windows boot (Only support the latest release)"
echo "(10) Fix Apple services"
echo "(11) Problem report"
echo "(12) Exit"
echo -e "${BOLD}Which option you want to choose? (1/2/3/4/5/6/7/8/9/10/11/12)${OFF}"
read -rp ":" xm_selection
case ${xm_selection} in
1)
updateEFI
returnMenu
;;
2)
changeBT
returnMenu
;;
3)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/ALCPlugFix/one-key-alcplugfix.sh)"
returnMenu
;;
4)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/ColorProfile/one-key-colorprofile.sh)"
returnMenu
;;
5)
bash -c "$(curl -fsSL https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/one-key-cpufriend/one-key-cpufriend.sh)"
returnMenu
;;
6)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Pasi-Studio/mpcpu/master/mpcpu.sh)"
returnMenu
;;
7)
bash -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/master/hidpi.sh)"
returnMenu
;;
8)
removeDVMTMSR
returnMenu
;;
9)
fixWindows
returnMenu
;;
10)
fixAppleService
returnMenu
;;
11)
reportProblem
returnMenu
;;
12)
clean
echo
echo "Wish you have a good day! Bye"
exit 0
;;
*)
echo -e "[ ${RED}ERROR${OFF} ]: Invalid input"
returnMenu
;;
esac
}
main