Skip to content

Instantly share code, notes, and snippets.

@nuklea
Created June 15, 2012 11:52
Show Gist options
  • Save nuklea/2936084 to your computer and use it in GitHub Desktop.
Save nuklea/2936084 to your computer and use it in GitHub Desktop.
Script for corrent unbind usb devices before suspend
#!/bin/sh
# Put this file into /etc/pm/sleep.d and don't forget
# `chmod +x to /etc/pm/sleep.d/20custom-hcd.sh'
# See http://ubuntuforums.org/showpost.php?p=11534892&postcount=88
TMPLIST=/tmp/hdc-dev-list
case "${1}" in
hibernate|suspend)
> $TMPLIST
for i in $(find /sys/bus/pci/drivers/{xhci,ehci}_hcd | egrep '[0-9a-z]+\:[0-9a-z]+\:.*$'); do
device=$(basename $i)
path=$(dirname $i)/unbind
echo "Unbind device $device in $path"
echo -n $device > $path
echo $i >> $TMPLIST
done
;;
resume|thaw)
for i in $(cat $TMPLIST); do
device=$(basename $i)
path=$(dirname $i)/bind
echo "Bind device $device in $path"
echo -n $device > $path
done
rm $TMPLIST
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment