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

  1. #!/bin/sh
  2. # Generated automatically from adsl-connect.in by configure.
  3. #***********************************************************************
  4. #
  5. # adsl-connect
  6. #
  7. # Shell script to connect to an ADSL provider using PPPoE
  8. #
  9. # Copyright (C) 2000 Roaring Penguin Software Inc.
  10. #
  11. # $Id: adsl-connect.in,v 1.23 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-connect [config_file]
  19. #        adsl-connect 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. localstatedir=/var
  29.  
  30. # Paths to programs
  31. IFCONFIG=/sbin/ifconfig
  32. PPPD=/usr/sbin/pppd
  33. SETSID=/usr/bin/setsid
  34. PPPOE=${exec_prefix}/sbin/pppoe
  35. LOGGER="/usr/bin/logger -t `basename $0`"
  36.  
  37. # Set to "C" locale so we can parse messages from commands
  38. LANG=C
  39. export LANG
  40.  
  41. # Must be root
  42. if test "`/usr/bin/id -u`" != 0 ; then
  43.     echo "$0: You must be root to run this script" >& 2
  44.     exit 1
  45. fi
  46.  
  47. if test "$SETSID" != "" -a ! -x "$SETSID"; then
  48.     SETSID=""
  49. fi
  50.  
  51. CONFIG=/etc//ppp/pppoe.conf
  52. USER=""
  53. ETH=""
  54.  
  55. # Sort out command-line arguments
  56. case "$#" in
  57.     1)
  58.     CONFIG="$1"
  59.     ;;
  60.     3)
  61.     CONFIG="$3"
  62.     ;;
  63. esac
  64.  
  65. if test ! -f "$CONFIG" -o ! -r "$CONFIG" ; then
  66.     echo "$0: Cannot read configuration file '$CONFIG'" >& 2
  67.     exit 1
  68. fi
  69.  
  70. . $CONFIG
  71.  
  72. PPPOE_PIDFILE="$PIDFILE.pppoe"
  73. PPPD_PIDFILE="$PIDFILE.pppd"
  74.  
  75. # Check for command-line overriding of ETH and USER
  76. case "$#" in
  77.     2|3)
  78.     ETH="$1"
  79.     USER="$2"
  80.     ;;
  81. esac
  82.  
  83. # Check that config file is sane
  84. if test "$USER" = "" ; then
  85.     echo "$0: Check '$CONFIG' -- no setting for USER" >& 2
  86.     exit 1
  87. fi
  88. if test "$ETH" = "" ; then
  89.     echo "$0: Check '$CONFIG' -- no setting for ETH" >& 2
  90.     exit 1
  91. fi
  92.  
  93. PPPD_PID=0
  94.  
  95. # Catch common error
  96. if test "$DEBUG" = "1" ; then
  97.     echo "*** If you want to use DEBUG, invoke adsl-start, not adsl-connect."
  98.     exit 1
  99. fi
  100.  
  101. if test "$DEBUG" != "" ; then
  102.     if test "$LINUX_PLUGIN" != "" ; then
  103.     echo "Cannot use DEBUG mode and LINUX_PLUGIN at the same time."
  104.     echo "Kernel-mode PPPoE is experimental and unsupported."
  105.     exit 1
  106.     fi
  107.     echo "* The following section identifies your Ethernet interface" >> $DEBUG
  108.     echo "* and user name.  Some ISP's need 'username'; others" >> $DEBUG
  109.     echo "* need 'username@isp.com'.  Try both" >> $DEBUG
  110.     echo "ETH=$ETH; USER=$USER" >> $DEBUG
  111.     echo "---------------------------------------------" >> $DEBUG
  112. fi
  113.  
  114. # MTU of Ethernet card attached to modem MUST be 1500.  This apparently
  115. # fails on some *BSD's, so we'll only do it under Linux
  116.  
  117. if test `uname -s` = Linux ; then
  118.     $IFCONFIG $ETH up mtu 1500
  119.     # For 2.4 kernels.  Will fail on 2.2.x, but who cares?
  120.     modprobe ppp_generic > /dev/null 2>&1
  121.     modprobe ppp_async > /dev/null 2>&1
  122.     modprobe ppp_synctty > /dev/null 2>&1
  123.     if test -n "$LINUX_PLUGIN" ; then
  124.     modprobe pppox > /dev/null 2>&1
  125.     modprobe pppoe > /dev/null 2>&1
  126.     fi
  127. fi
  128.  
  129. if test "$SYNCHRONOUS" = "yes" ; then
  130.     PPPOE_SYNC=-s
  131.     PPPD_SYNC=sync
  132.     # Increase the chances of it working on Linux...
  133.     if test `uname -s` = Linux ; then
  134.     modprobe n_hdlc > /dev/null 2>&1
  135.     fi
  136. else
  137.     PPPOE_SYNC=""
  138.     PPPD_SYNC=""
  139. fi
  140.  
  141. if test -n "$ACNAME" ; then
  142.     ACNAME="-C $ACNAME"
  143. fi
  144.  
  145. if test -n "$SERVICENAME" ; then
  146.     SERVICENAMEOPT="-S $SERVICENAME"
  147. else
  148.     SERVICENAMEOPT=""
  149. fi
  150.  
  151. if test "$CLAMPMSS" = "no" ; then
  152.     CLAMPMSS=""
  153. else
  154.     CLAMPMSS="-m $CLAMPMSS"
  155. fi
  156.  
  157. # If DNSTYPE is SERVER, we must use "usepeerdns" option to pppd.
  158. if test "$DNSTYPE" = "SERVER" ; then
  159.     PEERDNS=yes
  160.     USEPEERDNS=yes
  161. fi
  162.  
  163. if test "$PEERDNS" = "yes" ; then
  164.     PEERDNS="usepeerdns"
  165. else
  166.     PEERDNS=""
  167. fi
  168.  
  169. # Backward config file compatibility -- PEERDNS used to be USEPEERDNS
  170. if test "$USEPEERDNS" = "yes" ; then
  171.     PEERDNS="usepeerdns"
  172. fi
  173. if test "$USEPEERDNS" = "no" ; then
  174.     PEERDNS=""
  175. fi
  176.  
  177.  
  178. # Backward config file compatibility
  179. if test "$DEMAND" = "" ; then
  180.     DEMAND=no
  181. fi
  182.  
  183. if test "$DEMAND" = "no" ; then
  184.     DEMAND=""
  185. else
  186.     DEMAND="demand persist idle $DEMAND 10.112.112.112:10.112.112.113 ipcp-accept-remote ipcp-accept-local connect true noipdefault ktune"
  187. fi
  188.  
  189. case "$FIREWALL" in
  190.     STANDALONE)
  191.     . /etc/ppp/firewall-standalone
  192.     ;;
  193.     MASQUERADE)
  194.     . /etc/ppp/firewall-masq
  195.     ;;
  196. esac
  197.  
  198. # If we're using kernel-mode PPPoE on Linux...
  199. if test "$LINUX_PLUGIN" != "" ; then
  200.     PLUGIN_OPTS="plugin $LINUX_PLUGIN"
  201.     if test -n "$SERVICENAME" ; then
  202.     PLUGIN_OPTS="$PLUGIN_OPTS rp_pppoe_service $SERVICENAME"
  203.     fi
  204.  
  205.     # Interface name MUST BE LAST!!
  206.     PLUGIN_OPTS="$PLUGIN_OPTS $ETH"
  207.     modprobe pppoe > /dev/null 2>&1
  208. fi
  209.  
  210. if test "$DEFAULTROUTE" != "no" ; then
  211.     DEFAULTROUTE="defaultroute"
  212. else
  213.     DEFAULTROUTE=""
  214. fi
  215.  
  216. # Standard PPP options we always use
  217. PPP_STD_OPTIONS="$PLUGIN_OPTS noipdefault noauth default-asyncmap $DEFAULTROUTE hide-password nodetach $PEERDNS mtu 1492 mru 1492 noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp user $USER lcp-echo-interval $LCP_INTERVAL lcp-echo-failure $LCP_FAILURE $PPPD_EXTRA"
  218.  
  219. # Jigger DNS if required...
  220. if test "$DNSTYPE" = "SERVER" ; then
  221.     # Sorry, dude...
  222.     rm -f /etc/resolv.conf
  223.     ln -s /etc/ppp/resolv.conf /etc/resolv.conf
  224. elif test "$DNSTYPE" = "SPECIFY" ; then
  225.     # Sorry, dude...
  226.     rm -f /etc/resolv.conf
  227.     echo "nameserver $DNS1" > /etc/resolv.conf
  228.     if test -n "$DNS2" ; then
  229.     echo "nameserver $DNS2" >> /etc/resolv.conf
  230.     fi
  231. fi
  232.  
  233. # PPPoE invocation
  234. PPPOE_CMD="$PPPOE -p $PPPOE_PIDFILE -I $ETH -T $PPPOE_TIMEOUT -U $PPPOE_SYNC $CLAMPMSS $ACNAME $SERVICENAMEOPT $PPPOE_EXTRA"
  235. if test "$DEBUG" != "" ; then
  236.     if test "$DEMAND" != "" ; then
  237.     echo "(Turning off DEMAND for debugging purposes)"
  238.     DEMAND=""
  239.     fi
  240.     echo "* The following section shows the pppd command we will invoke" >> $DEBUG
  241.     echo "pppd invocation" >> $DEBUG
  242.     echo "$SETSID $PPPD pty '$PPPOE_CMD' $PPP_STD_OPTIONS $PPPD_SYNC debug" >> $DEBUG
  243.     echo "---------------------------------------------" >> $DEBUG
  244.     $SETSID $PPPD pty "$PPPOE_CMD -D $DEBUG-0" \
  245.     $PPP_STD_OPTIONS \
  246.     $PPPD_SYNC \
  247.     debug >> $DEBUG 2>&1
  248.     echo "---------------------------------------------" >> $DEBUG
  249.     echo "* The following section is an extract from your log." >> $DEBUG
  250.     echo "* Look for error messages from pppd, such as" >> $DEBUG
  251.     echo "* a lack of kernel support for PPP, authentication failure" >> $DEBUG
  252.     echo "* etc." >> $DEBUG
  253.     if test -f "/var/log/messages" ; then
  254.     echo "Extract from /var/log/messages" >> $DEBUG
  255.     grep 'ppp' /var/log/messages | tail -150 >> $DEBUG
  256.     elif test -f "/var/adm/messages"; then
  257.     echo "Extract from /var/adm/messages" >> $DEBUG
  258.     grep 'ppp' /var/adm/messages | tail -150 >> $DEBUG
  259.     else
  260.         echo "Can't find messages file (looked for /var/{log,adm}/messages" >> $DEBUG
  261.     fi
  262.     date >> $DEBUG
  263.     echo "---------------------------------------------" >> $DEBUG
  264.     echo "* The following section is a dump of the packets" >> $DEBUG
  265.     echo "* sent and received by rp-pppoe.  If you don't see" >> $DEBUG
  266.     echo "* any output, it's an Ethernet driver problem.  If you only" >> $DEBUG
  267.     echo "* see three PADI packets and nothing else, check your cables" >> $DEBUG
  268.     echo "* and modem.  Make sure the modem lights flash when you try" >> $DEBUG
  269.     echo "* to connect.  Check that your Ethernet card is in" >> $DEBUG
  270.     echo "* half-duplex, 10Mb/s mode.  If all else fails," >> $DEBUG
  271.     echo "* try using pppoe-sniff." >> $DEBUG
  272.     echo "rp-pppoe debugging dump" >> $DEBUG
  273.     cat $DEBUG-0 >> $DEBUG
  274.     rm -f $DEBUG-0
  275.     for i in 1 2 3 4 5 6 7 8 9 10 ; do
  276.     echo ""
  277.     echo ""
  278.     echo ""
  279.     done
  280.     echo "*** Finished debugging run.  Please review the file"
  281.     echo "*** '$DEBUG' and try to"
  282.     echo "*** figure out what is going on."
  283.     echo "***"
  284.     echo "*** Unfortunately, we can NO LONGER accept debugging"
  285.     echo "*** output for analysis.  Please do not send this to"
  286.     echo "*** Roaring Penguin; it is too time-consuming for"
  287.     echo "*** us to deal with all the analyses we have been sent."
  288.     exit 0
  289. fi
  290.  
  291. echo $$ > $PIDFILE
  292.  
  293. while [ true ] ; do
  294.     if test "$OVERRIDE_PPPD_COMMAND" != "" ; then
  295.     $SETSID $OVERRIDE_PPPD_COMMAND &
  296.     echo "$!" > $PPPD_PIDFILE
  297.     elif test "$LINUX_PLUGIN" != "" ; then
  298.     $SETSID $PPPD $PPP_STD_OPTIONS $DEMAND &
  299.     echo "$!" > $PPPD_PIDFILE
  300.     else
  301.     $SETSID $PPPD pty "$PPPOE_CMD" \
  302.         $PPP_STD_OPTIONS \
  303.         $DEMAND \
  304.         $PPPD_SYNC &
  305.     echo "$!" > $PPPD_PIDFILE
  306.     fi
  307.     wait
  308.  
  309.     if test "$RETRY_ON_FAILURE" = "no" ; then
  310.     exit
  311.     fi
  312.  
  313.     # Run /etc/ppp/adsl-lost if it exists
  314.     test -x /etc/ppp/adsl-lost && /etc/ppp/adsl-lost
  315.  
  316.     # Re-establish the connection
  317.     $LOGGER -p daemon.notice \
  318.         "ADSL connection lost; attempting re-connection."
  319.  
  320.     # Wait a bit in case a problem causes tons of log messages :-)
  321.     sleep 5
  322. done
  323.