File: //usr/sbin/pppoe-connect
#!/bin/sh
# ../scripts/pppoe-connect. Generated from pppoe-connect.in by configure.
#***********************************************************************
#
# pppoe-connect
#
# Shell script to connect to a PPPoE provider
#
# Copyright (C) 2000 Roaring Penguin Software Inc.
#
# $Id$
#
# This file may be distributed under the terms of the GNU General
# Public License.
#
# LIC: GPL
#
# Usage: pppoe-connect [config_file]
# pppoe-connect interface user [config_file]
# Second form overrides USER and ETH from config file.
# If config_file is omitted, defaults to /etc//ppp/pppoe.conf
#
#***********************************************************************
# From AUTOCONF
prefix=/usr
exec_prefix=${prefix}
localstatedir=/var
# Paths to programs
IFCONFIG=/sbin/ifconfig
PPPD=/usr/sbin/pppd
SETSID=/bin/setsid
LOGGER="/usr/bin/logger -t `basename $0`"
SYNOGETKEYVALUE="/usr/syno/bin/synogetkeyvalue"
CONFIG_GENERATOR="/etc/ppp/pppoe-generate-config.py"
# Set to "C" locale so we can parse messages from commands
LANG=C
export LANG
# Must be root
if [ -x "/bin/id" -a "`/bin/id -u`" != 0 ] ; then
echo "$0: You must be root to run this script" >& 2
exit 1
fi
if test "$SETSID" != "" -a ! -x "$SETSID"; then
SETSID=""
fi
# Sort out command-line arguments
CONFIG=/etc/ppp/pppoe.conf
case "$#" in
1)
CONFIG="$1"
;;
3)
CONFIG="$3"
;;
esac
if test ! -f "$CONFIG" -o ! -r "$CONFIG" ; then
echo "$0: Cannot read configuration file '$CONFIG'" >& 2
exit 1
fi
# Check for command-line overriding of ETH and USER
case "$#" in
2|3)
ETH="$1"
USER="$2"
;;
esac
OVERRIDE=""
# Check that config file is sane
if test -n "$USER"; then
OVERRIDE="${OVERRIDE} -r USER \"$USER\""
fi
if test -n "$ETH"; then
OVERRIDE="${OVERRIDE} -r ETH \"$ETH\""
fi
GENEREATED_CONFIG="$CONFIG.run"
if ! $CONFIG_GENERATOR -i $CONFIG -o $GENEREATED_CONFIG $OVERRIDE; then
echo "Failed to generate config for $CONFIG" >& 2
exit 1
fi
# fixed value. it can't be changed by user.
eval CF_BASE="$($SYNOGETKEYVALUE $CONFIG CF_BASE)"
eval PIDFILE="$($SYNOGETKEYVALUE $CONFIG PIDFILE)"
RETRY_ON_FAILURE="$($SYNOGETKEYVALUE $CONFIG RETRY_ON_FAILURE)"
# MTU of Ethernet card attached to modem MUST be 1500. This apparently
# fails on some *BSD's, so we'll only do it under Linux
if test `uname -s` = Linux ; then
$IFCONFIG $ETH up
EXISTING_MTU=`$IFCONFIG $ETH 2> /dev/null | grep MTU: | sed -e 's/.*MTU://' | sed -e 's/[^0-9].*//'`
if test "$EXISTING_MTU" = "" -o "$EXISTING_MTU" -lt 1500 ; then
$IFCONFIG $ETH mtu 1500
fi
fi
echo $$ > $PIDFILE
while [ true ] ; do
while [ "0" = `cat /sys/class/net/${ETH}/carrier` ] ; do
# No carrier
sleep 5
done
$SETSID $PPPD file "$GENEREATED_CONFIG" &
echo "$!" > "$PIDFILE.pppd"
wait $!
echo $? > /tmp/pppoe-connect.$$.error
if test "$RETRY_ON_FAILURE" = "no" ; then
exit
fi
# Run /etc/ppp/pppoe-lost if it exists
test -x /etc/ppp/pppoe-lost && /etc/ppp/pppoe-lost
# Re-establish the connection
$LOGGER -p daemon.notice \
"PPPoE connection lost; attempting re-connection."
# Wait a bit in case a problem causes tons of log messages :-)
sleep 5
done