#!/bin/sh
#
# Script to initiate a ppp connection. This is the first part of the
# pair of scripts. This is not a secure pair of scripts as the codes
# are visible with the 'ps' command.  However, it is simple.
#
# These are the parameters. Change as needed.
if [ $# -ne 3 ]; then
    echo "---------err1---------"
	echo "should have three params: 1:telephone 2:account 3:password "
exit 1
fi

TELEPHONE=$1	# The telephone number for the connection
ACCOUNT=$2		# The account name for logon (as in 'George Burns')
PASSWORD=$3		# The password for this account (and 'Gracie Allen')
#
# Export them so that they will be available at 'ppp-on-dialer' time.
export TELEPHONE ACCOUNT PASSWORD
# 
#echo $TELEPHONE
#echo $ACCOUNT
#echo $PASSWORD




/etc/ppp/pppd debug lock nocrtscts /dev/ttyAS1 115200 \
kdebug 4 0.0.0.0:0.0.0.0 noipdefault netmask 255.255.255.0 defaultroute connect /etc/ppp/ppp-dial-modem

con_cnt=0

while [ $con_cnt -lt 12 ]
do
	dial_ok=`ifconfig|grep -w "ppp0"|awk '{print $1}'`
#	echo "---dialing $TELEPHONE---"
	if [ -z $dial_ok ]
	then
		let "con_cnt+=1"
		sleep 10
	else
#		echo "modem dial success!"
		break
	fi
done

if [ $con_cnt -ge 6 ]
then
#	echo "modem dial failed"
	exit 1
fi
