head	1.3;
access;
symbols
	RELENG_2_2_8_RELEASE:1.2.6.2
	RELENG_2_2_7_RELEASE:1.2.6.2
	RELENG_2_2_6_RELEASE:1.2.6.2
	RELENG_2_2_5_RELEASE:1.2.6.2
	RELENG_2_2_2_RELEASE:1.2
	RELENG_2_2_1_RELEASE:1.2
	RELENG_2_2_0_RELEASE:1.2
	RELENG_2_1_7_RELEASE:1.2
	RELENG_2_1_6_1_RELEASE:1.2
	RELENG_2_1_6_RELEASE:1.2
	RELENG_2_2:1.2.0.6
	RELENG_2_2_BP:1.2
	RELENG_2_1_5_RELEASE:1.2
	RELENG_2_1_0_RELEASE:1.2
	RELENG_2_1_0:1.2.0.4
	RELENG_2_1_0_BP:1.2
	RELENG_2_0_5_RELEASE:1.2
	RELENG_2_0_5:1.2.0.2
	RELENG_2_0_5_BP:1.2
	RELENG_2_0_5_ALPHA:1.2
	RELEASE_2_0:1.1.1.1
	BETA_2_0:1.1.1.1
	chat:1.1.1.1;
locks; strict;
comment	@# @;


1.3
date	97.08.22.15.42.31;	author peter;	state dead;
branches;
next	1.2;

1.2
date	94.12.19.01.14.57;	author ache;	state Exp;
branches
	1.2.6.1;
next	1.1;

1.1
date	94.11.12.05.25.31;	author lars;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	94.11.12.05.25.32;	author lars;	state Exp;
branches;
next	;

1.2.6.1
date	97.09.14.20.39.30;	author jkh;	state Exp;
branches;
next	1.2.6.2;

1.2.6.2
date	97.09.14.20.40.12;	author jkh;	state dead;
branches;
next	;


desc
@@


1.3
log
@Cleanup and remove the not-too-useful examples.  The current versions
should be in share/examples if anywhere.
@
text
@#!/bin/sh
#
#	USAGE: connect-ppp <host>
#
#	Set up a PPP link to host. 
#
#	This script locks the tty so that faxd and uucp will not
#	interfere. If you are running with faxd as you "getty" then
#	faxd will remove the lock once it notices that pppd is gone.
#	This is the reason for pppd running in with the -detach flag, 
#	and you probably would run this script in the background.
#
#	I had to create the nodropdtr option to pppd in order to be
#	able to do what the script is doing here. Pathces has been
#	sent to the respective people, but I don't know if they like
#	them :-).
#
# 	Look for comments with <LOCAL> in the string. They identify 
#	things that you want to set for your system

#<LOCAL> define whatever your config file is.
CON_DB=/etc/ppp-connections

#<LOCAL> define whatever your device is.
DEVICE=cuaa0

#<LOCAL> define whatever your device speed is.
DEVICESPEED=57600

#<LOCAL> define whatever your lock directory is.
LOCKDIR=/var/spool/lock
LOCKFILE=$LOCKDIR/LCK..$DEVICE

#<LOCAL> define whatever debug level you want.
DEBUG="-d -d -d -d"

# Check that we got a name to connect to. This need not be an actuall hostname
# just the name you specified in the config file.
if [ $# -ne 1 ] ; then
	echo "Usage: $0 <host> &"
	exit 1
fi

# Get the configuration that is in effect for <name>
LINE=`grep "^$1" $CON_DB`
if [ -z "$LINE" ] ; then
	echo "Unknow host $1"
	exit 1
fi

# parse the CON_DB. The format is:
#
# <hostname>:<phone number>:<user id>:<password>:<local ip address>:\
# <remove_ip_address><netmask>:<pppd options>
#
# The last three are optional. But I would recomend specifying a netmask also
# when you specify a ip address.

IP_ADDR=""
IFS=':'
set $LINE
IFS=' '
HOST=$1
PHONE=$2
USER=$3
PASSWORD=$4
OUR_IP_ADDR=$5
THEIR_IP_ADDR=$6
NETMASK=$7
shift 7
OPTIONS=$*

if [ -f $LOCKFILE ] ; then
    echo "PPP device is locked"
    exit 1
else

    # Lock the device
    # faxd and UUCP wants 10 character lock id.
    echo "$$" | awk '{printf("%10s",$0)}' > $LOCKFILE
fi




#Do we know our local ip address? If so pppd needs a : at the end of it.
if [ ! -z "$OUR_IP_ADDR" ] ; then
	IP_ADDR=${OUR_IP_ADDR}:${THEIR_IP_ADDR}
fi

#Did we specify a netmask? If so convert to pppd format.
if [ ! -z "$NETMASK" ] ; then
	NETMASK="netmask ${NETMASK}"
fi

# Do the actual work in a subshell so that we can turn off tostop and set
# the tty speed before chat dials. The second reason for doing in like
# is that if you aren't running BIDIR, and you are running faxd, clocal
# doesn't get turned on from pppd so chat will never work if you exec 
# it from within pppd. I found that I needed to run uucp with the
# HAVE_CLOCAL_BUG flag set to 1 in order to get it to work in conjunction
# with faxd. Anyway, this setup seem to work.
(
   
    stty $DEVICESPEED -tostop hupcl 2> /dev/null

	# <LOCAL> Modify the Modem initialization strings to be whatever works for you
    if chat -v  ABORT "NO CARRIER" ABORT BUSY "" ATZ0E1 OK ATS50=255DT$PHONE \
		CONNECT "" ogin: $USER ssword: \\q$PASSWORD
    then
	# We got connected.
	/usr/libexec/pppd $DEBUG $OPTIONS -detach modem defaultroute \
		crtscts $NETMASK $DEVICE $DEVICESPEED $IP_ADDR 

    else
	echo "PPP call failed" 1>&2
	exit 1
    fi
) < /dev/$DEVICE > /dev/$DEVICE
# Get the return code from the subshell.
RC=$?

# Clear the lock. Slight window here where someone could detect that
# pppd is no longer running, remove its lock file and create its own.
# How to fix??
rm -f $LOCKFILE

#Pass on the exit code.
exit $RC
@


1.2
log
@Use proper dialout device name
@
text
@@


1.2.6.1
log
@MFC:  various bug fixes, doc updates and EOF -> -1 fixes.
@
text
@d1 129
@


1.2.6.2
log
@MFC: remove nuked files.
@
text
@@


1.1
log
@Initial revision
@
text
@d25 1
a25 1
DEVICE=tty00
@


1.1.1.1
log
@chat for ppp, from ppp 2.1.2
@
text
@@
