usbmon-setperms: do not grant unnecessary write

Also convert tabs to spaces.
This commit is contained in:
Peter Wu
2014-03-18 21:04:09 +01:00
parent 6a1cf3b75d
commit 222301408b

View File

@@ -2,32 +2,39 @@
# helper for allowing the developer to read usbmon as non-root. # helper for allowing the developer to read usbmon as non-root.
if [ "$USER" = "root" ]; then if [ "$USER" = "root" ]; then
echo "Please run as regular user or set USER" echo "Please run as regular user or set USER"
exit 1 exit 1
fi fi
GROUP="$(id -g)" GROUP="$(id -g)"
if [ $GROUP = 0 ]; then if [ $GROUP = 0 ]; then
GROUP="$(id -g "$USER")" GROUP="$(id -g "$USER")"
fi fi
if [ ! -e /dev/usbmon0 ]; then if [ ! -e /dev/usbmon0 ]; then
echo "Attempting to modprobe usbmon..." echo "Attempting to modprobe usbmon..."
sudo modprobe -v usbmon sudo modprobe -v usbmon
if [ ! -e /dev/usbmon0 ]; then if [ ! -e /dev/usbmon0 ]; then
echo "Cannot locate 'usbmon' kernel module" echo "Cannot locate 'usbmon' kernel module"
exit 1 exit 1
fi fi
fi fi
usbmons=$(lsusb -d046d: | cut -c7 | sed 's,^,/dev/usbmon,' | sort -u) usbmons=$(lsusb -d046d: | cut -c7 | sed 's,^,/dev/usbmon,' | sort -u)
echo Found devices: $usbmons echo Found devices: $usbmons
if [ -n "$usbmons" ]; then usbmonsw=
echo "Attempting to change permissions..." for dev in $usbmons; do
sudo chgrp -v $GROUP $usbmons if [ ! -r "$dev" ]; then
sudo chmod -v g+rw $usbmons usbmonsw="$usbmonsw $dev"
fi
done
if [ -n "$usbmonsw" ]; then
echo "Attempting to make $usbmonsw readable"
sudo chgrp -v $GROUP $usbmonsw
sudo chmod -v g+r $usbmonsw
else else
echo "No devices found" echo "No devices found"
fi fi