#!/bin/bash sleep 5 if [ "$1" != "megafon" ] && [ "$1" != "mts" ] && [ "$1" != "beeline" ] && [ "$1" != "irancell" ]; then echo "Usage: $0 megafon|mts|beeline|irancell" exit 1 fi killall pppd > /dev/null PROV=$1 GPRS="ttyACM0" SPEED="115200" DGW=`route -n | grep UG | head -n 1 | awk '{ print $2 }' | sed -r "s/([0-9]*)\.([0-9]*)\.([0-9]*).*/\1\.\2\.\3\.1/"` IP_UP="#!/bin/bash\nGW=\`echo \$5 | sed -r \"s/([0-9]*)\.([0-9]*)\.([0-9]*).*/\x5C\x31\.\x5C\x32\.\x5C\x33\.1/\"\`\n/sbin/route add default gw \$GW" IP_DOWN="#!/bin/bash\n/sbin/route add default gw $DGW" echo -e $IP_UP > /etc/ppp/ip-up chmod 0700 /etc/ppp/ip-up echo -e $IP_DOWN > /etc/ppp/ip-down chmod 0700 /etc/ppp/ip-down OPTIONS="/dev/$GPRS connect '/usr/sbin/chat -v -f /etc/ppp/chat/chat-gprs' local $SPEED unit 0 defaultroute noipdefault ipcp-accept-local ipcp-accept-remote lcp-echo-interval 60 lcp-echo-failure 5 passive modem mru 1500 " if [ "$PROV" == "megafon" ]; then USER="gdata" GATE="internet" TAIL="" fi if [ "$PROV" == "mts" ]; then USER="mts" GATE="internet.mts.ru" TAIL="CONNECT" fi if [ "$PROV" == "beeline" ]; then USER="beeline" GATE="internet.beeline.ru" TAIL="CONNECT" fi if [ "$PROV" == "irancell" ]; then USER="irancell" GATE="mtn.irancell" TAIL="CONNECT" fi PAPCHAP="gdata\t\t*\t\tgdata\nmts\t\t*\t\tmts\nbeeline\t\t*\t\tbeeline" PEERS="/dev/$GPRS user $USER $SPEED defaultroute usepeerdns nodetach persist noipdefault lock connect '/usr/sbin/chat -v -f /etc/ppp/chat/chat-gprs' novjccomp nopcomp noaccomp noipdefault nodeflate novj nobsdcomp debug " CHAT_GPRS=" TIMEOUT 10 ECHO ON ABORT '\nBUSY\r' ABORT '\nERROR\r' ABORT '\nNO ANSWER\r' ABORT '\nNO DIALTONE\r' ABORT '\nRINGING\r\n\r\nRINGING\r' \"\" '\rAT' TIMEOUT 20 OK 'ATE1S7=45' OK 'AT+CGDCONT=1,\"IP\",\"$GATE\"' OK 'ATD*99***1#' TIMEOUT 60 ABORT '\nERROR\r' $TAIL " if [ "`ps -eo pid,comm | grep ppp`" != "" ]; then killall pppd > /dev/null 2>&1 exit fi LOCK=`ls /var/lock | grep ACM ` if [ "$LOCK" != "" ]; then rm -f /var/lock/$LOCK > /dev/null 2>&1 fi MODULES=( $(ls /lib/modules/`uname -r`/kernel/drivers/net | grep "ppp")) if [ ${#MODULES[@]} -gt 0 ];then for MODULE in `seq 0 ${#MODULES[@]}` ; do if [ "${MODULES[$MODULE]}" != "" ]; then PPP=`echo ${MODULES[$MODULE]} | sed -r "s/\.ko//"` modprobe $PPP >/dev/null 2>&1 if [ $? == 0 ]; then RESULT="Ok" else RESULT="Failed" fi echo "Probing $PPP $RESULT" fi done fi if [ -e /etc/ppp/gprs ]; then rm -f /etc/ppp/gprs fi echo -e $PAPCHAP > /etc/ppp/pap-secrets if [ $? != 0 ]; then echo Error 1 exit fi chmod 0600 /etc/ppp/pap-secrets echo -e $PAPCHAP > /etc/ppp/chap-secrets if [ $? != 0 ]; then echo Error 2 exit fi chmod 0600 /etc/ppp/chap-secrets echo $OPTIONS > /etc/ppp/options if [ $? != 0 ]; then echo Error 3 exit fi echo $CHAT_GPRS > /etc/ppp/chat/chat-gprs if [ $? != 0 ]; then echo Error 4 exit fi chmod 0666 /etc/ppp/options if [ -e /etc/ppp/peers/gprs ]; then rm -f /etc/ppp/peers/gprs fi echo $PEERS > /etc/ppp/peers/gprs if [ $? != 0 ]; then echo Error 5 exit fi chmod 0666 /etc/ppp/peers/gprs if [ "`ls /dev | grep $GPRS`" != "" ]; then echo "Device /dev/$GPRS present" else if [ ! -e /dev/$GPRS ]; then mknod /dev/$GPRS c 166 0 if [ $? != 0 ]; then echo Error 6 exit fi fi if [ ! -e /dev/usb ]; then mkdir /dev/usb if [ $? != 0 ]; then echo Error 7 exit fi chmod 0666 /dev/usb fi ln -s /dev/$GPRS /dev/usb/$GPRS if [ $? != 0 ]; then echo Error 8 exit fi fi chmod 0666 /dev/$GPRS echo "Calling to $PROV..." if [ "$DGW" != "" ]; then route del default gw $DGW fi pppd call gprs