miniupnpd 1.9 (20160113)
[tomato.git] / release / src / router / rp-pppoe / scripts / pppoe-start.in
blob7e158048a9f85390845a8e7ab489493bf7a27420
1 #!/bin/sh
2 # @configure_input@
3 #***********************************************************************
5 # pppoe-start
7 # Shell script to bring up a PPPoE connection
9 # Copyright (C) 2000 Roaring Penguin Software Inc.
11 # $Id$
13 # This file may be distributed under the terms of the GNU General
14 # Public License.
16 # LIC: GPL
18 # Usage: pppoe-start [config_file]
19 # pppoe-start interface user [config_file]
20 # Second form overrides USER and ETH from config file.
21 # If config_file is omitted, defaults to /etc/ppp/pppoe.conf
23 #***********************************************************************
25 # From AUTOCONF
26 prefix=@prefix@
27 exec_prefix=@exec_prefix@
29 # Paths to programs
30 CONNECT=@sbindir@/pppoe-connect
31 ECHO=@ECHO@
32 IFCONFIG=/sbin/ifconfig
34 # Set to "C" locale so we can parse messages from commands
35 LANG=C
36 export LANG
38 # Defaults
39 CONFIG=/etc/ppp/pppoe.conf
40 USER=""
41 ETH=""
42 ME=`basename $0`
43 # Must be root
44 if [ "`@ID@ -u`" != 0 ] ; then
45 $ECHO "$ME: You must be root to run this script" >& 2
46 exit 1
49 # Debugging
50 if [ "$DEBUG" = "1" ] ; then
51 $ECHO "*** Running in debug mode... please be patient..."
52 DEBUG=/tmp/pppoe-debug-$$
53 export DEBUG
54 mkdir $DEBUG
55 if [ "$?" != 0 ] ; then
56 $ECHO "Could not create directory $DEBUG... exiting"
57 exit 1
59 DEBUG=$DEBUG/pppoe-debug.txt
61 # Initial debug output
62 $ECHO "---------------------------------------------" > $DEBUG
63 $ECHO "* The following section contains information about your system" >> $DEBUG
64 date >> $DEBUG
65 $ECHO "Output of uname -a" >> $DEBUG
66 uname -a >> $DEBUG
67 $ECHO "---------------------------------------------" >> $DEBUG
68 $ECHO "* The following section contains information about your network" >> $DEBUG
69 $ECHO "* interfaces. The one you chose for PPPoE should contain the words:" >> $DEBUG
70 $ECHO "* 'UP' and 'RUNNING'. If it does not, you probably have an Ethernet" >> $DEBUG
71 $ECHO "* driver problem." >> $DEBUG
72 $ECHO "Output of ifconfig -a" >> $DEBUG
73 $IFCONFIG -a >> $DEBUG
74 $ECHO "---------------------------------------------" >> $DEBUG
75 if [ "`uname -s`" = "Linux" ] ; then
76 $ECHO "* The following section contains information about kernel modules" >> $DEBUG
77 $ECHO "* If the module for your Ethernet card is 'tulip', you might" >> $DEBUG
78 $ECHO "* want to look for an updated version at http://www.scyld.com" >> $DEBUG
79 $ECHO "Output of lsmod" >> $DEBUG
80 lsmod >> $DEBUG
81 $ECHO "---------------------------------------------" >> $DEBUG
83 $ECHO "* The following section lists your routing table." >> $DEBUG
84 $ECHO "* If you have an entry which starts with '0.0.0.0', you probably" >> $DEBUG
85 $ECHO "* have defined a default route and gateway, and pppd will" >> $DEBUG
86 $ECHO "* not create a default route using your ISP. Try getting" >> $DEBUG
87 $ECHO "* rid of this route." >> $DEBUG
88 $ECHO "Output of netstat -n -r" >> $DEBUG
89 netstat -n -r >> $DEBUG
90 $ECHO "---------------------------------------------" >> $DEBUG
91 $ECHO "Contents of /etc/resolv.conf" >> $DEBUG
92 $ECHO "* The following section lists DNS setup." >> $DEBUG
93 $ECHO "* If you can browse by IP address, but not name, suspect" >> $DEBUG
94 $ECHO "* a DNS problem." >> $DEBUG
95 cat /etc/resolv.conf >> $DEBUG
96 $ECHO "---------------------------------------------" >> $DEBUG
97 $ECHO "* The following section lists /etc/ppp/options." >> $DEBUG
98 $ECHO "* You should have NOTHING in that file." >> $DEBUG
99 $ECHO "Contents of /etc/ppp/options" >> $DEBUG
100 cat /etc/ppp/options >> $DEBUG 2>/dev/null
101 $ECHO "---------------------------------------------" >> $DEBUG
102 else
103 DEBUG=""
106 # Sort out command-line arguments
107 case "$#" in
109 CONFIG="$1"
112 CONFIG="$3"
114 esac
116 if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
117 $ECHO "$ME: Cannot read configuration file '$CONFIG'" >& 2
118 exit 1
120 export CONFIG
121 . $CONFIG
123 # Check for command-line overriding of ETH and USER
124 case "$#" in
125 2|3)
126 ETH="$1"
127 USER="$2"
129 esac
131 # Check for pidfile
132 if [ -r "$PIDFILE" ] ; then
133 PID=`cat "$PIDFILE"`
134 # Check if still running
135 kill -0 $PID > /dev/null 2>&1
136 if [ $? = 0 ] ; then
137 $ECHO "$ME: There already seems to be a PPPoE connection up (PID $PID)" >& 2
138 exit 1
140 # Delete bogus PIDFILE
141 rm -f "$PIDFILE" "$PIDFILE.pppd" "$PIDFILE.pppoe" "$PIDFILE.start"
144 echo $$ > $PIDFILE.start
146 # Start the connection in the background unless we're debugging
147 if [ "$DEBUG" != "" ] ; then
148 $CONNECT "$@"
149 exit 0
152 $CONNECT "$@" > /dev/null 2>&1 &
153 CONNECT_PID=$!
155 if [ "$CONNECT_TIMEOUT" = "" -o "$CONNECT_TIMEOUT" = 0 ] ; then
156 exit 0
159 # Don't monitor connection if dial-on-demand
160 if [ "$DEMAND" != "" -a "$DEMAND" != "no" ] ; then
161 exit 0
164 # Monitor connection
165 TIME=0
166 while [ true ] ; do
167 @sbindir@/pppoe-status $CONFIG > /dev/null 2>&1
169 # Looks like the interface came up
170 if [ $? = 0 ] ; then
171 # Print newline if standard input is a TTY
172 tty -s && $ECHO " Connected!"
173 exit 0
176 if test -n "$FORCEPING" ; then
177 printf "%s" "$FORCEPING"
178 else
179 tty -s && printf "%s" "$PING"
181 sleep $CONNECT_POLL
182 TIME=`expr $TIME + $CONNECT_POLL`
183 if [ $TIME -gt $CONNECT_TIMEOUT ] ; then
184 break
186 done
188 $ECHO "TIMED OUT" >& 2
189 # Timed out! Kill the pppoe-connect process and quit
190 kill $CONNECT_PID > /dev/null 2>&1
192 # Clean up PIDFILE(s)
193 rm -f "$PIDFILE" "$PIDFILE.pppd" "$PIDFILE.pppoe" "$PIDFILE.start"
195 exit 1