1#!/bin/sh 2#*********************************************************************** 3# 4# pppoe-setup 5# 6# All-purpose slicing/dicing shell script to configure rp-pppoe. 7# 8# LIC: GPL 9# 10# Copyright (C) 2000 Roaring Penguin Software Inc. 11# Copyright (C) 2018 Dianne Skoll 12# 13#*********************************************************************** 14 15# From AUTOCONF 16prefix=@prefix@ 17exec_prefix=@exec_prefix@ 18 19# Paths to programs 20IFCONFIG=/sbin/ifconfig 21IP=@IP@ 22PPPD=@PPPD@ 23PPPOE=@sbindir@/pppoe 24LOGGER="/usr/bin/logger -t `basename $0`" 25 26# Set to "C" locale so we can parse messages from commands 27LANG=C 28export LANG 29 30CONFIG=${prefix}/etc/ppp/pppoe.conf 31 32# Protect created files 33umask 077 34 35copy() { 36 cp $1 $2 37 if [ "$?" != 0 ] ; then 38 echo "*** Error copying $1 to $2" 39 echo "*** Quitting." 40 exit 1 41 fi 42} 43 44echo "Welcome to the RP-PPPoE client setup. First, I will run" 45echo "some checks on your system to make sure the PPPoE client is installed" 46echo "properly..." 47echo "" 48 49# Must be root 50if [ "`@ID@ -u`" != 0 ] ; then 51 echo "$0: Sorry, you must be root to run this script" 52 exit 1 53fi 54 55# Prototype config file must exist 56if [ ! -r "$CONFIG" ] ; then 57 echo "Oh, dear, I don't see the file '$CONFIG' anywhere. Please" 58 echo "re-install the PPPoE client." 59 exit 1 60fi 61 62# Must have pppd 63if [ ! -x $PPPD ] ; then 64 echo "Oops, I can't execute the program '$PPPD'. You" 65 echo "must install the PPP software suite, version 2.3.10 or later." 66 exit 1 67fi 68export CONFIG 69. $CONFIG 70 71if [ "$DEMAND" = "" ] ; then 72 DEMAND=no 73fi 74 75# pppoe must exist 76if [ ! -x "$PPPOE" ] ; then 77 echo "Oh, dear, I can't execute the program '$PPPOE'. Please" 78 echo "re-install the rp-pppoe client." 79 exit 1 80fi 81 82echo "Looks good! Now, please enter some information:" 83 84while [ true ] ; do 85 echo "" 86 echo "USER NAME" 87 echo "" 88 printf "%s" ">>> Enter your PPPoE user name (default $USER): " 89 read U 90 91 if [ "$U" = "" ] ; then 92 U="$USER" 93 fi 94 95 # Under Linux, "fix" the default interface if eth1 is not available 96 if test `uname -s` = "Linux" ; then 97 $IP link show $ETH > /dev/null 2>&1 || ETH=eth0 98 else 99 $IFCONFIG $ETH > /dev/null 2>&1 || ETH=eth0 100 fi 101 echo "" 102 echo "INTERFACE" 103 echo "" 104 echo ">>> Enter the Ethernet interface connected to the DSL modem" 105 echo "For Solaris, this is likely to be something like /dev/hme0." 106 echo "For Linux, it will be ethn, where 'n' is a number." 107 printf "%s" "(default $ETH): " 108 read E 109 110 if [ "$E" = "" ] ; then 111 E="$ETH" 112 fi 113 114 echo "" 115 echo "Do you want the link to come up on demand, or stay up continuously?" 116 echo "If you want it to come up on demand, enter the idle time in seconds" 117 echo "after which the link should be dropped. If you want the link to" 118 echo "stay up permanently, enter 'no' (two letters, lower-case.)" 119 echo "NOTE: Demand-activated links do not interact well with dynamic IP" 120 echo "addresses. You may have some problems with demand-activated links." 121 printf "%s" ">>> Enter the demand value (default $DEMAND): " 122 read D 123 if [ "$D" = "" ] ; then 124 D=$DEMAND 125 fi 126 127 echo "" 128 echo "DNS" 129 echo "" 130 echo "Please enter the IP address of your ISP's primary DNS server." 131 echo "If your ISP claims that 'the server will provide DNS addresses'," 132 echo "enter 'server' (all lower-case) here." 133 echo "If you just press enter, I will assume you know what you are" 134 echo "doing and not modify your DNS setup." 135 printf "%s" ">>> Enter the DNS information here: " 136 137 read DNS1 138 139 140 if [ "$DNS1" != "" ] ; then 141 if [ "$DNS1" != "server" ] ; then 142 echo "Please enter the IP address of your ISP's secondary DNS server." 143 echo "If you just press enter, I will assume there is only one DNS server." 144 printf "%s" ">>> Enter the secondary DNS server address here: " 145 read DNS2 146 fi 147 fi 148 149 while [ true ] ; do 150 echo "" 151 echo "PASSWORD" 152 echo "" 153 stty -echo 154 printf "%s" ">>> Please enter your PPPoE password: " 155 read PWD1 156 echo "" 157 printf "%s" ">>> Please re-enter your PPPoE password: " 158 read PWD2 159 echo "" 160 stty echo 161 if [ "$PWD1" = "$PWD2" ] ; then 162 break 163 fi 164 165 printf "%s" ">>> Sorry, the passwords do not match. Try again? (y/n)" 166 read ANS 167 case "$ANS" in 168 N|No|NO|Non|n|no|non) 169 echo "OK, quitting. Bye." 170 exit 1 171 esac 172 done 173 174 # Firewalling 175 echo "" 176 echo "FIREWALLING" 177 echo "" 178 if test `uname -s` != "Linux" ; then 179 echo "Sorry, firewalling is only supported under Linux. Consult" 180 echo "your operating system manuals for details on setting up" 181 echo "packet filters for your system." 182 FIREWALL=NONE 183 else 184 echo "Please choose the firewall rules to use. Note that these rules are" 185 echo "very basic. You are strongly encouraged to use a more sophisticated" 186 echo "firewall setup; however, these will provide basic security. If you" 187 echo "are running any servers on your machine, you must choose 'NONE' and" 188 echo "set up firewalling yourself. Otherwise, the firewall rules will deny" 189 echo "access to all standard servers like Web, e-mail, ftp, etc. If you" 190 echo "are using SSH, the rules will block outgoing SSH connections which" 191 echo "allocate a privileged source port." 192 echo "" 193 while [ true ] ; do 194 echo "The firewall choices are:" 195 echo "0 - NONE: This script will not set any firewall rules. You are responsible" 196 echo " for ensuring the security of your machine. You are STRONGLY" 197 echo " recommended to use some kind of firewall rules." 198 echo "1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation" 199 echo "2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway" 200 echo " for a LAN" 201 printf "%s" ">>> Choose a type of firewall (0-2): " 202 read a 203 if [ "$a" = 0 -o "$a" = 1 -o "$a" = 2 ] ; then 204 break 205 fi 206 echo "Please enter a number from 0 to 2" 207 done 208 209 case "$a" in 210 0) 211 FIREWALL=NONE 212 ;; 213 1) 214 FIREWALL=STANDALONE 215 ;; 216 2) 217 FIREWALL=MASQUERADE 218 ;; 219 esac 220 fi 221 222 echo "" 223 echo "** Summary of what you entered **" 224 echo "" 225 echo "Ethernet Interface: $E" 226 echo "User name: $U" 227 if [ "$D" = "no" ] ; then 228 echo "Activate-on-demand: No" 229 else 230 echo "Activate-on-demand: Yes; idle timeout = $D seconds" 231 fi 232 233 if [ "$DNS1" != "" ] ; then 234 if [ "$DNS1" = "server" ] ; then 235 echo "DNS addresses: Supplied by ISP's server" 236 else 237 echo "Primary DNS: $DNS1" 238 if [ "$DNS2" != "" ] ; then 239 echo "Secondary DNS: $DNS2" 240 fi 241 fi 242 else 243 echo "DNS: Do not adjust" 244 fi 245 echo "Firewalling: $FIREWALL" 246 echo "" 247 while [ true ] ; do 248 printf "%s" '>>> Accept these settings and adjust configuration files (y/n)? ' 249 read ANS 250 case "ANS" in 251 Y|y|yes|Yes|oui|Oui) 252 ANS=y 253 ;; 254 N|n|no|No|non|Non) 255 ANS=n 256 ;; 257 esac 258 if [ "$ANS" = "y" -o "$ANS" = "n" ] ; then 259 break 260 fi 261 done 262 if [ "$ANS" = "y" ] ; then 263 break 264 fi 265done 266 267# Adjust configuration files. First to $CONFIG 268 269echo "Adjusting $CONFIG" 270 271copy $CONFIG $CONFIG-bak 272if [ "$DNS1" = "server" ] ; then 273 DNSTYPE=SERVER 274 DNS1="" 275 PEERDNS=yes 276else 277 PEERDNS=no 278 if [ "$DNS1" = "" ] ; then 279 DNSTYPE=NOCHANGE 280 else 281 DNSTYPE=SPECIFY 282 fi 283fi 284 285# Where is pppd likely to put its pid? 286if [ -d /var/run ] ; then 287 VARRUN=/var/run 288else 289 VARRUN=${prefix}/etc/ppp 290fi 291 292# Some #$(*& ISP's use a slash in the user name... 293sed -e "s&^USER=.*&USER='$U'&" \ 294 -e "s&^ETH=.*Ð='$E'&" \ 295 -e "s&^PIDFILE=.*&PIDFILE=\"$VARRUN/\$CF_BASE-pppoe.pid\"&" \ 296 -e "s/^FIREWALL=.*/FIREWALL=$FIREWALL/" \ 297 -e "s/^DEMAND=.*/DEMAND=$D/" \ 298 -e "s/^DNSTYPE=.*/DNSTYPE=$DNSTYPE/" \ 299 -e "s/^DNS1=.*/DNS1=$DNS1/" \ 300 -e "s/^DNS2=.*/DNS2=$DNS2/" \ 301 -e "s/^PEERDNS=.*/PEERDNS=$PEERDNS/" \ 302 < $CONFIG-bak > $CONFIG 303 304if [ $? != 0 ] ; then 305 echo "** Error modifying $CONFIG" 306 echo "** Quitting" 307 exit 1 308fi 309 310if [ "$DNS1" != "" ] ; then 311 if [ "$DNS1" != "server" ] ; then 312 echo "Adjusting /etc/resolv.conf" 313 if [ -r /etc/resolv.conf ] ; then 314 grep -s "MADE-BY-RP-PPPOE" /etc/resolv.conf > /dev/null 2>&1 315 if [ "$?" != 0 ] ; then 316 echo " (But first backing it up to /etc/resolv.conf-bak)" 317 copy /etc/resolv.conf /etc/resolv.conf-bak 318 fi 319 fi 320 echo "# MADE-BY-RP-PPPOE" > /etc/resolv.conf 321 echo "nameserver $DNS1" >> /etc/resolv.conf 322 if [ "$DNS2" != "" ] ; then 323 echo "nameserver $DNS2" >> /etc/resolv.conf 324 fi 325 fi 326fi 327 328echo "Adjusting ${prefix}/etc/ppp/pap-secrets and ${prefix}/etc/ppp/chap-secrets" 329if [ -r ${prefix}/etc/ppp/pap-secrets ] ; then 330 echo " (But first backing it up to ${prefix}/etc/ppp/pap-secrets-bak)" 331 copy ${prefix}/etc/ppp/pap-secrets ${prefix}/etc/ppp/pap-secrets-bak 332else 333 cp /dev/null ${prefix}/etc/ppp/pap-secrets-bak 334fi 335if [ -r ${prefix}/etc/ppp/chap-secrets ] ; then 336 echo " (But first backing it up to ${prefix}/etc/ppp/chap-secrets-bak)" 337 copy ${prefix}/etc/ppp/chap-secrets ${prefix}/etc/ppp/chap-secrets-bak 338else 339 cp /dev/null ${prefix}/etc/ppp/chap-secrets-bak 340fi 341 342egrep -v "^$U|^\"$U\"" ${prefix}/etc/ppp/pap-secrets-bak > ${prefix}/etc/ppp/pap-secrets 343echo "\"$U\" * \"$PWD1\"" >> ${prefix}/etc/ppp/pap-secrets 344egrep -v "^$U|^\"$U\"" ${prefix}/etc/ppp/chap-secrets-bak > ${prefix}/etc/ppp/chap-secrets 345echo "\"$U\" * \"$PWD1\"" >> ${prefix}/etc/ppp/chap-secrets 346 347echo "" 348echo "" 349echo "" 350echo "Congratulations, it should be all set up!" 351echo "" 352echo "Type 'pppoe-start' to bring up your PPPoE link and 'pppoe-stop' to bring" 353echo "it down. Type 'pppoe-status' to see the link status." 354exit 0 355