forked from niizam/vantage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vantage.sh
150 lines (131 loc) · 5.66 KB
/
vantage.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
#!/bin/bash
#Requirement: zenity, xinput, networkmanager, pulseaudio or pipewire-pulse
#Authors: Nizam (nizam@europe.com), Lanchon (https://github.com/Lanchon)
ENABLE_FAN_MODE=1
VPC="/sys/bus/platform/devices/VPC2004\:*"
touchpad_id="$(xinput list | grep "Touchpad" | cut -d '=' -f2 | awk '{print $1}')"
get_conservation_mode_status() {
cat $VPC/conservation_mode | awk '{print ($1 == "1") ? "On" : "Off"}'
}
get_usb_charging_status() {
cat $VPC/usb_charging | awk '{print ($1 == "1") ? "On" : "Off"}'
}
get_fan_mode_status() {
cat $VPC/fan_mode | awk '{
if ($1 == "133" || $1 == "0") print "Super Silent";
else if ($1 == "1") print "Standard";
else if ($1 == "2") print "Dust Cleaning";
else if ($1 == "4") print "Efficient Thermal Dissipation";
}'
}
get_fn_lock_status() {
cat $VPC/fn_lock | awk '{print ($1 == "1") ? "Off" : "On"}'
}
get_camera_status() {
lsmod | grep -q 'uvcvideo' && echo "On" || echo "Off"
}
get_microphone_status() {
pactl get-source-mute @DEFAULT_SOURCE@ | awk '{print ($2 == "yes") ? "Muted" : "Active"}'
}
get_touchpad_status() {
xinput --list-props "$touchpad_id" | grep "Device Enabled" | cut -d ':' -f2 | awk '{print ($1 == "1") ? "On" : "Off"}'
}
get_wifi_status() {
nmcli radio wifi | awk '{print ($1 == "enabled") ? "On" : "Off"}'
}
SUBMENU_ON="Activate"
SUBMENU_OFF="Deactivate"
show_submenu() {
local title="$1"
local status="$2"
zenity --list --title "$title" --text "Status: $status" --column "Menu" "${@:3}"
}
show_submenu_on_off() {
show_submenu "$@" "$SUBMENU_ON" "$SUBMENU_OFF"
}
main() {
while :; do
local options=()
test -f $VPC/conservation_mode && options+=("Conservation Mode" "$(get_conservation_mode_status)")
test -f $VPC/usb_charging && options+=("Always-On USB" "$(get_usb_charging_status)")
test -f $VPC/fan_mode && test "$ENABLE_FAN_MODE" = 1 && options+=("Fan Mode" "$(get_fan_mode_status)")
test -f $VPC/fn_lock && options+=("FN Lock" "$(get_fn_lock_status)")
modinfo -n uvcvideo >/dev/null && options+=("Camera" "$(get_camera_status)")
which pactl >/dev/null && options+=("Microphone" "$(get_microphone_status)")
test -n "$touchpad_id" && options+=("Touchpad" "$(get_touchpad_status)")
which nmcli >/dev/null && options+=("WiFi" "$(get_wifi_status)")
local menu="$(zenity --list --title "Lenovo Vantage" --text "Select function:" --column "Function" --column "Status" "${options[@]}" --height 340 --width 350)"
case "$menu" in
"Conservation Mode")
local submenu="$(show_submenu_on_off "Conservation Mode" "$(get_conservation_mode_status)")"
case "$submenu" in
"$SUBMENU_ON") echo "1" | pkexec tee $VPC/conservation_mode ;;
"$SUBMENU_OFF") echo "0" | pkexec tee $VPC/conservation_mode ;;
esac
;;
"Always-On USB")
local submenu="$(show_submenu_on_off "Always-On USB" "$(get_usb_charging_status)")"
case "$submenu" in
"$SUBMENU_ON") echo "1" | pkexec tee $VPC/usb_charging ;;
"$SUBMENU_OFF") echo "0" | pkexec tee $VPC/usb_charging ;;
esac
;;
"Fan Mode")
local submenu="$(show_submenu "Fan Mode" "$(get_fan_mode_status)" --height 250 --width 300 \
"Super Silent" \
"Standard" \
"Dust Cleaning" \
"Efficient Thermal Dissipation" \
)"
case "$submenu" in
"Super Silent") echo "0" | pkexec tee $VPC/fan_mode ;;
"Standard") echo "1" | pkexec tee $VPC/fan_mode ;;
"Dust Cleaning") echo "2" | pkexec tee $VPC/fan_mode ;;
"Efficient Thermal Dissipation") echo "4" | pkexec tee $VPC/fan_mode ;;
esac
;;
"FN Lock")
local submenu="$(show_submenu_on_off "FN Lock" "$(get_fn_lock_status)")"
case "$submenu" in
"$SUBMENU_ON") echo "0" | pkexec tee $VPC/fn_lock ;;
"$SUBMENU_OFF") echo "1" | pkexec tee $VPC/fn_lock ;;
esac
;;
"Camera")
local submenu="$(show_submenu_on_off "Camera" "$(get_camera_status)")"
case "$submenu" in
"$SUBMENU_ON") pkexec modprobe uvcvideo ;;
"$SUBMENU_OFF") pkexec modprobe -r uvcvideo ;;
esac
;;
"Microphone")
local submenu="$(show_submenu "Microphone" "$(get_microphone_status)" \
"Mute" \
"Unmute" \
)"
case "$submenu" in
"Mute") pactl set-source-mute @DEFAULT_SOURCE@ 1 ;;
"Unmute") pactl set-source-mute @DEFAULT_SOURCE@ 0 ;;
esac
;;
"Touchpad")
local submenu="$(show_submenu_on_off "Touchpad" "$(get_touchpad_status)")"
case "$submenu" in
"$SUBMENU_ON") xinput enable "$touchpad_id" ;;
"$SUBMENU_OFF") xinput disable "$touchpad_id" ;;
esac
;;
"WiFi")
local submenu="$(show_submenu_on_off "WiFi" "$(get_wifi_status)")"
case "$submenu" in
"$SUBMENU_ON") nmcli radio wifi on ;;
"$SUBMENU_OFF") nmcli radio wifi off ;;
esac
;;
*)
break
;;
esac
done
}
main "$@"