summaryrefslogtreecommitdiff
path: root/extras/inputdev.sh
blob: 82e4fdc37440fb995ae1515b6ce6f38d6dc260d7 (plain)
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
#!/bin/sh -e
#
# Scans /proc/bus/input/devices for the given device.
#
# (c) 2004 Darren Salt <linux@youmustbejoking.demon.co.uk>
# GPL v2 or later applies.

[ "$1" ] || exit 0

# input device name, less leading "input/"
DEVICE=${1#input/}

# "|"-separated list.
# The first found in the given device's "N:" line will be output.
DEFAULT_KEYWORDS='dvb|saa7134'
KEYWORDS=${2:-$DEFAULT_KEYWORDS}

exec sed -nre '
  /^I:/ {
    : gather
    N
    /\nH:/! b gather
    /'"$DEVICE"'/ {
      s/^.*\nN:[^\n]*("|\b)('"$KEYWORDS"')("|\b)[^\n]*\n.*$/inputdev/
      T
      p
    }
  }
' < /proc/bus/input/devices