#!/bin/bash
# $Id: fctStopAdsl,v 1.6 2004/08/14 18:00:53 mcoolive Exp $
# Name: fctStopAdsl
# Goal: stop ADSL connexion (do not display anything)
# Author: Tux
# Params:
#	h = display help
#	f = kill pppd even if PPPOX=none
#	s = simple mode (don't use ifup & ifdown scripts => do not requiere ifcfg-ethX)

if [ 1 == 1 ] ; then
	# when called from sources folder (when uninstalling)
	USE_IFUPDOWN=0
	PPPOX="pppoa"
	DELAY_KILL_PPPD=3
else
	# when called from /usr/local/sbin
	exit 123
fi

set -- "${@//#--help/-h}"
set -- "${@//#--force/-f}"
set -- "${@//#--simple/-s}"
evalParams() {
	while getopts "hfs" opt; do
		case $opt in
			h  ) echo -e $FCTSTOP_USAGE_MSG ; exit 0 ;;
			f  ) KILLPPP=1 ;;
			s  ) SIMPLE=1 ;;
			\? ) echo -e $FCTSTOP_USAGE_MSG ; exit 1 ;;
		esac
	done
}
if [ "$PPPOX" != "none" ] ; then
	KILLPPP=1
else
	KILLPPP=0
fi
evalParams "$@"


if [ $KILLPPP == 1 ] ; then
	# kill pppd (let Nsec after killall to stop properly)
	if [ ! -z "`pidof pppd`" ] ; then
		killall -q pppd
		sleep $DELAY_KILL_PPPD
		if [ ! -z "`pidof pppd`" ] ; then
			logger "2e tape stopadsl"
			sleep 2
			killall -9 -q pppd
		fi
	fi
fi

# if the modem is still plugged, modem interface is putted down
# if the modem is unplugged, hotplug should already have done that => do nothing
INTERFACE=`eaglectrl -i 2>/dev/null`
if [ $? == 0 ] ; then
	if [ $USE_IFUPDOWN == 1 ] && [ $SIMPLE == 0 ] ; then
		ifdown $INTERFACE
	else
		ifconfig $INTERFACE down
	fi
fi

#***************************************************************************
# $Log: fctStopAdsl,v $
# Revision 1.6  2004/08/14 18:00:53  mcoolive
# - mend the parameters processing
#
# Revision 1.5  2004/07/16 21:09:19  Tux
# - simplify parameters processing
#
# Revision 1.4  2004/04/21 20:02:27  Tux
# *** empty log message ***
#
#***************************************************************************/
