forked from OpenTabletDriver/OpenTabletDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-rules.sh
executable file
·71 lines (58 loc) · 2.3 KB
/
generate-rules.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
#!/usr/bin/env bash
# dependencies: jq, tr (coreutils), awk (gawk), sed (gnused)
print_help() {
echo "Usage: ${BASH_SOURCE[0]} [OPTIONS]..."
echo "Options:"
echo " -c, --configurations <configurations> Source configurations directory"
echo " -h, --help Print this help message"
}
for c in jq tr awk sed; do
command -v $c > /dev/null
if [[ $? > 0 ]]; then
echo "Error: Command $c not found in \$PATH." >&2
exit 1
fi
done
tohex() {
printf $1 | awk '{ printf("%04x", $1) }'
}
shopt -s globstar
set -eu
OTD_CONFIGURATIONS="${OTD_CONFIGURATIONS:="$(dirname ${BASH_SOURCE[0]})/OpenTabletDriver.Configurations/Configurations"}"
while [ $# -gt 0 ]; do
case "$1" in
-c=*|--configurations=*)
OTD_CONFIGURATIONS="${1#*=}"
;;
-c|--configurations)
OTD_CONFIGURATIONS="$2"
shift
;;
*)
print_help
exit 1
;;
esac
shift
done
script='[
.[] | { Name:.Name, libinput:(.Attributes.libinputoverride // "0") } + (.DigitizerIdentifiers[] | { VendorID:.VendorID, ProductID:.ProductID })
] | unique | sort_by(.VendorID,.ProductID) | group_by(.VendorID, .ProductID) |
map({ Names: (map(.Name) | join(",")), libinput: (map(.libinput) | max), VendorID: .[0].VendorID, ProductID: .[0].ProductID})
| .[] | "\(.Names):\(.VendorID):\(.ProductID):\(.libinput)"'
configs_arr=$(jq -s "$script" $OTD_CONFIGURATIONS/**/**.json | tr -d '"')
echo \# OpenTabletDriver udev rules \(https://github.com/OpenTabletDriver/OpenTabletDriver\)
echo KERNEL==\"uinput\", SUBSYSTEM==\"misc\", OPTIONS+=\"static_node=uinput\", TAG+=\"uaccess\", TAG+=\"udev-acl\"
echo KERNEL==\"js[0-9]*\", SUBSYSTEM==\"input\", ATTRS{name}==\"OpenTabletDriver Virtual Tablet\", RUN+=\"/usr/bin/env rm %E{DEVNAME}\"
IFS=':'
while read s; do
read -r names vid pid libinput <<< $s
vid=$(tohex $vid)
pid=$(tohex $pid)
echo \# $(echo $names | sed 's/,/\n# /g')
echo KERNEL==\"hidraw*\", ATTRS{idVendor}==\"$vid\", ATTRS{idProduct}==\"$pid\", TAG+=\"uaccess\", TAG+=\"udev-acl\"
echo SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"$vid\", ATTRS{idProduct}==\"$pid\", TAG+=\"uaccess\", TAG+=\"udev-acl\"
if [[ $libinput > 0 ]]; then
echo SUBSYSTEM==\"input\", ATTRS{idVendor}==\"$vid\", ATTRS{idProduct}==\"$pid\", ENV{LIBINPUT_IGNORE_DEVICE}=\"$libinput\"
fi
done <<< $configs_arr