-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathinstall_layout_auto_suggestion.sh
132 lines (111 loc) · 5.51 KB
/
install_layout_auto_suggestion.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
#!/usr/bin/env bash
source non_sudo_check.sh
LAPTOP_NAME_FULL=$(cat /sys/devices/virtual/dmi/id/product_name)
# LAPTOP_NAME_FULL="ROG Zephyrus Duo 15 SE GX551QR_GX551QR"
LAPTOP_NAME=$(echo $LAPTOP_NAME_FULL | rev | cut -d ' ' -f1 | rev | cut -d "_" -f1)
DEVICE_ID=$(cat /proc/bus/input/devices | grep ".*Touchpad\"$" | sort | cut -f 3 -d" " | cut -f 2 -d ":" | head -1)
# DEVICE_ID="3145"
VENDOR_ID=$(cat /proc/bus/input/devices | grep ".*Touchpad\"$" | sort | cut -f 3 -d" " | cut -f 1 -d ":" | head -1)
# VENDOR_ID="04F3"
# the base was provided by cz asus support and manually fixed + manually extended about missing laptops gathered from users by github issues and via GA
SUGGESTED_LAYOUT=$(cat laptop_numberpad_layouts | grep "$LAPTOP_NAME" | head -1 | cut -d'=' -f2)
# gathered from users via GA
if [[ -z "$SUGGESTED_LAYOUT" ]]; then
SUGGESTED_LAYOUT=$(cat laptop_touchpad_numberpad_layouts.csv | grep "$LAPTOP_NAME_FULL" | sort -t , -k 6 -r | head -1 | cut -d',' -f4)
else
LAYOUT_AUTO_SUGGESTION_BY_LAPTOP_PRODUCT=1
fi
if [[ -z "$SUGGESTED_LAYOUT" ]]; then
SUGGESTED_LAYOUT=$(cat laptop_touchpad_numberpad_layouts.csv | grep "$VENDOR_ID" | grep "$DEVICE_ID" | sort -t , -k 6 -r | head -1 | cut -d',' -f4)
elif [[ -z "$LAYOUT_AUTO_SUGGESTION_BY_LAPTOP_PRODUCT" ]]; then
LAYOUT_AUTO_SUGGESTION_BY_LAPTOP_NAME=1
fi
if [[ -z "$SUGGESTED_LAYOUT" || "$SUGGESTED_LAYOUT" == "none" ]]; then
LAYOUT_AUTO_SUGGESTION_ONLINE=1
# When exist device 9009:00 should return other DEVICE_ID: 3101 of 'ELAN1406:00'
#
# https://github.com/mohamed-badaoui/asus-touchpad-numpad-driver/issues/87
# https://github.com/asus-linux-drivers/asus-numberpad-driver/issues/95
#
# N: Name="ELAN9009:00 04F3:2C23 Touchpad"
# N: Name="ELAN1406:00 04F3:3101 Touchpad"
USER_AGENT="user-agent-name-here"
DEVICE_LIST_CURL_URL="https://linux-hardware.org/?view=search&vendorid=$VENDOR_ID&deviceid=$DEVICE_ID&typeid=input%2Fkeyboard"
DEVICE_LIST_CURL=$(curl --user-agent "$USER_AGENT" "$DEVICE_LIST_CURL_URL" )
# Probes identified by touchpad's VENDOR_ID & PRODUCT_ID may return probes grouped under multiple devices:
#
# e.g. returned ELAN, ASUE: https://linux-hardware.org/?view=search&vendorid=04F3&deviceid=3101&typeid=input%2Fkeyboard
#
# /?id=ps/2:04f3-3101-elan1406-00-04f3-3101-keyboard
# /?id=ps/2:04f3-3101-asue1406-00-04f3-3101-keyboard
DEVICE_URL_LIST=$(echo $DEVICE_LIST_CURL | xmllint --html --xpath '//td[@class="device"]//a[1]/@href' 2>/dev/null -)
IFS='\"' read -r -a array <<< $(echo $DEVICE_URL_LIST)
for INDEX in "${!array[@]}"
do
if [[ "${array[INDEX]}" != " href=" && "${array[INDEX]}" != "href=" ]]; then
LAPTOP_LIST_CURL_URL="https://linux-hardware.org$DEVICE_URL"
LAPTOP_LIST_CURL=$(curl --user-agent "$USER_AGENT" "$LAPTOP_LIST_CURL_URL" )
LAPTOP_LIST=$(echo $LAPTOP_LIST_CURL | xmllint --html --xpath '//table[contains(@class, "computers_list")]//tr/td[3]/span/@title' 2>/dev/null -)
# create laptop array
#
# [0] = Zenbook UX3402ZA_UX3402ZA
# [1] = Zenbook UM5401QAB_UM5401QA
# ...
#
IFS='\"' read -r -a array <<< $(echo $LAPTOP_LIST)
for INDEX in "${!array[@]}"
do
if [[ "${array[INDEX]}" != " title=" && "${array[INDEX]}" != "title=" ]]; then
PROBE_LAPTOP_NAME_FULL="${array[INDEX]}"
PROBE_LAPTOP_NAME=$( echo $PROBE_LAPTOP_NAME_FULL | rev | cut -d ' ' -f1 | rev | cut -d "_" -f1)
SUGGESTED_LAYOUT=$(cat laptop_numberpad_layouts | grep "$PROBE_LAPTOP_NAME" | head -1 | cut -d'=' -f2)
if [[ -z "$SUGGESTED_LAYOUT" ]]; then
SUGGESTED_LAYOUT=$(cat laptop_touchpad_numberpad_layouts.csv | grep "$PROBE_LAPTOP_NAME_FULL" | head -1 | cut -d',' -f4)
else
LAYOUT_AUTO_SUGGESTION_BY_LAPTOP_PRODUCT=1
fi
if [[ -z "$SUGGESTED_LAYOUT" || "$SUGGESTED_LAYOUT" == "none" ]]; then
continue
else
LAYOUT_AUTO_SUGGESTION_BY_LAPTOP_NAME=1
break
fi
fi
done
fi
done
if [[ -z "$SUGGESTED_LAYOUT" || "$SUGGESTED_LAYOUT" == "none" ]]; then
echo
echo "Could not automatically detect NumberPad layout for your laptop."
else
LAYOUT_AUTO_SUGGESTION_ONLINE_FOUND=1
fi
else
LAYOUT_AUTO_SUGGESTION_OFFLINE_FOUND=1
if [[ -z "$LAYOUT_AUTO_SUGGESTION_BY_LAPTOP_PRODUCT" && -z "$LAYOUT_AUTO_SUGGESTION_BY_LAPTOP_NAME" ]]; then
LAYOUT_AUTO_SUGGESTION_BY_VENDOR_DEVICE=1
fi
fi
for OPTION in $(ls layouts); do
if [ "$OPTION" = "$SUGGESTED_LAYOUT.py" ]; then
echo
echo "NumberPad layout"
echo
read -r -p "The automatically recommended NumberPad layout for this laptop ($LAPTOP_NAME_FULL) is $SUGGESTED_LAYOUT. Do you want to use the $SUGGESTED_LAYOUT layout? (The photo of the recommended NumberPad layout can be found here https://github.com/asus-linux-drivers/asus-numberpad-driver#$SUGGESTED_LAYOUT) [y/N]" RESPONSE
case "$RESPONSE" in [yY][eE][sS]|[yY])
echo
LAYOUT_AUTO_SUGGESTION=1
LAYOUT_NAME=$SUGGESTED_LAYOUT
SPECIFIC_BRIGHTNESS_VALUES="$LAYOUT_NAME-$DEVICE_ID"
if [ -f "layouts/$SPECIFIC_BRIGHTNESS_VALUES.py" ];
then
LAYOUT_NAME=$SPECIFIC_BRIGHTNESS_VALUES
echo "Selected key layout specified by touchpad ID: $DEVICE_ID"
fi
echo "Selected key layout: $LAYOUT_NAME"
;;
*)
;;
esac
fi
done