forked from daliansky/XiaoMi-Pro-Hackintosh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
one-key-alcplugfix_cn.sh
executable file
·143 lines (130 loc) · 3.98 KB
/
one-key-alcplugfix_cn.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
# stevezhengshiqi重写于2019.02.27, 特别感谢@Menchen
# 支持小米笔记本Pro (ALC298,节点99)
# 界面 (参考: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 '支持小米笔记本电脑Pro(ALC298, 节点99)'
echo '==============================================='
}
# 选择选项
function choice() {
echo "(1) 开启 ALCPlugFix"
echo "(2) 关闭 ALCPlugFix"
echo "(3) 退出"
read -p "你想选择哪个选项? (1/2/3):" alc_option
echo
}
# 如果网络连接失败则退出
function networkWarn(){
echo "错误: 下载ALCPlugFix失败, 请检查网络连接状态"
clean
exit 1
}
# 下载资源来自 https://github.com/daliansky/XiaoMi-Pro/master/ALCPlugFix 和 https://github.com/Menchen/ALCPlugFix/tree/master/build/Release
function download(){
mkdir -p one-key-alcplugfix
cd one-key-alcplugfix
echo "正在下载声卡修复文件..."
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 "下载完成"
echo
}
# 拷贝声卡修复文件
function copy() {
echo "正在拷贝声卡修复文件..."
if [ ! -d "/usr/local/bin" ]; then
echo "'/usr/local/bin' 不存在, 新建中..."
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 "拷贝完成"
echo
}
# 修复权限
function fixpermission() {
echo "正在修复权限..."
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 "修复完成"
echo
}
# 加载进程
function loadservice() {
echo "正在加载进程..."
sudo launchctl load /Library/LaunchDaemons/good.win.ALCPlugFix.plist
echo "加载完成"
echo
}
# 清理
function clean() {
echo "正在清理..."
sudo rm -rf ../one-key-alcplugfix
echo "清理完成"
echo
}
# 卸载
function uninstall() {
echo "正在卸载..."
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 "卸载完成"
echo
if [[ $1 = "cleanup" ]]; then
return
else exit 0
fi
}
# 安装程序
function install(){
download
uninstall "cleanup"
copy
fixpermission
loadservice
clean
echo '棒!安装ALCPlugFix守护进程完成!'
exit 0
}
# 主程序
function main() {
interface
choice
case $alc_option in
1)
install
;;
2)
uninstall
;;
3)
exit 0
;;
*)
echo "错误: 输入有误, 将关闭脚本"
exit 1
;;
esac
}
main