#!/bin/sh

#quectel-pppd devname apn user password
echo "quectel-pppd options in effect:"
DEVNAME=/dev/ttyUSB3
APN=3gnet
USER=user
PASSWORD=passwd
if [ $# -ge 1 ]; then
	DEVNAME=$1	
	echo "devname   $DEVNAME    # (from command line)"
else
	echo "devname   $DEVNAME    # (default)"
fi
if [ $# -ge 2 ]; then
	APN=$2	
	echo "apn       $APN    # (from command line)"
else
	echo "apn       $APN    # (default)"
fi
if [ $# -ge 3 ]; then
	USER=$3	
	echo "user      $USER   # (from command line)"
else
	echo "user      $USER   # (default)"
fi
if [ $# -ge 4 ]; then
	PASSWORD=$4	
	echo "password  $PASSWORD   # (from command line)"
else
	echo "password  $PASSWORD   # (default)"
fi

CONNECT="'chat -s -v ABORT BUSY ABORT \"NO CARRIER\" ABORT \"NO DIALTONE\" ABORT ERROR ABORT \"NO ANSWER\" TIMEOUT 30 \
\"\" AT OK ATE0 OK ATI\;+CSUB\;+CSQ\;+CPIN?\;+COPS?\;+CGREG?\;\&D2 \
OK AT+CGDCONT=1,\\\"IP\\\",\\\"$APN\\\",,0,0 OK ATD*99# CONNECT'"

pppd $DEVNAME 115200 user "$USER" password "$PASSWORD" \
connect "'$CONNECT'" \
disconnect 'chat -s -v ABORT ERROR ABORT "NO DIALTONE" SAY "\nSending break to the modem\n" "" +++ "" +++ "" +++ SAY "\nGood bay\n"' \
noauth debug defaultroute noipdefault novj novjccomp noccp ipcp-accept-local ipcp-accept-remote ipcp-max-configure 30 local lock modem dump nodetach nocrtscts usepeerdns &
