forked from daliansky/XiaoMi-Pro-Hackintosh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
one-key-alcplugfix.sh
executable file
·143 lines (130 loc) · 4.02 KB
/
one-key-alcplugfix.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
#!/bin/bash
#set -x # for DEBUGGING
# Rewrite on Feb 27, 2019 by stevezhengshiqi, special thanks to @Menchen
# Support Xiaomi-Pro (ALC298,layout-id99)
# Interface (Ref:http://patorjk.com/software/taag/#p=display&f=Ivrit&t=P%20l%20u%20g%20F%20i%20x)
function interface() {
echo ' ____ _ _____ _ '
echo '| _ \ | | _ _ __ _ | ___| (_) __ __ '
echo '| |_) | | | | | | | / _` | | |_ | | \ \/ / '
echo '| __/ | | | |_| | | (_| | | _| | | > < '
echo '|_| |_| \__,_| \__, | |_| |_| /_/\_\ '
echo ' |___/ '
echo 'Support XiaoMi-Pro(ALC298, layout-id 99)'
echo '==============================================='
}
# Choose option
function choice() {
echo "(1) Enable ALCPlugFix"
echo "(2) Disable ALCPlugFix"
echo "(3) Exit"
read -p "Which option you want to choose? (1/2/3):" alc_option
echo
}
# Exit if connection fails
function networkWarn(){
echo "ERROR: Fail to download ALCPlugFix, please check the network state"
clean
exit 1
}
# Download from https://github.com/daliansky/XiaoMi-Pro/master/ALCPlugFix and https://github.com/Menchen/ALCPlugFix/tree/master/build/Release
function download(){
mkdir -p one-key-alcplugfix
cd one-key-alcplugfix
echo "Downloading audio fix patch..."
curl -fsSL https://raw.githubusercontent.com/Menchen/ALCPlugFix/master/build/Release/ALCPlugFix -O || networkWarn
curl -fsSL https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/ALCPlugFix/good.win.ALCPlugFix.plist -O || networkWarn
curl -fsSL https://raw.githubusercontent.com/daliansky/XiaoMi-Pro-Hackintosh/master/ALCPlugFix/hda-verb -O || networkWarn
echo "Download complete"
echo
}
# Copy the audio fix files
function copy() {
echo "Copying audio fix patch..."
if [ ! -d "/usr/local/bin" ]; then
echo "'/usr/local/bin' not found, creating one instead..."
sudo mkdir -p -m 775 /usr/local/bin
sudo chown $USER:admin /usr/local/bin
fi
sudo cp "./ALCPlugFix" /usr/local/bin/
sudo cp "./hda-verb" /usr/local/bin/
sudo cp "./good.win.ALCPlugFix.plist" /Library/LaunchDaemons/
echo "Copy complete"
echo
}
# Fix permission
function fixpermission() {
echo "Fixing permission..."
sudo chmod 755 /usr/local/bin/ALCPlugFix
sudo chown $USER:admin /usr/local/bin/ALCPlugFix
sudo chmod 755 /usr/local/bin/hda-verb
sudo chown $USER:admin /usr/local/bin/hda-verb
sudo chmod 644 /Library/LaunchDaemons/good.win.ALCPlugFix.plist
sudo chown root:wheel /Library/LaunchDaemons/good.win.ALCPlugFix.plist
echo "Fix complete"
echo
}
# Load service
function loadservice() {
echo "Loading service..."
sudo launchctl load /Library/LaunchDaemons/good.win.ALCPlugFix.plist
echo "Load complete"
echo
}
# Clean
function clean() {
echo "Cleaning..."
sudo rm -rf ../one-key-alcplugfix
echo "Clean complete"
echo
}
# Uninstall
function uninstall() {
echo "Uninstalling..."
sudo launchctl remove /Library/LaunchAgents/good.win.ALCPlugFix.plist
sudo launchctl remove /Library/LaunchDaemons/good.win.ALCPlugFix.plist
sudo rm -rf /Library/LaunchAgents/good.win.ALCPlugFix.plist
sudo rm -rf /Library/LaunchDaemons/good.win.ALCPlugFix.plist
sudo rm -rf /usr/bin/ALCPlugFix
sudo rm -rf /usr/bin/hda-verb
sudo rm -rf /usr/local/bin/ALCPlugFix
sudo rm -rf /usr/local/bin/hda-verb
echo "Uninstall complete"
echo
if [[ $1 = "cleanup" ]]; then
return
else exit 0
fi
}
# Install function
function install() {
download
uninstall "cleanup"
copy
fixpermission
loadservice
clean
echo 'Nice! The installation of the ALCPlugFix daemon completes.'
exit 0
}
# Main function
function main() {
interface
choice
case $alc_option in
1)
install
;;
2)
uninstall
;;
3)
exit 0
;;
*)
echo "ERROR: Invalid input, closing the script"
exit 1
;;
esac
}
main