#!/bin/sh

# ---------------------------------------------------------------------------
# Script di Collegamento al Cisco del DEI - Universita` di Padova
#
# autore Giuseppe Zanetti (beppe@iperv.it)
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
#                            CONFIGURAZIONI
#
# le configurazioni devono essere inserite nel file $HOME/.deippprc nel
# seguente modo:
#
# LOGIN=[il proprio nome di login]
# PASSWORD=[la propria password]
# DEFAULTLINE=[ultima cifra del numero telefonico di default]
#
# esempio:   LOGIN=beppe
#            PASSWORD=nonteladico
#            DEFAULTLINE=4
#
# ricordatevi di proteggere il file in lettura !
# ---------------------------------------------------------------------------




# ---------------------------------------------------------------------------
#                      NON TOCCATE LE RIGHE SEGUENTI
# ---------------------------------------------------------------------------


CONFILE=$HOME/.deippprc

LOGIN=`grep ^LOGIN= $CONFILE|cut -f2 -d=`
PASSWORD=`grep ^PASSWORD= $CONFILE|cut -f2 -d=`
DEFAULTLINE=`grep ^DEFAULTLINE= $CONFILE|cut -f2 -d=`

clear
echo "---------------------------------------------------------------------------"
echo "      Script di Collegamento al Cisco del DEI - Universita\` di Padova"
echo
echo "                 autore Giuseppe Zanetti (beppe@iperv.it)"
echo "---------------------------------------------------------------------------"

echo "                   ------------- DEI PPP SETUP ------------"
echo "                   CONFILE=$CONFILE"
echo "                   LOGIN=$LOGIN"
echo "                   PASSWORD=$PASSWORD"
echo "                   DEFAULTLINE=$DEFAULTLINE"
echo "                   ----------------------------------------"
echo

SPEED=""
SPEOK=""

N=$1

if [ "$1" = "" ]
then
	N=$DEFAULTLINE
fi

echo Calling DEI Linea $N ...

if [ "$1" = 2400 ]
then
	SPEED="AT&N3"
	SPEOK="OK"
fi

# check if the link is running

# the special file that rappresents the serial port

CUA=/dev/modem

# uncomment this if you use a modem; comment if you use a 3 wires cable

MODEM=modem
CRTSCTS=crtscts

# uncomment the ADDR that you need
# format is my_address:yours_address
# or noipdefaults if it is assigned
# from the server

#ADDR=150.178.101.2:150.178.101.1
#ADDR=193.207.29.72:
#ADDR=:150.178.101.1
ADDR=noipdefault

# the debug level (bethween 0 and 5)

DEBUGLEVEL=0

# reset the modem port permissions

chown root $CUA
chmod 666 $CUA

# start the link

(
	stty 0
    echo -n "setting tty ... " 1>&2
    stty 38400 -tostop

    echo -n "connecting ... " 1>&2

    if /usr/lib/ppp/chat -v "" AT OK ATZ OK $SPEED $SPEOK atd827776$N CONNECT "\r\r" ername:-"\r"-ername: "\r\r" sername: $LOGIN ssword: $PASSWORD \> ppp
    then
		/usr/lib/ppp/pppd $MODEM $CRTSCTS asyncmap 0 debug kdebug $DEBUGLEVEL mru 296 mtu 296 defaultroute $CUA $ADDR &

		if [ ! $? = 0 ]
		then
			echo "pppd error (see /var/adm/messages)" 1>&2
		fi

		tail -f /var/adm/messages 1>&2
    else
		echo "chat failed" 1>&2
		exit 1
    fi
) < $CUA > $CUA

