#!/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 (cycle to next ISP in ${basePPP}/cycle.$1 if exists)
#
. /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 [ -r ${basePPP}/cycle.$DEVICE ]
then	if [ -z "$ISP" ]
	then	line=1
	else	line=`grep -n ^$ISP ${basePPP}/cycle.$DEVICE | cut -f1 -d:`
		line=`expr "$line" + 1`
		lns=`wc -l ${basePPP}/cycle.$DEVICE | cut -b1-7`
		if [ $line -gt $lns  ]
		then	line=1
		else	len=`expr length \`getln $line ${basePPP}/cycle.$DEVICE\``
			if [ $len -lt 1 ]; then line=1; fi
			unset len
		fi
		unset lns
	fi
	ISP=`getln $line ${basePPP}/cycle.$DEVICE`
fi

if [ -n "$ISP" ]
then	${basePPP}/ppp-on $ISP $DEVICE
else	${basePPP}/ppp-on - $DEVICE
fi
