Last active
February 10, 2016 23:29
-
-
Save UdeRecife/88a9822466c7feba6e5b to your computer and use it in GitHub Desktop.
Script to reset usb ports, covering all possible cases.
This file contains 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 | |
if [ "$(id -u)" != 0 ] ; then | |
echo This must be run as root! | |
exit 1 | |
fi | |
# | |
# Look for the most comment cases | |
# | |
for driver in xhci_hcd ehci_hcd uhci_hcd xhci-pci ehci-pci uhci-pci ; do | |
# | |
# The directory to operate within | |
# | |
dir=/sys/bus/pci/drivers/${driver} | |
# | |
# If it exists we have the appropriate USB-driver | |
# | |
if [ -d $dir ]; then | |
echo "Reseting: ${driver}" | |
cd ${dir} | |
for dev_id in ????:??:??.? ; do | |
if [ "${dev_id}" == "????:??:??.?" ] ; then | |
break | |
fi | |
printf "${dev_id}" > unbind | |
printf "${dev_id}" > bind | |
done | |
else | |
echo "Not present: ${driver}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment