Last active
September 27, 2017 12:41
-
-
Save kou1okada/0a2bb903e633f7417cd905287faa2bc2 to your computer and use it in GitHub Desktop.
usbhub_rebind.sh - USB hub rebind.
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
#!/usr/bin/env bash | |
# | |
# USB hub rebind | |
# Copyright (c) 2017 Koichi OKADA. All rights reserved. | |
# This script is distributed under the MIT license. | |
# | |
function usbhub_rebind () #= usb[0-9]+ | |
{ | |
local PCIDEV="$(realpath "/sys/bus/usb/devices/${1}")" | |
PCIDEV="${PCIDEV%/*}" | |
local DRIVER="$(realpath "${PCIDEV}/driver")" | |
local PCIBUS="${PCIDEV##*/}" | |
cat<<-EOD | |
echo "${PCIBUS}" | sudo tee "${DRIVER}/unbind" | |
sleep 1 | |
echo "${PCIBUS}" | sudo tee "${DRIVER}/bind" | |
EOD | |
} | |
if (( $# < 1 )); then | |
cat<<-EOD | |
Usage: ${0##*/} ubs[0-9]+ ... | sh | |
EOD | |
exit 1 | |
fi | |
for i in "$@"; do | |
usbhub_rebind "$i" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment