-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrecord_usb.sh
executable file
·44 lines (34 loc) · 1.05 KB
/
record_usb.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
#!/bin/bash
set -e
# Attempt to emit full umockdev recording for a USB device to tmp.umockdev
# This takes care of the annoying nature of subdevices and should result in
# a complete tree, with required hid nodes too
BUS="$1"
DEVICE="$2"
if [[ -z "$BUS" ]]; then
echo "Must provide bus and device"
exit 1
fi
if [[ -z "$DEVICE" ]]; then
echo "Must provide bus and device"
exit 1
fi
if [[ ! -e "/dev/bus/usb/${BUS}/${DEVICE}" ]] ; then
echo "Specified USB device does not exist"
exit 1
fi
# Figure out the sysfs node for the device
SYSFS_NODE=$(echo "/sys`udevadm info /dev/bus/usb/${BUS}/${DEVICE}|head -n1|awk '{print $2}'`")
if [[ ! -e "${SYSFS_NODE}" ]]; then
echo "Cannot find sysfs node"
exit 1
fi
# Find the device ID to perform a split for ports
devID=`basename "${SYSFS_NODE}"`
# Find all directories containing an exposed device and merge them
NODES=""
for item in `find ${SYSFS_NODE}/${devID}:* -maxdepth 2 -name modalias -type f`; do
NODES+="`dirname $item` "
done
# Record it.
sudo umockdev-record $NODES > tmp.umockdev