aboutsummaryrefslogtreecommitdiff
path: root/usb-disable
blob: 5268256c42665b156d2742e541900cbae6713911 (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
34
35
#!/bin/bash
#
# 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
  usb_set_state 1
elif [ "$BASENAME" == 'usb-disable' ]; then
  usb_set_state 0
elif [ "$BASENAME" == 'usb-status' ]; then
  status="`cat /sys/module/usbcore/parameters/authorized_default`"

  if [ "$status" == "0" ]; then
    echo "Hotplug disabled."
  elif [ "$status" == "1" ]; then
    echo "Hotplug enabled."
  fi
fi