#!/bin/sh
######################################################################
#
# Determine the device to be terminated.
#
if [ "$1" = "" ]; then
	DEVICE=ppp0
else
	DEVICE=$1
fi

# return .sav 
cd /etc
if (test -f resolv.conf.sav); then
    mv resolv.conf.sav resolv.conf
elif (test -f resolv.conf.save); then
    mv resolv.conf.save resolv.conf
fi
cd /etc/ppp
if (test -f pap-secrets.sav); then
    mv pap-secrets.sav pap-secrets
fi
if (test -f chap-secrets.sav); then
    mv chap-secrets.sav chap-secrets
fi

# 01.08.10 Otake Kill chat
if [ -r /var/run/chat.pid ]; then
        kill -INT `cat /var/run/chat.pid`
fi

######################################################################
#
# If the ppp0 pid file is present then the program is running. Stop it.
if [ -r /var/run/$DEVICE.pid ]; then
        kill -INT `cat /var/run/$DEVICE.pid`

#
# If the kill did not work then there is no process running for this
# pid. It may also mean that the lock file will be left. You may wish
# to delete the lock file at the same time.
        if [ ! "$?" = "0" ]; then
                rm -f /var/run/$DEVICE.pid
#                echo "ERROR: Removed stale pid file"
                exit 1
        fi
#
# Success. Let pppd clean up its own junk.
#        echo "PPP link to $DEVICE terminated."
        exit 0
fi
#
# The ppp process is not running for ppp0
#echo "ERROR: PPP link is not active on $DEVICE"
exit 1
