1#!/bin/sh 2# @configure_input@ 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.1.1.1 2008/10/15 03:31:00 james26_jang Exp $ 12# 13# This file may be distributed under the terms of the GNU General 14# Public License. 15# 16# Usage: adsl-connect [config_file] 17# adsl-connect interface user [config_file] 18# Second form overrides USER and ETH from config file. 19# If config_file is omitted, defaults to /etc//ppp/pppoe.conf 20# 21#*********************************************************************** 22 23# From AUTOCONF 24prefix=@prefix@ 25exec_prefix=@exec_prefix@ 26localstatedir=/var 27 28# Paths to programs 29IFCONFIG=/sbin/ifconfig 30PPPD=@PPPD@ 31SETSID=@SETSID@ 32PPPOE=@sbindir@/pppoe 33LOGGER="/usr/bin/logger -t `basename $0`" 34 35# Must be root 36if test "`id -u`" != 0 ; then 37 echo "$0: You must be root to run this script" >& 2 38 exit 1 39fi 40 41if test "$SETSID" != "" -a ! -x "$SETSID"; then 42 SETSID="" 43fi 44 45CONFIG=/etc//ppp/pppoe.conf 46USER="" 47ETH="" 48 49# Sort out command-line arguments 50case "$#" in 51 1) 52 CONFIG="$1" 53 ;; 54 3) 55 CONFIG="$3" 56 ;; 57esac 58 59if test ! -f "$CONFIG" -o ! -r "$CONFIG" ; then 60 echo "$0: Cannot read configuration file '$CONFIG'" >& 2 61 exit 1 62fi 63 64. $CONFIG 65 66PPPOE_PIDFILE="$PIDFILE.pppoe" 67PPPD_PIDFILE="$PIDFILE.pppd" 68 69# Check for command-line overriding of ETH and USER 70case "$#" in 71 2|3) 72 ETH="$1" 73 USER="$2" 74 ;; 75esac 76 77# Check that config file is sane 78if test "$USER" = "" ; then 79 echo "$0: Check '$CONFIG' -- no setting for USER" >& 2 80 exit 1 81fi 82if test "$ETH" = "" ; then 83 echo "$0: Check '$CONFIG' -- no setting for ETH" >& 2 84 exit 1 85fi 86 87PPPD_PID=0 88 89# Catch common error 90if test "$DEBUG" = "1" ; then 91 echo "*** If you want to use DEBUG, invoke adsl-start, not adsl-connect." 92 exit 1 93fi 94 95if test "$DEBUG" != "" ; then 96 echo "ETH=$ETH; USER=$USER" >> $DEBUG 97 echo "---------------------------------------------" >> $DEBUG 98fi 99 100# MTU of Ethernet card attached to modem MUST be 1500. This apparently 101# fails on some *BSD's, so we'll only do it under Linux 102 103if test `uname -s` = Linux ; then 104 $IFCONFIG $ETH up mtu 1500 105fi 106 107if test "$SYNCHRONOUS" = "yes" ; then 108 PPPOE_SYNC=-s 109 PPPD_SYNC=sync 110 # Increase the chances of it working on Linux... 111 if test `uname -s` = Linux ; then 112 modprobe n_hdlc > /dev/null 2>&1 113 fi 114else 115 PPPOE_SYNC="" 116 PPPD_SYNC="" 117fi 118 119if test "$CLAMPMSS" = "no" ; then 120 CLAMPMSS="" 121else 122 CLAMPMSS="-m $CLAMPMSS" 123fi 124 125if test "$USEPEERDNS" = "yes" ; then 126 USEPEERDNS="usepeerdns" 127else 128 USEPEERDNS="" 129fi 130 131# Backward config file compatibility 132if test "$DEMAND" = "" ; then 133 DEMAND=no 134fi 135 136if test "$DEMAND" = "no" ; then 137 DEMAND="" 138else 139 DEMAND="demand persist idle $DEMAND 10.112.112.112:10.112.112.113 ipcp-accept-remote ipcp-accept-local connect true noipdefault ktune" 140fi 141 142case "$FIREWALL" in 143 STANDALONE) 144 . /etc/ppp/firewall-standalone 145 ;; 146 MASQUERADE) 147 . /etc/ppp/firewall-masq 148 ;; 149esac 150 151# Standard PPP options we always use 152PPP_STD_OPTIONS="noipdefault noauth defaultroute hide-password nodetach $USEPEERDNS local mtu 1492 mru 1492 noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp user $USER lcp-echo-interval $LCP_INTERVAL lcp-echo-failure $LCP_FAILURE" 153 154# PPPoE invocation 155PPPOE_CMD="$PPPOE -p $PPPOE_PIDFILE -I $ETH -T $PPPOE_TIMEOUT $PPPOE_SYNC $CLAMPMSS $PPPOE_EXTRA" 156if test "$DEBUG" != "" ; then 157 if test "$DEMAND" != "" ; then 158 echo "(Turning off DEMAND for debugging purposes)" 159 DEMAND="" 160 fi 161 echo "pppd invocation" >> $DEBUG 162 echo "$SETSID $PPPD pty '$PPPOE_CMD' $PPP_STD_OPTIONS $PPPD_SYNC debug" >> $DEBUG 163 echo "---------------------------------------------" >> $DEBUG 164 $SETSID $PPPD pty "$PPPOE_CMD -D $DEBUG-0" \ 165 $PPP_STD_OPTIONS \ 166 $PPPD_SYNC \ 167 debug >> $DEBUG 2>&1 168 echo "---------------------------------------------" >> $DEBUG 169 170 echo "Extract from /var/log/messages" >> $DEBUG 171 grep 'ppp' /var/log/messages | tail -150 >> $DEBUG 172 date >> $DEBUG 173 echo "---------------------------------------------" >> $DEBUG 174 echo "rp-pppoe debugging dump" >> $DEBUG 175 cat $DEBUG-0 >> $DEBUG 176 rm -f $DEBUG-0 177 for i in 1 2 3 4 5 6 7 8 9 10 ; do 178 echo "" 179 echo "" 180 echo "" 181 done 182 echo "*** Finished debugging run. Please review the file" 183 echo "*** '$DEBUG' and make sure it does not contain" 184 echo "*** any sensitive information. Once you are satisfied with it," 185 echo "*** e-mail it to 'pppoe@roaringpenguin.com' for diagnosis." 186 echo "" 187 echo "*** BUT BEFORE YOU DO THIS, make sure you have read the HOW-TO-CONNECT" 188 echo "*** file which came with the rp-pppoe package." 189 exit 0 190fi 191 192echo $$ > $PIDFILE 193 194while [ true ] ; do 195 $SETSID $PPPD pty "$PPPOE_CMD" \ 196 $PPP_STD_OPTIONS \ 197 $DEMAND \ 198 $PPPD_SYNC & 199 echo "$!" > $PPPD_PIDFILE 200 wait 201 202 # Otherwise, re-establish the connection 203 $LOGGER -p daemon.notice \ 204 "ADSL connection lost; attempting re-connection." 205done 206