Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

less commands to create dev_title and dev_name #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions my-udev-notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,11 @@ notify_unplugged()

if [[ "$bus_num" != "" && "$dev_num" != "" ]]; then

# make bus_num and dev_num have leading zeros
bus_num=`printf %03d $bus_num`
dev_num=`printf %03d $dev_num`

# Retrieve device title. Currently it's done just by lsusb and grep.
# Not so good: if one day lsusb change its output format, this script
# might stop working.
dev_title=`lsusb -D /dev/bus/usb/$bus_num/$dev_num | grep '^Device:\|bInterfaceClass\|bInterfaceSubClass\|bInterfaceProtocol'|sed 's/^\s*\([a-zA-Z]\+\):*\s*[0-9]*\s*/<b>\1:<\/b> /' | awk 1 ORS='###'`
dev_name=`lsusb -D /dev/bus/usb/$bus_num/$dev_num | grep idProduct | tr -s ' ' | cut -s -d' ' -f4,5,6,7,8,9`
dev_title="$(lsusb -v -s $bus_num:$dev_num | awk '/ Device /{if($1=="Bus")print ":<b>" substr($0, index($0,$5)) "</b>"}; /bInterfaceClass|bInterfaceProtocol/{print "<b>" $1 ":</b> " substr($0, index($0,$3)) }' ORS='###')"
dev_name="$(lsusb -v -s $bus_num:$dev_num | grep -Po "(?<=idProduct\ {10}0x\S{4} ).*")"

# Sometimes we might have the same device attached to different bus_num or dev_num:
# in this case, we just modify bus_num and dev_num to the current ones.
Expand Down