summary refs log tree commit diff
path: root/bin/usb2sys
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-01-26 17:16:07 +0100
committerRobert Günzler <r@gnzler.io>2020-01-26 18:00:59 +0100
commitf5d56602df70950de6b7d40966b00c9939c81763 (patch)
treeb50ffeb5496fe3525cc1bab2629389ced95435b7 /bin/usb2sys
Intial commit of v2
See https://drewdevault.com/2019/12/30/dotfiles.html
Diffstat (limited to 'bin/usb2sys')
-rwxr-xr-xbin/usb2sys36
1 files changed, 36 insertions, 0 deletions
diff --git a/bin/usb2sys b/bin/usb2sys
new file mode 100755
index 0000000..d810431
--- /dev/null
+++ b/bin/usb2sys
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# usb2sys - find lsusb device in /sys file system
+#
+# https://superuser.com/a/1253083
+#
+
+die()
+{
+    echo "$@"
+    exit 1
+}
+
+[[ $# -lt 1 ]] && die "need vendor and product ids (from lsusb) as dddd:dddd"
+
+vendor=${1%:*}
+product=${1##*:}
+
+sys=/sys/bus/usb/devices/
+cd $sys
+
+for d in *; do
+    path=$sys/$d
+    if [ -f $path/idProduct ]; then
+      prod=$( cat $path/idProduct )
+      vend=$( cat $path/idVendor )
+
+      if [ $prod = $product -a $vend = $vendor ]; then
+        echo prod = $prod
+        echo vend = $vend
+        echo /sys device is $path
+        cat $path/power/wakeup
+        echo ""
+      fi
+    fi
+done