#!/bin/sh

#
#       ppp-on
#
#       Set up a PPP link
#

PPP_DEVICE=${PPP_DEVICE:-modem}
#PPP_PHONE=${PPP_PHONE:-7251337}
PPP_PHONE=${PPP_PHONE:-3138300}

LOCKDIR=/var/lock

echo -n 'PPP username: '
read USER
echo -n 'PPP password: '
stty -echo
read PASSWORD
stty echo
echo

chown root /dev/${PPP_DEVICE} 2>/dev/null
chmod 666 /dev/${PPP_DEVICE} 2>/dev/null
(
    #stty 0	# force hangup
    setserial /dev/${PPP_DEVICE} spd_hi
    stty 38400 -tostop -clocal hupcl

    if /usr/sbin/chat -v -t 900 ABORT "NO CARRIER" ABORT "BUSY" \
	""			"ATZ0" \
	"OK"			"ATM1L0E1Q0V1S0=0&B1&D2&R2&C1&S1&H1&K1" \
	"OK"			"ATDT${PPP_PHONE}" \
	"CONNECT"		"\\r" \
	"name:--name:"		"${USER}" \
	"word:"			"\\q${PASSWORD}" \
	"edu>"			"ppp default" \
	"system." 		"\\r" 
    then
        /usr/sbin/pppd /dev/${PPP_DEVICE}
        status=$?
        if [ $status -ne 0 ];then
                echo 'PPP: initialization failed.' 1>&2
                rm -f $LOCKDIR/LCK..${PPP_DEVICE}
        fi
        exit $status
    else
        echo 'PPP: failed to connect.' 1>&2
        exit 1
    fi
) < /dev/${PPP_DEVICE} > /dev/${PPP_DEVICE}
