b667fba
#! /bin/bash
b667fba
# Generated automatically from pppoe-stop.in by configure.
b667fba
#***********************************************************************
b667fba
#
b667fba
# pppoe-stop
b667fba
#
b667fba
# Shell script to bring down an PPPoE connection
b667fba
#
b667fba
# Copyright (C) 2000 Roaring Penguin Software Inc.
b667fba
#
b667fba
# $Id$
b667fba
#
b667fba
# This file may be distributed under the terms of the GNU General
b667fba
# Public License.
b667fba
#
b667fba
# LIC: GPL
b667fba
#
b667fba
# Usage: pppoe-stop [config_file]
b667fba
# If config_file is omitted, defaults to /etc/ppp/pppoe.conf
b667fba
#
b667fba
#***********************************************************************
b667fba
b667fba
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
b667fba
1c21fbb
IP=/usr/sbin/ip
b667fba
LS=/bin/ls
b667fba
NETWORKDIR=/etc/sysconfig/network-scripts
b667fba
b667fba
# Set to "C" locale so we can parse messages from commands
b667fba
LANG=C
b667fba
export LANG
b667fba
b667fba
get_device() {
b667fba
    if [ ! -d $NETWORKDIR ] ; then
b667fba
        $ECHO "** $NETWORKDIR not found"
b667fba
        $ECHO "** Quitting"
b667fba
        exit 1
b667fba
    fi
b667fba
b667fba
    cd $NETWORKDIR
b667fba
    interfaces=$($LS ifcfg-ppp* 2>/dev/null | egrep -v '(~|\.bak)$' | \
b667fba
                 egrep -v '(rpmsave|rpmorig|rpmnew)' | sed 's/^ifcfg-//g')
b667fba
b667fba
    for i in $interfaces ; do
b667fba
        test -f ifcfg-$i && . ifcfg-$i 2>/dev/null
b667fba
        if [ "$TYPE" = "xDSL" ] ; then
b667fba
            CONFIG=$NETWORKDIR/ifcfg-$i
b667fba
            break
b667fba
        fi
b667fba
    done
b667fba
}
b667fba
b667fba
ME="`basename $0`"
b667fba
LOGGER="/usr/bin/logger -t $ME"
b667fba
CONFIG="$1"
b667fba
if [ -z "$CONFIG" ] ; then
b667fba
    get_device
b667fba
    [ -z "$CONFIG" ] && CONFIG=/etc/ppp/pppoe.conf
b667fba
fi
b667fba
b667fba
if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
b667fba
    [ "$DEBUG" = "1" ] && echo "$ME: Cannot read configuration file '$CONFIG'" >& 2
b667fba
    exit 1
b667fba
fi
b667fba
b667fba
export CONFIG
b667fba
. $CONFIG
b667fba
b667fba
PPPOE_PIDFILE="$PIDFILE.pppoe"
b667fba
PPPD_PIDFILE="$PIDFILE.pppd"
b667fba
STARTPID="$PIDFILE.start"
b667fba
b667fba
# Backward config file compatibility
b667fba
if test "$DEMAND" = "" ; then
b667fba
	DEMAND=no
b667fba
fi
b667fba
b667fba
# Ignore SIGTERM
b667fba
trap "" 15
b667fba
b667fba
# Check for pidfile
b667fba
if [ -r "$PIDFILE" ] ; then
b667fba
    PID=`cat $PIDFILE`
b667fba
b667fba
    # Check if still running
b667fba
    kill -0 $PID > /dev/null 2>&1
b667fba
    if [ $? != 0 ] ; then
b667fba
        [ "$DEBUG" = "1" ] && echo "$ME: The pppoe-connect script (PID $PID) appears to have died" >& 2
b667fba
    fi
b667fba
b667fba
    # Kill pppd, which should in turn kill pppoe
b667fba
    if [ -r "$PPPD_PIDFILE" ] ; then
b667fba
        PPPD_PID=`cat "$PPPD_PIDFILE"`
b667fba
        $LOGGER -p daemon.notice "Killing pppd"
b667fba
        [ "$DEBUG" = "1" ] && echo "Killing pppd ($PPPD_PID)"
b667fba
        kill $PPPD_PID > /dev/null 2>&1
b667fba
    fi
b667fba
b667fba
    # Kill pppoe-start
b667fba
    PIDS=`cat $STARTPID`
b667fba
    kill -0 $PIDS > /dev/null 2>&1
b667fba
    if [ $? = 0 ] ; then
b667fba
        $LOGGER -p daemon.notice "Killing pppoe-connect"
b667fba
        kill $PIDS > /dev/null 2>&1
b667fba
    fi
b667fba
b667fba
    # Kill pppoe-connect
b667fba
    $LOGGER -p daemon.notice "Killing pppoe-connect"
b667fba
    [ "$DEBUG" = "1" ] && echo "Killing pppoe-connect ($PID)"
b667fba
    kill $PID > /dev/null 2>&1
b667fba
b667fba
    # Kill pppd again, in case it's still hanging around
b667fba
    if [ -r "$PPPD_PIDFILE" ] ; then
b667fba
       PPPD_PID=`cat "$PPPD_PIDFILE"`
b667fba
       kill -9 $PPPD_PID > /dev/null 2>&1 || exit 1
b667fba
    fi
b667fba
b667fba
    # Kill br2684ctl if necessary
b667fba
    if [ -n "$BR2684DEV" -a -r /var/run/nas$BR2684DEV.pid ]; then
b667fba
	PIDS=`cat /var/run/nas$BR2684DEV.pid`
b667fba
	kill -0 $PIDS > /dev/null 2>&1
b667fba
	if [ $? = 0 ]; then
b667fba
	    $LOGGER -p daemon.notice "Killing br2684ctl for nas$BR2684DEV"
b667fba
	    kill $PIDS > /dev/null 2>&1
b667fba
	fi
b667fba
	rm -f /var/run/nas$BR2684DEV.pid
b667fba
    fi
b667fba
b667fba
    rm -f "$PIDFILE" "$PPPD_PIDFILE" "$PPPOE_PIDFILE" "$STARTPID"
b667fba
else
b667fba
    [ "$DEBUG" = "1" ] && echo "$ME: No PPPoE connection appears to be running" >&2
b667fba
    exit 1
b667fba
fi
b667fba
b667fba
# add old default gw back
04bb6d2
if [ -s /etc/default-routes ] ; then
04bb6d2
    while read spec; do
1c21fbb
        $IP route add $spec
04bb6d2
    done < /etc/default-routes
04bb6d2
    rm -f /etc/default-routes
b667fba
fi
b667fba
b667fba
exit 0