Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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