wok diff rp-pppoe/stuff/pppoe-setup @ rev 8

Add : gcc-lib-base, rp-pppoe, rsync, zlib
author Christophe Lincoln <pankso@slitaz.org>
date Thu Dec 13 15:21:06 2007 +0100 (2007-12-13)
parents
children 283d55e62810
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rp-pppoe/stuff/pppoe-setup	Thu Dec 13 15:21:06 2007 +0100
     1.3 @@ -0,0 +1,352 @@
     1.4 +#!/bin/sh
     1.5 +#***********************************************************************
     1.6 +#
     1.7 +# pppoe-setup
     1.8 +#
     1.9 +# All-purpose slicing/dicing shell script to configure rp-pppoe.
    1.10 +#
    1.11 +# LIC: GPL
    1.12 +#
    1.13 +# Copyright (C) 2000 Roaring Penguin Software Inc.
    1.14 +#
    1.15 +# $Id: pppoe-setup.in,v 1.2 2005/08/10 00:25:18 dfs Exp $
    1.16 +#***********************************************************************
    1.17 +
    1.18 +# From AUTOCONF
    1.19 +prefix=/usr
    1.20 +exec_prefix=${prefix}
    1.21 +
    1.22 +# Paths to programs
    1.23 +IFCONFIG=/sbin/ifconfig
    1.24 +PPPD=/usr/sbin/pppd
    1.25 +PPPOE=${exec_prefix}/sbin/pppoe
    1.26 +ECHO=/bin/echo
    1.27 +LOGGER="/usr/bin/logger -t `basename $0`"
    1.28 +
    1.29 +# Set to "C" locale so we can parse messages from commands
    1.30 +LANG=C
    1.31 +export LANG
    1.32 +
    1.33 +CONFIG=/etc/ppp/pppoe.conf
    1.34 +
    1.35 +# Protect created files
    1.36 +umask 077
    1.37 +
    1.38 +copy() {
    1.39 +    cp $1 $2
    1.40 +    if [ "$?" != 0 ] ; then
    1.41 +	$ECHO "*** Error copying $1 to $2"
    1.42 +	$ECHO "*** Quitting."
    1.43 +	exit 1
    1.44 +    fi
    1.45 +}
    1.46 +
    1.47 +$ECHO "Welcome to the Roaring Penguin PPPoE client setup.  First, I will run"
    1.48 +$ECHO "some checks on your system to make sure the PPPoE client is installed"
    1.49 +$ECHO "properly..."
    1.50 +$ECHO ""
    1.51 +
    1.52 +# Must be root
    1.53 +if [ "`/usr/bin/id -u`" != 0 ] ; then
    1.54 +    $ECHO "$0: Sorry, you must be root to run this script"
    1.55 +    exit 1
    1.56 +fi
    1.57 +
    1.58 +# Prototype config file must exist
    1.59 +if [ ! -r "$CONFIG" ] ; then
    1.60 +    $ECHO "Oh, dear, I don't see the file '$CONFIG' anywhere.  Please"
    1.61 +    $ECHO "re-install the PPPoE client."
    1.62 +    exit 1
    1.63 +fi
    1.64 +
    1.65 +# Must have pppd
    1.66 +if [ ! -x $PPPD ] ; then
    1.67 +    $ECHO "Oops, I can't execute the program '$PPPD'.  You"
    1.68 +    $ECHO "must install the PPP software suite, version 2.3.10 or later."
    1.69 +    exit 1
    1.70 +fi
    1.71 +export CONFIG
    1.72 +. $CONFIG
    1.73 +
    1.74 +if [ "$DEMAND" = "" ] ; then
    1.75 +    DEMAND=no
    1.76 +fi
    1.77 +
    1.78 +# pppoe must exist
    1.79 +if [ ! -x "$PPPOE" ] ; then
    1.80 +    $ECHO "Oh, dear, I can't execute the program '$PPPOE'.  Please"
    1.81 +    $ECHO "re-install the rp-pppoe client."
    1.82 +    exit 1
    1.83 +fi
    1.84 +
    1.85 +$ECHO "Looks good!  Now, please enter some information:"
    1.86 +
    1.87 +while [ true ] ; do
    1.88 +    $ECHO ""
    1.89 +    $ECHO "USER NAME"
    1.90 +    $ECHO ""
    1.91 +    printf "%s" ">>> Enter your PPPoE user name (default $USER): "
    1.92 +    read U
    1.93 +
    1.94 +    if [ "$U" = "" ] ; then
    1.95 +	U="$USER"
    1.96 +    fi
    1.97 +
    1.98 +    # Under Linux, "fix" the default interface if eth1 is not available
    1.99 +    if test `uname -s` = "Linux" ; then
   1.100 +	$IFCONFIG $ETH > /dev/null 2>&1 || ETH=eth0
   1.101 +    fi
   1.102 +    $ECHO ""
   1.103 +    $ECHO "INTERFACE"
   1.104 +    $ECHO ""
   1.105 +    $ECHO ">>> Enter the Ethernet interface connected to the DSL modem"
   1.106 +    $ECHO "For Solaris, this is likely to be something like /dev/hme0."
   1.107 +    $ECHO "For Linux, it will be ethn, where 'n' is a number."
   1.108 +    printf "%s" "(default $ETH): "
   1.109 +    read E
   1.110 +
   1.111 +    if [ "$E" = "" ] ; then
   1.112 +	E="$ETH"
   1.113 +    fi
   1.114 +
   1.115 +    $ECHO ""
   1.116 +    $ECHO "Do you want the link to come up on demand, or stay up continuously?"
   1.117 +    $ECHO "If you want it to come up on demand, enter the idle time in seconds"
   1.118 +    $ECHO "after which the link should be dropped.  If you want the link to"
   1.119 +    $ECHO "stay up permanently, enter 'no' (two letters, lower-case.)"
   1.120 +    $ECHO "NOTE: Demand-activated links do not interact well with dynamic IP"
   1.121 +    $ECHO "addresses.  You may have some problems with demand-activated links."
   1.122 +    printf "%s" ">>> Enter the demand value (default $DEMAND): "
   1.123 +    read D
   1.124 +    if [ "$D" = "" ] ; then
   1.125 +	D=$DEMAND
   1.126 +    fi
   1.127 +
   1.128 +    $ECHO ""
   1.129 +    $ECHO "DNS"
   1.130 +    $ECHO ""
   1.131 +    $ECHO "Please enter the IP address of your ISP's primary DNS server."
   1.132 +    $ECHO "If your ISP claims that 'the server will provide DNS addresses',"
   1.133 +    $ECHO "enter 'server' (all lower-case) here."
   1.134 +    $ECHO "If you just press enter, I will assume you know what you are"
   1.135 +    $ECHO "doing and not modify your DNS setup."
   1.136 +    printf "%s" ">>> Enter the DNS information here: "
   1.137 +
   1.138 +    read DNS1
   1.139 +
   1.140 +
   1.141 +    if [ "$DNS1" != "" ] ; then
   1.142 +        if [ "$DNS1" != "server" ] ; then
   1.143 +	    $ECHO "Please enter the IP address of your ISP's secondary DNS server."
   1.144 +	    $ECHO "If you just press enter, I will assume there is only one DNS server."
   1.145 +	    printf "%s" ">>> Enter the secondary DNS server address here: "
   1.146 +	    read DNS2
   1.147 +	fi
   1.148 +    fi
   1.149 +
   1.150 +    while [ true ] ; do
   1.151 +	$ECHO ""
   1.152 +	$ECHO "PASSWORD"
   1.153 +	$ECHO ""
   1.154 +	stty -echo
   1.155 +	printf "%s" ">>> Please enter your PPPoE password:    "
   1.156 +	read PWD1
   1.157 +	$ECHO ""
   1.158 +	printf "%s" ">>> Please re-enter your PPPoE password: "
   1.159 +	read PWD2
   1.160 +	$ECHO ""
   1.161 +	stty echo
   1.162 +	if [ "$PWD1" = "$PWD2" ] ; then
   1.163 +	    break
   1.164 +	fi
   1.165 +
   1.166 +	printf "%s" ">>> Sorry, the passwords do not match.  Try again? (y/n)"
   1.167 +	read ANS
   1.168 +	case "$ANS" in
   1.169 +	    N|No|NO|Non|n|no|non)
   1.170 +		$ECHO "OK, quitting.  Bye."
   1.171 +		exit 1
   1.172 +	esac
   1.173 +    done
   1.174 +
   1.175 +    # Firewalling
   1.176 +    $ECHO ""
   1.177 +    $ECHO "FIREWALLING"
   1.178 +    $ECHO ""
   1.179 +    if test `uname -s` != "Linux" ; then
   1.180 +	$ECHO "Sorry, firewalling is only supported under Linux.  Consult"
   1.181 +	$ECHO "your operating system manuals for details on setting up"
   1.182 +	$ECHO "packet filters for your system."
   1.183 +	FIREWALL=NONE
   1.184 +    else
   1.185 +	$ECHO "Please choose the firewall rules to use.  Note that these rules are"
   1.186 +	$ECHO "very basic.  You are strongly encouraged to use a more sophisticated"
   1.187 +	$ECHO "firewall setup; however, these will provide basic security.  If you"
   1.188 +	$ECHO "are running any servers on your machine, you must choose 'NONE' and"
   1.189 +	$ECHO "set up firewalling yourself.  Otherwise, the firewall rules will deny"
   1.190 +	$ECHO "access to all standard servers like Web, e-mail, ftp, etc.  If you"
   1.191 +	$ECHO "are using SSH, the rules will block outgoing SSH connections which"
   1.192 +	$ECHO "allocate a privileged source port."
   1.193 +	$ECHO ""
   1.194 +	while [ true ] ; do
   1.195 +	    $ECHO "The firewall choices are:"
   1.196 +	    $ECHO "0 - NONE: This script will not set any firewall rules.  You are responsible"
   1.197 +	    $ECHO "          for ensuring the security of your machine.  You are STRONGLY"
   1.198 +	    $ECHO "          recommended to use some kind of firewall rules."
   1.199 +	    $ECHO "1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation"
   1.200 +	    $ECHO "2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway"
   1.201 +	    $ECHO "                for a LAN"
   1.202 +	    printf "%s" ">>> Choose a type of firewall (0-2): "
   1.203 +	    read a
   1.204 +	    if [ "$a" = 0 -o "$a" = 1 -o "$a" = 2 ] ; then
   1.205 +		break
   1.206 +	    fi
   1.207 +	    $ECHO "Please enter a number from 0 to 2"
   1.208 +	done
   1.209 +
   1.210 +	case "$a" in
   1.211 +	    0)
   1.212 +		FIREWALL=NONE
   1.213 +		;;
   1.214 +	    1)
   1.215 +		FIREWALL=STANDALONE
   1.216 +		;;
   1.217 +	    2)
   1.218 +		FIREWALL=MASQUERADE
   1.219 +		;;
   1.220 +	esac
   1.221 +    fi
   1.222 +
   1.223 +    $ECHO ""
   1.224 +    $ECHO "** Summary of what you entered **"
   1.225 +    $ECHO ""
   1.226 +    $ECHO "Ethernet Interface: $E"
   1.227 +    $ECHO "User name:          $U"
   1.228 +    if [ "$D" = "no" ] ; then
   1.229 +	$ECHO "Activate-on-demand: No"
   1.230 +    else
   1.231 +	$ECHO "Activate-on-demand: Yes; idle timeout = $D seconds"
   1.232 +    fi
   1.233 +
   1.234 +    if [ "$DNS1" != "" ] ; then
   1.235 +        if [ "$DNS1" = "server" ] ; then
   1.236 +	    $ECHO "DNS addresses:      Supplied by ISP's server"
   1.237 +        else
   1.238 +	    $ECHO "Primary DNS:        $DNS1"
   1.239 +	    if [ "$DNS2" != "" ] ; then
   1.240 +		$ECHO "Secondary DNS:      $DNS2"
   1.241 +	    fi
   1.242 +        fi
   1.243 +    else
   1.244 +	$ECHO "DNS:                Do not adjust"
   1.245 +    fi
   1.246 +    $ECHO "Firewalling:        $FIREWALL"
   1.247 +    $ECHO ""
   1.248 +    while [ true ] ; do
   1.249 +        printf "%s" '>>> Accept these settings and adjust configuration files (y/n)? '
   1.250 +        read ANS
   1.251 +	case "ANS" in
   1.252 +	    Y|y|yes|Yes|oui|Oui)
   1.253 +		ANS=y
   1.254 +		;;
   1.255 +            N|n|no|No|non|Non)
   1.256 +		ANS=n
   1.257 +		;;
   1.258 +	esac
   1.259 +	if [ "$ANS" = "y" -o "$ANS" = "n" ] ; then
   1.260 +	    break
   1.261 +        fi
   1.262 +    done
   1.263 +    if [ "$ANS" = "y" ] ; then
   1.264 +	break
   1.265 +    fi
   1.266 +done
   1.267 +
   1.268 +# Adjust configuration files.  First to $CONFIG
   1.269 +
   1.270 +$ECHO "Adjusting $CONFIG"
   1.271 +
   1.272 +copy $CONFIG $CONFIG-bak
   1.273 +if [ "$DNS1" = "server" ] ; then
   1.274 +    DNSTYPE=SERVER
   1.275 +    DNS1=""
   1.276 +    PEERDNS=yes
   1.277 +else
   1.278 +    PEERDNS=no
   1.279 +    if [ "$DNS1" = "" ] ; then
   1.280 +	DNSTYPE=NOCHANGE
   1.281 +    else
   1.282 +	DNSTYPE=SPECIFY
   1.283 +    fi
   1.284 +fi
   1.285 +
   1.286 +# Where is pppd likely to put its pid?
   1.287 +if [ -d /var/run ] ; then
   1.288 +    VARRUN=/var/run
   1.289 +else
   1.290 +    VARRUN=/etc/ppp
   1.291 +fi
   1.292 +
   1.293 +# Some #$(*& ISP's use a slash in the user name...
   1.294 +sed -e "s&^USER=.*&USER='$U'&" \
   1.295 +    -e "s&^ETH=.*&ETH='$E'&" \
   1.296 +    -e "s&^PIDFILE=.*&PIDFILE=\"$VARRUN/\$CF_BASE-pppoe.pid\"&" \
   1.297 +    -e "s/^FIREWALL=.*/FIREWALL=$FIREWALL/" \
   1.298 +    -e "s/^DEMAND=.*/DEMAND=$D/" \
   1.299 +    -e "s/^DNSTYPE=.*/DNSTYPE=$DNSTYPE/" \
   1.300 +    -e "s/^DNS1=.*/DNS1=$DNS1/" \
   1.301 +    -e "s/^DNS2=.*/DNS2=$DNS2/" \
   1.302 +    -e "s/^PEERDNS=.*/PEERDNS=$PEERDNS/" \
   1.303 +    < $CONFIG-bak > $CONFIG
   1.304 +
   1.305 +if [ $? != 0 ] ; then
   1.306 +    $ECHO "** Error modifying $CONFIG"
   1.307 +    $ECHO "** Quitting"
   1.308 +    exit 1
   1.309 +fi
   1.310 +
   1.311 +if [ "$DNS1" != "" ] ; then
   1.312 +    if [ "$DNS1" != "server" ] ; then
   1.313 +	$ECHO "Adjusting /etc/resolv.conf"
   1.314 +	if [ -r /etc/resolv.conf ] ; then
   1.315 +	    grep -s "MADE-BY-RP-PPPOE" /etc/resolv.conf > /dev/null 2>&1
   1.316 +	    if [ "$?" != 0 ] ; then
   1.317 +		$ECHO "  (But first backing it up to /etc/resolv.conf-bak)"
   1.318 +		copy /etc/resolv.conf /etc/resolv.conf-bak
   1.319 +	    fi
   1.320 +	fi
   1.321 +	$ECHO "# MADE-BY-RP-PPPOE" > /etc/resolv.conf
   1.322 +	$ECHO "nameserver $DNS1" >> /etc/resolv.conf
   1.323 +	if [ "$DNS2" != "" ] ; then
   1.324 +	    $ECHO "nameserver $DNS2" >> /etc/resolv.conf
   1.325 +	fi
   1.326 +    fi
   1.327 +fi
   1.328 +
   1.329 +$ECHO "Adjusting /etc/ppp/pap-secrets and /etc/ppp/chap-secrets"
   1.330 +if [ -r /etc/ppp/pap-secrets ] ; then
   1.331 +    $ECHO "  (But first backing it up to /etc/ppp/pap-secrets-bak)"
   1.332 +    copy /etc/ppp/pap-secrets /etc/ppp/pap-secrets-bak
   1.333 +else
   1.334 +    cp /dev/null /etc/ppp/pap-secrets-bak
   1.335 +fi
   1.336 +if [ -r /etc/ppp/chap-secrets ] ; then
   1.337 +    $ECHO "  (But first backing it up to /etc/ppp/chap-secrets-bak)"
   1.338 +    copy /etc/ppp/chap-secrets /etc/ppp/chap-secrets-bak
   1.339 +else
   1.340 +    cp /dev/null /etc/ppp/chap-secrets-bak
   1.341 +fi
   1.342 +
   1.343 +egrep -v "^$U|^\"$U\"" /etc/ppp/pap-secrets-bak > /etc/ppp/pap-secrets
   1.344 +$ECHO "\"$U\"	*	\"$PWD1\"" >> /etc/ppp/pap-secrets
   1.345 +egrep -v "^$U|^\"$U\"" /etc/ppp/chap-secrets-bak > /etc/ppp/chap-secrets
   1.346 +$ECHO "\"$U\"	*	\"$PWD1\"" >> /etc/ppp/chap-secrets
   1.347 +
   1.348 +$ECHO ""
   1.349 +$ECHO ""
   1.350 +$ECHO ""
   1.351 +$ECHO "Congratulations, it should be all set up!"
   1.352 +$ECHO ""
   1.353 +$ECHO "Type 'pppoe-start' to bring up your PPPoE link and 'pppoe-stop' to bring"
   1.354 +$ECHO "it down.  Type 'pppoe-status' to see the link status."
   1.355 +exit 0