#!/bin/sh

# $Id: poff,v 1.3 1998/02/26 06:42:45 phil Exp $
# Written by Phil Hands <phil@hands.com>, distributed under the GNU GPL

case $1 in
 "")   SIG=TERM DONE=stopped ;;
 "-r") SIG=HUP  DONE=signalled ;;
 "-d") SIG=USR1 DONE=signalled ;;
 "-c") SIG=USR2 DONE=signalled ;;
 *) cat <<!EOF!
usage: $0 [options]

options:
  -r        cause pppd to drop the line and redial
  -d        toggles the state of pppd's debug option
  -c        cause pppd to renegotiate compression
!EOF!
    exit 1
    ;;
esac

# Lets see how many pppds are running....
set -- `cat /var/run/ppp*.pid 2>/dev/null`

case $# in
  0) # pppd only creates a pid file once ppp is up, so let's try killing pppd
     # on the assumption that we've not got that far yet.
     killall -${SIG} pppd
     exit 0
     ;;
  1) # If only one was running then it can be killed (apparently killall
     # caused problems for some, so lets try killing the pid from the file)
     kill -${SIG} $1
     exit 0
     ;;
  *) # More than one! Aieehh.. Dont know which one to kill.
     echo "More than one pppd running. None ${DONE}"
     exit 1
     ;;
esac
