Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Last active September 27, 2017 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kou1okada/0a2bb903e633f7417cd905287faa2bc2 to your computer and use it in GitHub Desktop.
Save kou1okada/0a2bb903e633f7417cd905287faa2bc2 to your computer and use it in GitHub Desktop.
usbhub_rebind.sh - USB hub rebind.
#!/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