#!/bin/sh
# Generated automatically from adsl-stop.in by configure.
#***********************************************************************
#
# adsl-stop
#
# Shell script to bring down an ADSL connection
#
# Copyright (C) 2000 Roaring Penguin Software Inc.
#
# $Id: adsl-stop.in,v 1.2 2000/03/21 03:52:12 dfs Exp $
#
# This file may be distributed under the terms of the GNU General
# Public License.
#
# Usage: adsl-stop [config_file]
# If config_file is omitted, defaults to /etc/ppp/pppoe.conf
#
#***********************************************************************

CONFIG="$1"
if [ "$CONFIG" = "" ] ; then
    CONFIG=/etc/ppp/pppoe.conf
fi

if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
    echo "$0: Cannot read configuration file '$CONFIG'" >& 2
    exit 1
fi

. $CONFIG

# Warn if dial-on-demand used
if [ "$DEMAND" != "" -a "$DEMAND" != "no" ] ; then
    echo "$0: Warning: Link is configured for activate-on-demand; this"
    echo "script will not reliably shut down demand-activated links."
fi

# Check for pidfile
if [ -r "$PIDFILE" ] ; then
    PID=`cat $PIDFILE`

    # Check if still running
    kill -0 $PID > /dev/null 2>&1
    if [ $? != 0 ] ; then
	echo "$0: The ADSL (PID $PID) appears to have died" >& 2
	exit 1
    fi

    # Create the terminate file
    echo $$ > "$TERMINATEFILE"

    # Kill the PPPoE daemon
    msg=`kill $PID 2>&1`
    if [ $? != 0 ] ; then
	echo "$0: Problem killing PID $PID: $msg" >& 2
	exit 1
    fi
else
    echo "$0: No ADSL connection appears to be running" >&2
    exit 1
fi
