chiark / gitweb /
move some helpers from extras to /lib/udev
[elogind.git] / extras / inputdev.sh
1 #!/bin/sh -e
2 #
3 # Scans /proc/bus/input/devices for the given device.
4 #
5 # (c) 2004 Darren Salt <linux@youmustbejoking.demon.co.uk>
6 # GPL v2 or later applies.
7
8 [ "$1" ] || exit 0
9
10 # input device name, less leading "input/"
11 DEVICE=${1#input/}
12
13 # "|"-separated list.
14 # The first found in the given device's "N:" line will be output.
15 DEFAULT_KEYWORDS='dvb|saa7134'
16 KEYWORDS=${2:-$DEFAULT_KEYWORDS}
17
18 exec sed -nre '
19   /^I:/ {
20     : gather
21     N
22     /\nH:/! b gather
23     /'"$DEVICE"'/ {
24       s/^.*\nN:[^\n]*("|\b)('"$KEYWORDS"')("|\b)[^\n]*\n.*$/inputdev/
25       T
26       p
27     }
28   }
29 ' < /proc/bus/input/devices
30