Created
June 16, 2012 18:47
-
-
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
This file contains 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
#!/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