Repository navigation
Expand file tree
/
Copy pathsetup-udev.sh
More file actions
executable file
·37 lines (34 loc) · 1.71 KB
/
Copy pathsetup-udev.sh
File metadata and controls
executable file
·37 lines (34 loc) · 1.71 KB
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
#!/usr/bin/env bash
# Give the logged-in user the device access lankvm needs. Run with sudo.
#
# server: read the keyboards, mice and touchpads, and write /dev/uinput
# client: write /dev/uinput only
#
# Access follows the active local session (systemd-logind "uaccess"): it lands
# without logging out, and goes when the session ends. Reading keyboards is
# what lankvm needs and also what a keylogger needs, so the client is not given
# it. Delete /etc/udev/rules.d/70-lankvm.rules to withdraw all of it.
set -euo pipefail
role=${1:-}
[[ $role == server || $role == client ]] || { echo "usage: sudo setup-udev.sh server|client" >&2; exit 2; }
[[ $EUID -eq 0 ]] || { echo "run with sudo" >&2; exit 1; }
rules=/etc/udev/rules.d/70-lankvm.rules
{
echo "# lankvm ($role): written by setup-udev.sh. Delete this file to withdraw the access."
echo 'KERNEL=="uinput", SUBSYSTEM=="misc", TAG+="uaccess", OPTIONS+="static_node=uinput"'
if [[ $role == server ]]; then
echo 'SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_KEY}=="1", TAG+="uaccess"'
echo 'SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_MOUSE}=="1", TAG+="uaccess"'
echo 'SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_TOUCHPAD}=="1", TAG+="uaccess"'
fi
} >"$rules"
modprobe uinput
udevadm control --reload
udevadm trigger --action=change --subsystem-match=misc --sysname-match=uinput
if [[ $role == server ]]; then
udevadm trigger --action=change --subsystem-match=input --property-match=ID_INPUT_KEY=1
udevadm trigger --action=change --subsystem-match=input --property-match=ID_INPUT_MOUSE=1
udevadm trigger --action=change --subsystem-match=input --property-match=ID_INPUT_TOUCHPAD=1
fi
udevadm settle
echo "wrote $rules"