forked from daliansky/XiaoMi-Pro-Hackintosh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
one-key-alcplugfix.sh
executable file
·151 lines (137 loc) · 4.18 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
144
145
146
147
148
149
150
151
#!/bin/bash
#set -x # for DEBUGGING
# Rewrite on Feb 27, 2019 by stevezhengshiqi, special thanks to @Menchen
# Support Xiaomi-Pro (ALC298,layout-id99)
function init() {
if [[ ${OSTYPE} != darwin* ]]; then
echo "This script can only run in macOS, aborting"
exit 1
fi
}
# 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 8th Gen (ALC298, layout-id 30/99)'
echo '======================================================'
}
# Choose option
function choice() {
echo "(1) Enable ALCPlugFix"
echo "(2) Disable ALCPlugFix"
echo "(3) Exit"
read -rp "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/Menchen/ALCPlugFix
function download(){
mkdir -p one-key-alcplugfix
cd one-key-alcplugfix || exit 1
echo "Downloading audio fix patch..."
curl -L -O https://raw.githubusercontent.com/Menchen/ALCPlugFix/master/build/Release/ALCPlugFix || networkWarn
curl -L -O https://raw.githubusercontent.com/Menchen/ALCPlugFix/master/alc_fix/good.win.ALCPlugFix.plist || networkWarn
curl -L -O https://raw.githubusercontent.com/Menchen/ALCPlugFix/master/alc_fix/hda-verb || 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 || exit 1
sudo chown "$USER":admin /usr/local/bin || exit 1
fi
sudo cp "./ALCPlugFix" /usr/local/bin/ || exit 1
sudo cp "./hda-verb" /usr/local/bin/ || exit 1
sudo cp "./good.win.ALCPlugFix.plist" /Library/LaunchDaemons/ || exit 1
echo "Copy complete"
echo
}
# Fix permission
function fixpermission() {
echo "Fixing permission..."
sudo chmod 755 /usr/local/bin/ALCPlugFix || exit 1
sudo chown "$USER":admin /usr/local/bin/ALCPlugFix || exit 1
sudo chmod 755 /usr/local/bin/hda-verb || exit 1
sudo chown "$USER":admin /usr/local/bin/hda-verb || exit 1
sudo chmod 644 /Library/LaunchDaemons/good.win.ALCPlugFix.plist || exit 1
sudo chown root:wheel /Library/LaunchDaemons/good.win.ALCPlugFix.plist || exit 1
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() {
init
interface
choice
case $alc_option in
1)
install
;;
2)
uninstall
;;
3)
exit 0
;;
*)
echo "ERROR: Invalid input, closing the script"
exit 1
;;
esac
}
main