#!/bin/bash # Company: PowerCraft Technology # Author: Copyright Jelle de Jong # Note: Please send me an email if you enhanced the script # Version: 0.0.1 # Date: 31-03-2008 # System: Ubuntu/Debian GNU/Linux # Description: Create a HSDPA connection with the USB Huawei E220 # Usage: Make sure you first followed the setup guide for the device # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more de/usr/bin/tails. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # todo: # issues that are not solved: # find a correct way to use the device without sudo rights # currently i added wvdial to the sudoers file # the following iformation is based on the information found in: # /media/20071107_130928/apn.xml # when using a vodafone data simcard use "office.vodafone.nl" # when using a vodafone prepaid simcard use "live.vodafone.com" # change the apn further below in the Init3 command cecho() { if [ "$1" = "black" ]; then echo -ne "\E[30m" elif [ "$1" = "red" ]; then echo -ne "\E[31m" elif [ "$1" = "green" ]; then echo -ne "\E[32m" elif [ "$1" = "yellow" ]; then echo -ne "\E[33m" elif [ "$1" = "blue" ]; then echo -ne "\E[34m" elif [ "$1" = "magenta" ]; then echo -ne "\E[35m" elif [ "$1" = "cyan" ]; then echo -ne "\E[36m" fi echo $2 $3 tput sgr0 } if [ ! -e /usr/bin/wvdial ] then cecho "red" "wvdial not found, installing now" sudo apt-get install wvdial fi if [ ! -e /usr/sbin/pppd ] then cecho "red" "pppd not found, installing now" sudo apt-get install ppp fi if [ ! -e /usr/bin/bwm-ng ] then cecho "red" "bwm-ng not found, installing now" sudo apt-get install bwm-ng fi #~ if [ $(sudo cat /etc/sudoers | grep "/usr/bin/wvdial") ] #~ then #~ cecho "red" "sudoers and wvdial not configured, configuring now" #~ hostname=$(cat /etc/hostname) #~ user=$(whoami) #~ sudo bash -c "echo $user $hostname = NOPASSWD: /usr/bin/wvdial >> /etc/sudoers" #~ fi #~ route -n #~ route del default gw sudo rmmod option sudo rmmod usbserial sudo modprobe usbserial vendor=0x12d1 product=0x1003 sudo /etc/init.d/networking stop unset ready maximum=30 count=0 while [ -z "$ready" ] && [ "$count" -lt "$maximum" ] do count=$(($count+1)) cd /dev/ for interface in ttyUSB* do if [ "$interface" = "ttyUSB0" ] then ready="true" fi done if [ -z "$ready" ] then /bin/sleep 1 && /bin/echo -ne "...device not detected, trial: $count/$maximum \r" fi done if [ -n "$ready" ] then cecho "green" "device detected, continuing now..." echo '[Dialer Defaults]' > $HOME/.wvdial.conf echo 'Modem = /dev/ttyUSB0' >> $HOME/.wvdial.conf echo 'Baud = 7200000' >> $HOME/.wvdial.conf echo 'Init1 = ATZ' >> $HOME/.wvdial.conf echo 'Init2 = ATQ0 &FE V1 X1 S0=0 &C1 &D2' >> $HOME/.wvdial.conf echo 'Init3 = AT+CGDCONT=16,"IP","live.vodafone.com";' >> $HOME/.wvdial.conf echo '[Dialer vodafone]' >> $HOME/.wvdial.conf echo 'Phone = *99***16#' >> $HOME/.wvdial.conf echo 'Username = vodafone' >> $HOME/.wvdial.conf echo 'Password = vodafone' >> $HOME/.wvdial.conf echo 'Stupid Mode = 1' >> $HOME/.wvdial.conf echo 'Debug = 1' >> $HOME/.wvdial.conf if [ -f $HOME/.wvdial.conf ] then sudo wvdial --no-syslog --config $HOME/.wvdial.conf vodafone & fi else cecho "red" "device detection failed, closing now" exit fi unset ipaddress maximum=30 count=0 while [ -z "$ipaddress" ] && [ "$count" -lt "$maximum" ] do count=$(($count+1)) cd /sys/class/net/ for interface in * do if [ "$interface" = "ppp0" ] && [ -z "$ipaddress" ] then ipaddress=$(/sbin/ifconfig $interface | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}') case "$ipaddress" in *.*.*.*) /bin/echo "received ipaddress: $ipaddress" ;; esac fi done if [ -z "$ipaddress" ] then /bin/sleep 2 && /bin/echo -e "get ipaddress trial: $count/$maximum \r" fi done if [ -n "$ipaddress" ] then cecho "green" "internet adress detected, continuing now..." bwm-ng --interfaces ppp0 --output curses --unit bytes --type sum --timeout 500 else cecho "red" "connection failed, closing now" exit fi exit #~ iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE #~ echo "1" > /proc/sys/net/ipv4/ip_forward