home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / pppoe-connect < prev    next >
Encoding:
Text File  |  2005-12-20  |  8.8 KB  |  326 lines

  1. #!/bin/sh
  2. # ../scripts/pppoe-connect.  Generated from pppoe-connect.in by configure.
  3. #***********************************************************************
  4. #
  5. # pppoe-connect
  6. #
  7. # Shell script to connect to a PPPoE provider
  8. #
  9. # Copyright (C) 2000 Roaring Penguin Software Inc.
  10. #
  11. # $Id: pppoe-connect.in,v 1.3 2005/08/29 12:16:37 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: pppoe-connect [config_file]
  19. #        pppoe-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 "`/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. export CONFIG
  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 pppoe-start, not pppoe-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 nic-$ETH"
  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 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.  
  223.  echo "hacked" >/dev/null #BK
  224. #BK    rm -f /etc/resolv.conf
  225. #BK    ln -s /etc/ppp/resolv.conf /etc/resolv.conf
  226.  
  227. elif test "$DNSTYPE" = "SPECIFY" ; then
  228.     # Sorry, dude...
  229.     rm -f /etc/resolv.conf
  230.     echo "nameserver $DNS1" > /etc/resolv.conf
  231.     if test -n "$DNS2" ; then
  232.     echo "nameserver $DNS2" >> /etc/resolv.conf
  233.     fi
  234. fi
  235.  
  236. # PPPoE invocation
  237. PPPOE_CMD="$PPPOE -p $PPPOE_PIDFILE -I $ETH -T $PPPOE_TIMEOUT -U $PPPOE_SYNC $CLAMPMSS $ACNAME $SERVICENAMEOPT $PPPOE_EXTRA"
  238. if test "$DEBUG" != "" ; then
  239.     if test "$DEMAND" != "" ; then
  240.     echo "(Turning off DEMAND for debugging purposes)"
  241.     DEMAND=""
  242.     fi
  243.     echo "* The following section shows the pppd command we will invoke" >> $DEBUG
  244.     echo "pppd invocation" >> $DEBUG
  245.     echo "$SETSID $PPPD pty '$PPPOE_CMD' $PPP_STD_OPTIONS $PPPD_SYNC debug" >> $DEBUG
  246.     echo "---------------------------------------------" >> $DEBUG
  247.     $SETSID $PPPD pty "$PPPOE_CMD -D $DEBUG-0" \
  248.     $PPP_STD_OPTIONS \
  249.     $PPPD_SYNC \
  250.     debug >> $DEBUG 2>&1
  251.     echo "---------------------------------------------" >> $DEBUG
  252.     echo "* The following section is an extract from your log." >> $DEBUG
  253.     echo "* Look for error messages from pppd, such as" >> $DEBUG
  254.     echo "* a lack of kernel support for PPP, authentication failure" >> $DEBUG
  255.     echo "* etc." >> $DEBUG
  256.     if test -f "/var/log/messages" ; then
  257.     echo "Extract from /var/log/messages" >> $DEBUG
  258.     grep 'ppp' /var/log/messages | tail -150 >> $DEBUG
  259.     elif test -f "/var/adm/messages"; then
  260.     echo "Extract from /var/adm/messages" >> $DEBUG
  261.     grep 'ppp' /var/adm/messages | tail -150 >> $DEBUG
  262.     else
  263.         echo "Can't find messages file (looked for /var/{log,adm}/messages" >> $DEBUG
  264.     fi
  265.     date >> $DEBUG
  266.     echo "---------------------------------------------" >> $DEBUG
  267.     echo "* The following section is a dump of the packets" >> $DEBUG
  268.     echo "* sent and received by rp-pppoe.  If you don't see" >> $DEBUG
  269.     echo "* any output, it's an Ethernet driver problem.  If you only" >> $DEBUG
  270.     echo "* see three PADI packets and nothing else, check your cables" >> $DEBUG
  271.     echo "* and modem.  Make sure the modem lights flash when you try" >> $DEBUG
  272.     echo "* to connect.  Check that your Ethernet card is in" >> $DEBUG
  273.     echo "* half-duplex, 10Mb/s mode.  If all else fails," >> $DEBUG
  274.     echo "* try using pppoe-sniff." >> $DEBUG
  275.     echo "rp-pppoe debugging dump" >> $DEBUG
  276.     cat $DEBUG-0 >> $DEBUG
  277.     rm -f $DEBUG-0
  278.     for i in 1 2 3 4 5 6 7 8 9 10 ; do
  279.     echo ""
  280.     echo ""
  281.     echo ""
  282.     done
  283.     echo "*** Finished debugging run.  Please review the file"
  284.     echo "*** '$DEBUG' and try to"
  285.     echo "*** figure out what is going on."
  286.     echo "***"
  287.     echo "*** Unfortunately, we can NO LONGER accept debugging"
  288.     echo "*** output for analysis.  Please do not send this to"
  289.     echo "*** Roaring Penguin; it is too time-consuming for"
  290.     echo "*** us to deal with all the analyses we have been sent."
  291.     exit 0
  292. fi
  293.  
  294. echo $$ > $PIDFILE
  295.  
  296. while [ true ] ; do
  297.     if test "$OVERRIDE_PPPD_COMMAND" != "" ; then
  298.     $SETSID $OVERRIDE_PPPD_COMMAND &
  299.     echo "$!" > $PPPD_PIDFILE
  300.     elif test "$LINUX_PLUGIN" != "" ; then
  301.     $SETSID $PPPD $PPP_STD_OPTIONS $DEMAND &
  302.     echo "$!" > $PPPD_PIDFILE
  303.     else
  304.     $SETSID $PPPD pty "$PPPOE_CMD" \
  305.         $PPP_STD_OPTIONS \
  306.         $DEMAND \
  307.         $PPPD_SYNC &
  308.     echo "$!" > $PPPD_PIDFILE
  309.     fi
  310.     wait
  311.  
  312.     if test "$RETRY_ON_FAILURE" = "no" ; then
  313.     exit
  314.     fi
  315.  
  316.     # Run /etc/ppp/pppoe-lost if it exists
  317.     test -x /etc/ppp/pppoe-lost && /etc/ppp/pppoe-lost
  318.  
  319.     # Re-establish the connection
  320.     $LOGGER -p daemon.notice \
  321.         "PPPoE connection lost; attempting re-connection."
  322.  
  323.     # Wait a bit in case a problem causes tons of log messages :-)
  324.     sleep 5
  325. done
  326.