Skip to content

Instantly share code, notes, and snippets.

@pklaus
Created June 16, 2012 18:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pklaus/2942235 to your computer and use it in GitHub Desktop.
Save pklaus/2942235 to your computer and use it in GitHub Desktop.
3G Modem on Ubuntu 12.04 – Rebind USB on Failure – see http://goo.gl/aMS9B
#!/bin/bash
## Author: Philipp Klaus <philipp.klaus → AT → gmail.com>
## See <http://goo.gl/aMS9B> and <http://lwn.net/Articles/143397/>
if [ $(id -u) != 0 ];then
echo "must be run as root"
exit 2
fi
usage () {
echo "\nusage: $0 <serial modem device>\n\nexample: $0 /dev/ttyUSB0\n" >&2; exit 1
}
[ -z "$1" ] && usage
dev=$(basename $1)
sd_path="/sys/bus/usb/drivers/qcserial"
sleep_time=4
for dir in $(ls $sd_path/ | egrep -v "bind|module|new_id|remove_id|uevent|unbind"); do
if [ -n "$(ls $sd_path/$dir/$dev)" ]; then
echo "Rebinding $dir on $sd_path"
echo -n $dir > $sd_path/unbind
sleep $sleep_time
echo -n $dir > $sd_path/bind
sleep $sleep_time
killall modem-manager
sleep $sleep_time
service network-manager restart
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment