Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Script for cycling through several libertynet accounts trying to conect.
- #TODO: Due to a problem with the drivers?, the dongle must be reset between dial in attempts.
- #TODO: For now this reset must be done by physically pulling and re-inserting the dongle.
- #TODO: But someone smarter than me should figure out how to do this with code.
- # TODO: Find a reasonable way to monitor for a successful connection connection.
- # TODO: When the connection is successful, start IRC. This is important because if all accounts are in use
- # TODO: a sms sent to twitter could post a mesage in the #baobab channel to alert those online that someone
- # TODO: is waiting to get online. For now we just print a reminder to start IRC.
- # TODO: Set up the SMS-twitter-IRC alerting system.
- # TODO: Another posibility: The SMS sent by a baobaber waiting for use of a libertynet account would
- # TODO: initiate a disonnect of the person who has been online the longest unless they override the dissconect.
- # assign usernames to the array u and passwords to p, numberOfAccts is the number of accounts
- numberOfAccts=2
- u[0]="username0" # dummy values were put in to allow for public consumption
- p[0]="password0" # substitute with real usernames and passwords
- u[1]="username1"
- p[1]="password1"
- #This is the config that will be put into /etc/wvdial.conf with the various usernames/passwords
- wvdialconf="
- [Dialer Defaults]
- New PPPD = yes
- Modem = /dev/ttyUSB0
- Init1 = ATZ
- Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
- Dial Command = ATDT
- Phone = #777
- Modem Type = Analog Modem
- Baud = 460800
- Carrier Check = on
- Username = 26u79n
- Password = 5vn7drq
- Stupid Mode = on
- Check Def Route = on
- Abort on Busy = off
- Abort on No Dialtone = off
- Auto Reconnect = off
- ISDN = 0
- Auto DNS = on
- Idle Seconds = 0
- Dial Attempts = 1
- "
- echo "
- This script is supposed to facilitate the sharing of several libertynet
- accounts among several users. You probably should turn off other network
- connecitons before you connect to libertynet. (I always uncheck
- 'enable wireless' in the system tray.) Durring this script we will create
- new /etc/chap-secrets, /etc/pap-secrets, and /etc/wvdial.conf files. The
- originals will be backed up to /etc/chap-secrets.bak, /etc/pap-secrets.bak,
- and /etc/wvdial.conf.bak.
- Please, start IRC when you get a successful connection.
- "
- read -p "Continue? <Y/n> " prompt
- if [[ $prompt == "n" || $prompt == "N" || $prompt == "no" || $prompt == "No" || $prompt == "NO" ]]
- then
- exit
- #~ else
- #~ echo "...continuing..."
- fi
- sudo modprobe usbserial vendor=0x19d2 product=0xfffe #register the driver?
- #echo "...did the modprobe..."
- #backup chap-secrets, pap-secrets, and wvdial.conf
- #echo "Backing up chap-secrets, pap-secrets, and wvdial.conf..."
- sudo mv -f /etc/ppp/pap-secrets /etc/ppp/pap-secrets.bak
- sudo mv -f /etc/ppp/chap-secrets /etc/ppp/chap-secrets.bak
- sudo mv -f /etc/wvdial.conf /etc/wvdial.conf.bak
- #Go through each username and password.
- index=0
- while true
- do
- echo "
- If the libertynet dongle is not inserted, insert it now. If it is, please
- remove and re-insert it. The dongle will be ready to dial once the orange
- light has extuingished. It should take about 20 seconds after it is inserted.
- "
- read -p "After the orange light on the dongle has extuingished, press <enter> to continue." prompt
- echo "
- Trying to connect with username ${u[$index]} and password ${p[$index]}
- "
- #substitute the current username/password into the configuration string and write it to /tmp/wvdial.conf
- echo "$wvdialconf" | sed "s_Password = [^ ]*_Password = ${p[$index]}_" | sed "s_Username = [^ ]*_Username = ${u[$index]}_" > /tmp/wvdial.conf
- #move the tmp config file to the /etc
- sudo mv /tmp/wvdial.conf /etc/wvdial.conf
- #little daemon-like loop that checks the log file to see if we are connected, this is disabled because i couldn't figure out how to kill it gracefully
- #~ while true
- #~ do
- #~ sleep 5
- #~ if grep -q "DNS address" /tmp/libertynet.log #the DNS address is sent to stderr when the connection is successful
- #~ then
- #~ echo "...connected..."
- #~ echo "Be a team player, start IRC and listen for requests to give up your connection from offline baobabers."
- #~ break
- #~ else
- #~ echo "...not connected..."
- #~ fi
- #~ done&
- #the dial/re-dial routine
- while true
- do
- >/tmp/libertynet.log #initialize the log for each dial attempt
- sudo wvdial 3>&1 1>&2 2>&3 | tee /tmp/libertynet.log #dial the modem, send stderr to log file and to screen (tee only works on stdout, so we swap stdout and stderr)
- if grep -q "Device or resource busy" /tmp/libertynet.log #this happens if the modem is not yet ready
- then
- echo
- echo "... looks like the modem was not available, is it already in use by another application?..."
- sleep 3
- echo "...re-dialing..."
- echo
- elif grep -q "No such file" /tmp/libertynet.log #this also happens if the modem is not yet ready
- then
- echo
- echo "... wvdial can not see the modem, is the dongle plugged in? ... "
- sleep 3
- echo "...re-dialing..."
- echo
- elif grep -q "NO CARRIER" /tmp/libertynet.log #this happens if the modem fails to find a cell tower
- then
- echo
- echo "...Modem did not succesfully connect to a cell tower, are you getting cell reception? "
- echo "...re-dialing..."
- echo
- elif grep -q "Modem not responding." /tmp/libertynet.log #this happens if the modem is not re-inserted
- then
- echo
- echo "...Looks like the dongle was not reset...."
- echo "...Don't forget to remove and re-insert the dongle when prompted..."
- echo
- break
- else
- echo
- echo "...Looks like that account is already in use...."
- echo
- break
- fi
- done
- #~ if [ $! ] ; then kill $!; fi # Kill the background daemon-like loop, this seems to give some unwanted output
- # but at least the background process does stop. Disabled, because it was messy.
- let "index += 1"
- if [ $index == $numberOfAccts ] #when we've tried all acounts, give the option to quit or start over
- then
- echo
- echo "We have tried all the libertynet accounts. Do you want to start over with the first account or quit?"
- read -p "<S>tart over or <q>uit?" prompt
- if [[ $prompt == "q" || $prompt == "Q" || $prompt == "quit" || $prompt == "Quit" || $prompt == "QUIT" ]]
- then
- exit 0
- else
- let "index=0"
- echo "...starting over with the first username/password..."
- fi
- fi
- done
Add Comment
Please, Sign In to add comment