#!/bin/sh
#	Program:	pppon	1995-05-24
#			jmf
#	Description:	run this quick shell prog once a PPP link is up.
#
# Initialize variables.
IP=
DATE=
VER=0.1

################################################################################
#
# First, make sure that the link *is* up -- check the PID file.
# if the PID file is absent, exit with a code of 1.
#
if [ ! -e /var/run/ppp0.pid ]; then
	echo "
		* * * 	Unable to find PPP0 PID file * * *
	     "
	exit 1
fi

###############################################################################
#
# Now, get the dynamically allocated IP address from ifconfig and update the
# /etc/hosts file accordingly.
#
clear
ifconfig | grep P-t-P - | cut -b 21-32 > /tmp/IPaddr	# get IP address
IP=`cat /tmp/IPaddr` ; rm -f /tmp/IPaddr		# set IP = new address
DATE=`date`						# set DATE = current time

echo "#
# This file automatically generated by pppon and should indicate the
# correct dynamically allocated IP address below.
#
# This file generated on $DATE
#
127.0.0.1	localhost
$IP	MyMachine.vanderbilt.edu		MyMachine" > /etc/hosts

###############################################################################
#
# Indicate status of connection and offer to check the mail using popclient.
#

echo -n "
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~


			PPP-ON Startup Script
			      ver $VER
			    John M. Fisk
			


	STATUS OF CONNECTION:

	The ppp0 interface is connected.
	Our current IP address is............$IP
	Check for new mail [y,n]?............"

read YESNO
if [ "$YESNO" = "y" ]; then
	echo "        Status...............................Checking mail."
	popclient -3 -v -u myname -p mypassword -o /root/mail/mail-in ctrvax.vanderbilt.edu >& /var/adm/popclient.log
		if [ "$?" = "0" ]; then
		echo "        Status...............................There is new mail."
		else
		echo "        Status...............................No new mail."
		fi
else
	echo "        Status...............................No mail check."
fi

if [ -e "/var/run/ppp0.pid" ]; then
	echo "        Status...............................Running PPP-UP!

~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ 
"
fi

exec /usr/lib/ppp/popcheck &
exec /usr/lib/ppp/ppp-up &
exit
