summaryrefslogtreecommitdiff
path: root/usbmon-setperms
blob: 3c27ce06e715c546f13c6efdb118508fcf0eda5a (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
31
32
33
#!/bin/sh
# helper for allowing the developer to read usbmon as non-root.

if [ "$USER" = "root" ]; then
	echo "Please run as regular user or set USER"
	exit 1
fi

GROUP="$(id -g)"
if [ $GROUP = 0 ]; then
	GROUP="$(id -g "$USER")"
fi

if [ ! -e /dev/usbmon0 ]; then
	echo "Attempting to modprobe usbmon..."
	sudo modprobe -v usbmon
	if [ ! -e /dev/usbmon0 ]; then
		echo "Cannot locate 'usbmon' kernel module"
		exit 1
	fi
fi

usbmons=$(lsusb -d046d: | cut -c7 | sed 's,^,/dev/usbmon,' | sort -u)

echo Found devices: $usbmons

if [ -n "$usbmons" ]; then
	echo "Attempting to change permissions..."
	sudo chgrp -v $GROUP $usbmons
	sudo chmod -v g+rw $usbmons
else
	echo "No devices found"
fi