updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / ppp-rdr / poff
blob8b4dffc59e1357521739c43b16b5003d5f8e242a
1 #!/bin/sh
3 # Written by John Hasler <john@dhh.gt.org> and based on work
4 # by Phil Hands <phil@hands.com>. Distributed under the GNU GPL
6 if [ -x /usr/bin/kill ]; then
7 KILL="/usr/bin/kill"
8 else
9 KILL="/bin/kill"
11 SIG=TERM
12 DONE="stopped"
13 MODE=""
15 usage ()
17 cat <<!EOF!
18 usage: $0 [option] [provider]
19 options:
20 -r Cause pppd to drop the line and redial.
21 -d Toggle the state of pppd's debug option.
22 -c Cause pppd to renegotiate compression.
23 -a Stop all pppd's. 'provider' will be ignored.
24 -h Print this help summary and exit.
25 -v Print version and exit.
26 none Stop pppd.
28 Options may not be combined.
30 If 'provider' is omitted pppd will be stopped or signalled if and only if
31 there is exactly one running unless the '-a' option was given. If
32 'provider' is supplied the pppd controlling the connection to that
33 provider will be stopped or signalled.
34 !EOF!
37 # Get option. If there are none replace the "?" that getopts puts in
38 # FLAG on error with "null".
39 getopts rdcavh FLAG
40 if [ "$?" -ne 0 ]; then
41 FLAG="null"
44 # Check for additional options. Should be none.
45 getopts :rdcavh DUMMY
46 if [ "$?" -eq 0 ]; then
47 echo "$0: Illegal option -- ${OPTARG}."
48 exit 1
51 case $FLAG in
52 "r") SIG=HUP; DONE=signalled; shift ;;
53 "d") SIG=USR1; DONE=signalled; shift ;;
54 "c") SIG=USR2; DONE=signalled; shift ;;
55 "a") MODE="all"; shift ;;
56 "v") echo "$0$Revision: 1.1 $_TrickToPrint_RCS_Revision"; exit 0 ;;
57 "h") usage; exit 0 ;;
58 "?") exit 1;
59 esac
61 # Get the PIDs of all the pppds running. Could also get these from
62 # /var/run, but pppd doesn't create .pid files until ppp is up.
63 PIDS=`pidof pppd`
65 # poff is pointless if pppd isn't running.
66 if test -z "$PIDS"; then
67 echo "$0: No pppd is running. None ${DONE}."
68 exit 1
71 # Find out how many pppd's are running.
72 N=`echo "$PIDS" | wc -w`
74 # If there are no arguments we can't do anything if there is more than one
75 # pppd running.
76 if test "$#" -eq 0 -a "$N" -gt 1 -a $FLAG != "a" ; then
77 echo "$0: More than one pppd running and no "-a" option and
78 no arguments supplied. Nothing ${DONE}."
79 exit 1
82 # If either there are no arguments or '-a' was specified kill all the
83 # pppd's.
84 if test "$#" -eq 0 -o "$MODE" = "all" ; then
85 $KILL -$SIG $PIDS || {
86 echo "$0: $KILL failed. None ${DONE}."
87 exit 1
89 exit 0
92 # There is an argument, so kill the pppd started on that provider.
93 PID=`ps axw | grep "[ /]pppd call $1 *\$" | awk '{print $1}'`
94 if test -n "$PID" ; then
95 $KILL -$SIG $PID || {
96 echo "$0: $KILL failed. None ${DONE}."
97 exit 1
99 else
100 echo "$0: I could not find a pppd process for provider '$1'. None ${DONE}."
101 exit 1
103 exit 0