home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 March / PCWELT_3_2006.ISO / base / 05_common.mo / usr / sbin / adsl-start < prev    next >
Encoding:
Text File  |  2003-03-02  |  5.4 KB  |  197 lines

  1. #!/bin/sh
  2. # Generated automatically from adsl-start.in by configure.
  3. #***********************************************************************
  4. #
  5. # adsl-start
  6. #
  7. # Shell script to bring up an ADSL connection
  8. #
  9. # Copyright (C) 2000 Roaring Penguin Software Inc.
  10. #
  11. # $Id: adsl-start.in,v 1.8 2002/04/09 17:28:39 dfs Exp $
  12. #
  13. # This file may be distributed under the terms of the GNU General
  14. # Public License.
  15. #
  16. # LIC: GPL
  17. #
  18. # Usage: adsl-start [config_file]
  19. #        adsl-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
  22. #
  23. #***********************************************************************
  24.  
  25. # From AUTOCONF
  26. prefix=/usr
  27. exec_prefix=${prefix}
  28.  
  29. # Paths to programs
  30. CONNECT=${exec_prefix}/sbin/adsl-connect
  31. ECHO=/usr/bin/echo
  32. IFCONFIG=/sbin/ifconfig
  33.  
  34. # Set to "C" locale so we can parse messages from commands
  35. LANG=C
  36. export LANG
  37.  
  38. # Defaults
  39. CONFIG=/etc/ppp/pppoe.conf
  40. USER=""
  41. ETH=""
  42. ME=`basename $0`
  43. # Must be root
  44. if [ "`/usr/bin/id -u`" != 0 ] ; then
  45.     $ECHO "$ME: You must be root to run this script" >& 2
  46.     exit 1
  47. fi
  48.  
  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
  58.     fi
  59.     DEBUG=$DEBUG/pppoe-debug.txt
  60.  
  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
  82.     fi
  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=""
  104. fi
  105.  
  106. # Sort out command-line arguments
  107. case "$#" in
  108.     1)
  109.     CONFIG="$1"
  110.     ;;
  111.     3)
  112.     CONFIG="$3"
  113.     ;;
  114. esac
  115.  
  116. if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
  117.     $ECHO "$ME: Cannot read configuration file '$CONFIG'" >& 2
  118.     exit 1
  119. fi
  120.  
  121. . $CONFIG
  122.  
  123. # Check for command-line overriding of ETH and USER
  124. case "$#" in
  125.     2|3)
  126.     ETH="$1"
  127.     USER="$2"
  128.     ;;
  129. esac
  130.  
  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 an ADSL connection up (PID $PID)" >& 2
  138.     exit 1
  139.     fi
  140.     # Delete bogus PIDFILE
  141.     rm -f "$PIDFILE" "$PIDFILE.pppd" "$PIDFILE.pppoe" "$PIDFILE.start"
  142. fi
  143.  
  144. echo $$ > $PIDFILE.start
  145.  
  146. # Start the connection in the background unless we're debugging
  147. if [ "$DEBUG" != "" ] ; then
  148.     $CONNECT "$@"
  149.     exit 0
  150. fi
  151.  
  152. $CONNECT "$@" > /dev/null 2>&1 &
  153. CONNECT_PID=$!
  154.  
  155. if [ "$CONNECT_TIMEOUT" = "" -o "$CONNECT_TIMEOUT" = 0 ] ; then
  156.     exit 0
  157. fi
  158.  
  159. # Don't monitor connection if dial-on-demand
  160. if [ "$DEMAND" != "" -a "$DEMAND" != "no" ] ; then
  161.     exit 0
  162. fi
  163.  
  164. # Monitor connection
  165. TIME=0
  166. while [ true ] ; do
  167.     ${exec_prefix}/sbin/adsl-status $CONFIG > /dev/null 2>&1
  168.  
  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
  174.     fi
  175.  
  176.     if test -n "$FORCEPING" ; then
  177.     $ECHO -n "$FORCEPING"
  178.     else
  179.     tty -s && $ECHO -n "$PING"
  180.     fi
  181.     sleep $CONNECT_POLL
  182.     TIME=`expr $TIME + $CONNECT_POLL`
  183.     if [ $TIME -gt $CONNECT_TIMEOUT ] ; then
  184.     break
  185.     fi
  186. done
  187.  
  188. $ECHO "TIMED OUT" >& 2
  189. # Timed out!  Kill the adsl-connect process and quit
  190. kill $CONNECT_PID > /dev/null 2>&1
  191.  
  192. # Clean up PIDFILE(s)
  193. rm -f "$PIDFILE" "$PIDFILE.pppd" "$PIDFILE.pppoe" "$PIDFILE.start"
  194.  
  195. exit 1
  196.  
  197.