aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xusb-disable24
l---------[-rwxr-xr-x]usb-enable18
l---------[-rwxr-xr-x]usb-status18
3 files changed, 23 insertions, 37 deletions
diff --git a/usb-disable b/usb-disable
index cc4525e..5268256 100755
--- a/usb-disable
+++ b/usb-disable
@@ -2,16 +2,34 @@
#
# USB hotplug switcher.
# See https://links.sarava.org/tags/badusb
+# https://www.kernel.org/doc/Documentation/usb/authorization.txt
#
# Parameters
BASENAME="`basename $0`"
+# Set hotplug state
+function usb_set_state {
+ echo "Applying at /sys/module/usbcore/parameters/authorized_default..."
+ sudo su -c "echo $1 > /sys/module/usbcore/parameters/authorized_default"
+
+ for bus in /sys/bus/usb/devices/usb*; do
+ echo "Applying at ${bus}/authorized_default..."
+ sudo su -c "echo $1 > ${bus}/authorized_default"
+ done
+}
+
# Dispatch
if [ "$BASENAME" == 'usb-enable' ]; then
- sudo su -c "echo '-1' > /sys/module/usbcore/parameters/authorized_default"
+ usb_set_state 1
elif [ "$BASENAME" == 'usb-disable' ]; then
- sudo su -c "echo '0' > /sys/module/usbcore/parameters/authorized_default"
+ usb_set_state 0
elif [ "$BASENAME" == 'usb-status' ]; then
- cat /sys/module/usbcore/parameters/authorized_default
+ status="`cat /sys/module/usbcore/parameters/authorized_default`"
+
+ if [ "$status" == "0" ]; then
+ echo "Hotplug disabled."
+ elif [ "$status" == "1" ]; then
+ echo "Hotplug enabled."
+ fi
fi
diff --git a/usb-enable b/usb-enable
index cc4525e..f54f446 100755..120000
--- a/usb-enable
+++ b/usb-enable
@@ -1,17 +1 @@
-#!/bin/bash
-#
-# USB hotplug switcher.
-# See https://links.sarava.org/tags/badusb
-#
-
-# Parameters
-BASENAME="`basename $0`"
-
-# Dispatch
-if [ "$BASENAME" == 'usb-enable' ]; then
- sudo su -c "echo '-1' > /sys/module/usbcore/parameters/authorized_default"
-elif [ "$BASENAME" == 'usb-disable' ]; then
- sudo su -c "echo '0' > /sys/module/usbcore/parameters/authorized_default"
-elif [ "$BASENAME" == 'usb-status' ]; then
- cat /sys/module/usbcore/parameters/authorized_default
-fi
+usb-disable \ No newline at end of file
diff --git a/usb-status b/usb-status
index cc4525e..f54f446 100755..120000
--- a/usb-status
+++ b/usb-status
@@ -1,17 +1 @@
-#!/bin/bash
-#
-# USB hotplug switcher.
-# See https://links.sarava.org/tags/badusb
-#
-
-# Parameters
-BASENAME="`basename $0`"
-
-# Dispatch
-if [ "$BASENAME" == 'usb-enable' ]; then
- sudo su -c "echo '-1' > /sys/module/usbcore/parameters/authorized_default"
-elif [ "$BASENAME" == 'usb-disable' ]; then
- sudo su -c "echo '0' > /sys/module/usbcore/parameters/authorized_default"
-elif [ "$BASENAME" == 'usb-status' ]; then
- cat /sys/module/usbcore/parameters/authorized_default
-fi
+usb-disable \ No newline at end of file