Last active
May 9, 2018 03:54
-
-
Save jgeboski/1ac5203927a06c9f48d50535beae7216 to your computer and use it in GitHub Desktop.
Script to suspend all USB devices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DEV_ROOT=/sys/bus/usb/devices | |
read_usb_sysfs() { | |
cat "$DEV_ROOT/$1/$2" | |
} | |
write_usb_sysfs() { | |
path="$DEV_ROOT/$1/$2" | |
[ -e "$path" ] && echo $3 > "$path" | |
} | |
device_id() { | |
vendor=$(read_usb_sysfs "$device" idVendor) | |
product=$(read_usb_sysfs "$device" idProduct) | |
echo "$vendor:$product" | |
} | |
unbind_driver() { | |
interface=$1 | |
device=$(echo $interface | cut -d: -f1) | |
[ -e "$DEV_ROOT/$device" ] || return | |
# Unbind drivers for the Logitech G710 keyboard | |
case $(device_id "$device") in 046d:c24d) | |
write_usb_sysfs "$interface" driver/unbind "$interface" | |
esac | |
} | |
for device in $(ls -1 "$DEV_ROOT" | sort -r); do | |
case "$device" in | |
*:*) # Only unbind drivers for certain interfaces | |
unbind_driver "$device" | |
continue ;; | |
usb*) # Ignore USB hubs | |
continue ;; | |
esac | |
# Suspend USB devices | |
write_usb_sysfs "$device" power/autosuspend_delay_ms 0 | |
write_usb_sysfs "$device" power/wakeup disabled | |
write_usb_sysfs "$device" power/control auto | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment