diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-03-18 21:04:09 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-03-18 21:04:09 +0100 |
commit | 222301408bef7dfda449eaf22180fe6927a418a1 (patch) | |
tree | 7bdd3771d17416f4f5f08a563ec543c0353f5bb1 | |
parent | 6a1cf3b75d3fe7d88571ad75df478c0cf732dd86 (diff) | |
download | ltunify-222301408bef7dfda449eaf22180fe6927a418a1.tar.gz |
usbmon-setperms: do not grant unnecessary write
Also convert tabs to spaces.
-rwxr-xr-x | usbmon-setperms | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/usbmon-setperms b/usbmon-setperms index 3c27ce0..0aa1c37 100755 --- a/usbmon-setperms +++ b/usbmon-setperms @@ -2,32 +2,39 @@ # 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 + echo "Please run as regular user or set USER" + exit 1 fi GROUP="$(id -g)" if [ $GROUP = 0 ]; then - GROUP="$(id -g "$USER")" + 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 + 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 +usbmonsw= +for dev in $usbmons; do + if [ ! -r "$dev" ]; then + 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 - echo "No devices found" + echo "No devices found" fi |