-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.sh
executable file
·336 lines (333 loc) · 9.41 KB
/
helper.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
#!/bin/bash
die() {
echo -e "\e[0;31mSomething went wrong...\e[0m"
exit 1
}
dir="$HOME/.lenovo_v330_helper"
if [ ! -d "$dir" ]; then
mkdir -p $dir
mkdir -p $dir/{status,backup}
fi
if [ "$1" == remove ]; then rm -rf $dir; fi
if [ "$1" == change ]; then rm -f $dir/distro; fi
echo -e "Lenovo V330 Linux helper"
if [ ! -f $dir/distro ]; then
echo -e "\e[0;33m Choose your Linux distro:\e[0m"
cat <<EOF
1. Arch Linux
2. Ubuntu/Debian like
P.S. You can change it later, by executing $0 change
EOF
read -rp "> " distro
case "$distro" in
1 | A* | arch*)
distro_=Arch
;;
2 | U* | D* | debian* | ubuntu*)
distro_=Deb
;;
*)
echo "Unknown distribution."
exit 1
;;
esac
[ -f $dir/distro ] || echo $distro_ > $dir/distro
else distro_="$(cat $dir/distro)"
fi
case "$distro_" in
Arch)
PM_INSTALL() {
sudo pacman -S "$@" --noconfirm
}
PM_REMOVE() {
sudo pacman -Rs "$@" --noconfirm
}
PM_QUERY() {
if pacman -Qq "$@" &>/dev/null; then return 0; else return 1; fi
}
;;
Deb)
PM_INSTALL() {
sudo apt install "$@" -y
}
PM_REMOVE() {
sudo apt purge "$@" -y
}
PM_QUERY() {
if dpkg -s "$@" &>/dev/null; then return 0; else return 1; fi
}
;;
esac
for status in 1 2 3 4 5 6 7 8 9; do
if [ -f $dir/status/$status ]; then
if [ "$(cat $dir/status/$status)" == 1 ]; then
eval status${status}="O"
else
eval status${status}="X"
fi
else
eval status${status}="X"
fi
done
echo -e "\e[0;32m Choose what to do:\e[0m"
cat <<EOF
1. Fix 'dummy output' on ALSA/PulseAudio ($status1)
2. Install xf86-video-intel instead modesetting ($status2)
3. Fix tearing ($status3)
4. Enable Bluetooth auto-connect ($status4)
5. Switch notebook to performance mode (governor) ($status5)
6. Remove spam from 'iwlwifi' from logs ($status6)
7. Turn off the beeping thing (PC Speaker) ($status7)
8. Try to fix bluetooth headphones on PulseAudio ($status8)
9. Install new 'Mesa' driver (iris instead of i915) ($status9)
EOF
read -rp "> " action
case "$action" in
1)
if [ "$status1" = "O" ]; then
read -rp "This fix has already been applied. Restore to original condition? [y/N]: " ask
case "$ask" in "" | N* | n*) exit 0 ;; Y* | y*) RESTORE=1 ;; *) exit 1 ;; esac
else
RESTORE=0
fi
if [ "$RESTORE" == 1 ]; then
sudo mv $dir/backup/alsa.conf /etc/modprobe.d/alsa.conf 2>/dev/null
echo 0 >$dir/status/1
exit 0
else
[ -f /etc/modprobe.d/alsa.conf ] && cp /etc/modprobe.d/alsa.conf $dir/backup/alsa.conf
cat <<EOF | sudo tee -a /etc/modprobe.d/alsa.conf || die
options snd-hda-intel model=auto
EOF
echo "Done!"
echo 1 >$dir/status/1
exit 0
fi
;;
2)
if [ "$status2" = "O" ]; then
read -rp "This fix has already been applied. Restore to original condition? [y/N]: " ask
case "$ask" in "" | N* | n*) exit 0 ;; Y* | y*) RESTORE=1 ;; *) exit 1 ;; esac
else
RESTORE=0
fi
if [ "$RESTORE" == 1 ]; then
case "$distro_" in
Arch) PM_REMOVE xf86-video-intel 2>/dev/null ;;
Deb) PM_REMOVE xserver-xorg-video-intel 2>/dev/null ;;
esac
sudo mv $dir/backup/20-intel.conf /etc/X11/xorg.conf.d/20-intel.conf 2>/dev/null
echo 0 >$dir/status/2
else
case "$distro_" in
Arch) PM_QUERY xf86-video-intel || PM_QUERY xf86-video-intel-git || PM_INSTALL xf86-video-intel || die ;;
Deb) PM_QUERY xserver-xorg-video-intel || PM_INSTALL xserver-xorg-video-intel || die ;;
esac
[ -f /etc/X11/xorg.conf.d/20-intel.conf ] && cp /etc/X11/xorg.conf.d/20-intel.conf $dir/backup/20-intel.conf
cat <<EOF | sudo tee /etc/X11/xorg.conf.d/20-intel.conf || die
Section "Device"
Identifier "Intel Graphics"
Driver "intel"
Option "AccelMethod" "sna"
EndSection
EOF
echo "Done!"
echo 1 >$dir/status/2
exit 0
fi
;;
3)
if [[ "$status3" = "O" ]]; then
read -rp "This fix has already been applied. Restore to original condition? [y/N]: " ask
case "$ask" in "" | N* | n*) exit 0 ;; Y* | y*) RESTORE=1 ;; *) exit 1 ;; esac
else
RESTORE=0
fi
if [ "$RESTORE" == 1 ]; then
if [ -f /etc/X11/xorg.conf.d/20-intel.conf ]; then
sudo sed '/[[:blank:]]*Option.*TearFree.*true/d' -i /etc/X11/xorg.conf.d/20-intel.conf || die
fi
echo 0 >$dir/status/3
exit 0
else
[ ! -f /etc/X11/xorg.conf.d/20-intel.conf ] && {
echo "Apply fix n.2 first (xf86-video-intel)"
exit 0
}
sudo sed '/^EndSection/i \ \ \ Option "TearFree" "true"' -i /etc/X11/xorg.conf.d/20-intel.conf || die
echo "Done!"
echo 1 >$dir/status/3
exit 0
fi
;;
4)
if [[ "$status4" = "O" ]]; then
read -rp "This fix has already been applied. Restore to original condition? [y/N]: " ask
case "$ask" in "" | N* | n*) exit 0 ;; Y* | y*) RESTORE=1 ;; *) exit 1 ;; esac
else
RESTORE=0
fi
if [ "$RESTORE" == 1 ]; then
sudo mv $dir/backup/main.conf /etc/bluetooth/main.conf 2>/dev/null
sudo systemctl restart bluetooth
echo 0 >$dir/status/4
exit 0
else
PM_QUERY bluez || PM_INSTALL bluez || die
[ -f /etc/bluetooth/main.conf ] && cp /etc/bluetooth/main.conf $dir/backup/main.conf
if [ "$(grep -o ".*AutoEnable=.*" /etc/bluetooth/main.conf 2>/dev/null)" ]; then
sudo sed 's/.*AutoEnable=.*/AutoEnable=true/g' -i /etc/bluetooth/main.conf || die
fi
if [ ! -f /etc/bluetooth/main.conf ]; then
cat <<EOF | sudo tee /etc/bluetooth/main.conf || die
AutoEnable=true
EOF
fi
if [ "$(grep -o ".*DiscoverableTimeout = .*" /etc/bluetooth/main.conf)" ]; then
sudo sed 's/.*DiscoverableTimeout = .*/DiscoverableTimeout = 0/g' -i /etc/bluetooth/main.conf || die
else
cat <<EOF | sudo tee -a /etc/bluetooth.main.conf || die
DiscoverableTimeout = 0
EOF
fi
sudo systemctl restart bluetooth
echo "Done!"
echo 1 >$dir/status/4
exit 0
fi
;;
5)
if [ "$status5" = "O" ]; then
read -rp "This fix has already been applied. Restore to original condition? [y/N]: " ask
case "$ask" in "" | N* | n*) exit 0 ;; Y* | y*) RESTORE=1 ;; *) exit 1 ;; esac
else
RESTORE=0
fi
if [ "$RESTORE" == 1 ]; then
case "$distro_" in
Arch)
PM_QUERY cpupower && PM_REMOVE cpupower 2>/dev/null
PM_INSTALL cpufrequtils
;;
Deb)
PM_QUERY linux-tools-common && PM_REMOVE linux-tools-common
PM_INSTALL cpufrequtils 2>/dev/null
;;
esac
sudo systemctl disable cpupower-set
sudo systemctl restart cpupower 2>/dev/null
sudo rm /etc/systemd/system/cpupower-set.service
echo 0 >$dir/status/5
exit 0
else
###
case "$distro_" in
Arch)
PM_QUERY cpufrequtils && PM_REMOVE cpufrequtils
PM_QUERY cpupower || PM_INSTALL cpupower || die
;;
Deb)
PM_QUERY cpufrequtils && PM_REMOVE cpufrequtils
PM_QUERY linux-tools-common || PM_INSTALL linux-tools-common || die
;;
esac
cat <<EOF | sudo tee /etc/systemd/system/cpupower-set.service || die
[Unit]
Description=Set performance governor
Before=graphical.target
[Service]
Type=oneshot
ExecStart=/usr/bin/cpupower frequency-set -g performance
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable --now cpupower-set || die
echo "Done!"
echo 1 >$dir/status/5
exit 0
fi
;;
6)
if [ "$status6" = "O" ]; then
read -rp "This fix has already been applied. Restore to original condition? [y/N]: " ask
case "$ask" in "" | N* | n*) exit 0 ;; Y* | y*) RESTORE=1 ;; *) exit 1 ;; esac
else
RESTORE=0
fi
if [ "$RESTORE" == 1 ]; then
sudo rm /etc/modprobe.d/iwlwifi-spam.conf
echo 0 >$dir/status/6
exit 0
else
cat <<EOF | sudo tee /etc/modprobe.d/iwlwifi-spam.conf || die
options iwlwifi power_save=0
options iwlmvm power_scheme=1
EOF
echo "Done!"
echo 1 >$dir/status/6
exit 0
fi
;;
7)
if [ "$status7" = "O" ]; then
read -rp "This fix has already been applied. Restore to original condition? [y/N]: " ask
case "$ask" in "" | N* | n*) exit 0 ;; Y* | y*) RESTORE=1 ;; *) exit 1 ;; esac
else
RESTORE=0
fi
if [ "$RESTORE" == 1 ]; then
sudo mv $dir/backup/pcspkr.conf /etc/modprobe.d/pcspkr.conf 2>/dev/null
echo 0 >$dir/status/7
exit 0
else
[ -f /etc/modprobe.d/pcspkr.conf ] && cp /etc/modprobe.d/pcspkr.conf $dir/backup/pcspkr.conf
cat <<EOF | sudo tee /etc/modprobe.d/pcspkr.conf || die
blacklist pcspkr
EOF
echo "Done!"
echo 1 >$dir/status/7
exit 0
fi
;;
8)
if [ "$status8" = "O" ]; then
read -rp "This fix has already been applied. Restore to original condition? [y/N]: " ask
case "$ask" in "" | N* | n*) exit 0 ;; Y* | y*) RESTORE=1 ;; *) exit 1 ;; esac
else
RESTORE=0
fi
if [ "$RESTORE" == 1 ]; then
sudo mv $dir/backup/default.pa /etc/pulse/default.pa 2>/dev/null
sudo systemctl restart bluetooth
echo 0 >$dir/status/8
exit 0
else
[ -f /etc/pulse/default.pa ] && cp /etc/pulse/default.pa $dir/backup/default.pa
if [ "$(grep -o ".*load-module module-switch-on-connect.*" /etc/pulse/default.pa)" ]; then
sudo sed 's/.*load-module module-switch-on-connect.*/load-module module-switch-on-connect/g' -i /etc/pulse/default.pa || die
fi
sudo systemctl restart bluetooth
echo "Done!"
echo 1 >$dir/status/8
exit 0
fi
;;
9)
if [ "$status9" = "O" ]; then
read -rp "This fix has already been applied. Restore to original condition? [y/N]: " ask
case "$ask" in "" | N* | n*) exit 0 ;; Y* | y*) RESTORE=1 ;; *) exit 1 ;; esac
else
RESTORE=0
fi
if [ "$RESTORE" == 1 ]; then
sudo sed "/MESA_LOADER_DRIVER_OVERRIDE=iris/d" -i /etc/environment || die
echo 0 >$dir/status/9
exit 0
else
echo "MESA_LOADER_DRIVER_OVERRIDE=iris" | sudo tee -a /etc/environment || die
echo "Done!"
echo 1 >$dir/status/9
exit 0
fi
;;
esac