#!/bin/sh
# <BEGIN COPYRIGHT>
# This file is part of the "Bad Penguin" GNU/Linux distribution
# Copyright (C) 1997-98-99 by Antonio GALLO
# Home Page at ......: http://www.badpenguin.org  http://www.linux.it/~agx/
# e-mail contact ....: mailto:agx@linux.it      mailto:agx@geocities.com
# This program is distributed under the GNU General Public License
# You are not allowed to remove the copyright notice
# <END COPYRIGHT>

# <ORIGINAL HEADER: from ppp-off on Slackware 3.5>
# Taken from Slackware 3.5 (there was no copyright info on this header)
# </ORIGINAL HEADER>

# BAD PENGUIN" - Internet Connection Utility
# 1999-02-23, Ver. 1.0.0 by agx@linux.it 
# 2000-01-18, Ver. 1.0.1 by Stefano Falsetto: exit code on errors


# First stop this monster
echoc GREEN "Hanging up ...."
#echo "+++" > /dev/modem
#echo "at" > /dev/modem
#echo "at H0" > /dev/modem
#sleep 2
chat -f /etc/ppp/hangup.chat > /dev/modem

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

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

PID=`pidof pppd`
if [ ! "$PID" = "" ]; then
  killall -INT pppd 2>/dev/null
fi

rm -f /var/run/$DEVICE.pid
#<suggested by md@linux.it> rm -f /var/lock/LCK*

# Hang up
#echoc YELLOW "Hanging up ...."
#chat -f /etc/ppp/hangup.chat > /dev/modem
ps ax | grep -q chat
if [ $? = 0 ]; then
  echoc RED "La connessione e' ancora attiva !"
  exit 1
fi
ps ax | grep -q ppp
if [ $? = 0 ]; then
  echoc RED "La connessione e' ancora attiva !"
  exit 2  
fi

# Remove chat temp file
rm -f /root/*.connect
echo
