#!/bin/bash
######################################################################
#
# This script is part of the PPP System designed and used by
# Preston A. Elder of Shadow Realm.  If you have any problems
# with this system please email prez@antisocial.com.
#
# This system is publically distributable via. the GNU license.
#
######################################################################
#
# Redial on PPP (check max retries)
#
. /etc/ppp-settings

if [ -f ${basePID}/all.off ]; then exit 1; fi

if [ -z "$1" -o "$1" = "-" ]
then	ISP=""
else	ISP=$1
fi
if [ -z "$2" -o "$2" = "-" ]
then	DEVICE="${baseTTY}"
else	DEVICE=$2
fi

if [ -n "$MAXDIAL" ]
then	if [ -r ${basePID}/$DEVICE.attempt ]
	then	i=`cat ${basePID}/$DEVICE.attempt`
		i=`expr $i + 1`
	else	i=1
	fi

	if [ $i -lt $MAXDIAL ]
	then	echo $i >${basePID}/$DEVICE.attempt
		if [ -n "$ISP" ]
		then	${basePPP}/ppp-on $ISP $DEVICE
		else	${basePPP}/ppp-on - $DEVICE
		fi
	else	rm -f ${basePID}/$DEVICE.attempt
	fi
else	if [ -r ${basePID}/$DEVICE.attempt ]
	then	rm -f ${basePID}/$DEVICE.attempt
	fi
	if [ -n "$ISP" ]
	then	${basePPP}/ppp-on $ISP $DEVICE
	else	${basePPP}/ppp-on - $DEVICE
	fi	
fi
