#!/bin/bash . $(dirname $0)/functions option account standard_option option mode standard_option pppoe option device standard_option option vpi standard_option option vci standard_option option mtu standard_option 1492 option mru standard_option 1492 option defaultroute boolean_option 1 option statefile standard_option /var/state/adsl option pidfile reserved_option /var/run/adsl.pid option plugindir standard_option /usr/lib/pppd/%%PKGVER%% option unit standard_option function do_status { if [ ! -r "$pidfile" ]; then echo "adsl status = down (no pid file)" exit 1 fi pid=$(<"$pidfile") if [ -n "$pid" -a -L /proc/$pid/cwd ]; then adsl=disabled ; pppd="not running" [ -e "$opt_statefile" ] && adsl=$(<"$opt_statefile") [ -n "$(pidof pppd)" ] && pppd="running" echo "adsl status = running,$adsl,pppd $pppd" return 0 else echo "adsl status = down (no process)" exit 1 fi } function do_check { do_status "$@" } function do_stop { echo "disabled" >$opt_statefile #pids=$(pidof -o $$ adsl) pids= [ -e "$pidfile" ] && pids=$(<"$pidfile") if [ -n "$pids" ]; then kill $pids >/dev/null 2>&1 fi killall pppd >/dev/null 2>&1 killall -CONT pppd >/dev/null 2>&1 retry=0 while [ $retry -lt 3 ] && pidof pppd >/dev/null; do usleep $[ 100000 << $retry ] retry=$[ $retry + 1 ] done killall -9 pppd >/dev/null 2>&1 killall -CONT pppd >/dev/null 2>&1 rm -f "$pidfile" return 0 } function do_help { echo "Usage: ${0##*/} " return 0 } function do_start { local PPPOAPLG="${opt_plugindir}/pppoatm.so" local PPPOEPLG="${opt_plugindir}/pppoe.so" if [ "$opt_mode" == "pppoe" ]; then if [ ! -x "$PPPOEPLG" ]; then echo "FATAL: PPPoE plugin '$PPPOEPLG' missing" exit 1 fi if [ -z "$opt_device" ]; then echo "FATAL: in PPPoE mode, you need to name the physical device using option 'device'" exit 1 fi elif [ "$opt_mode" == "pppoa" ]; then if [ ! -x "$PPPOAPLG" ]; then echo "FATAL: PPPoA plugin '$PPPOAPLG' missing" exit 1 fi if [ -z "$opt_vpi" -o -z "$opt_vci" ]; then echo "FATAL: in PPPoA mode, you need to name VPI and VCI using options 'vpi' and 'vci'" exit 1 fi else echo "FATAL: unknown mode '${opt_mode}'. Please specify either 'pppoa' or 'pppoe' using option 'mode'." exit 1 fi if [ -z "$opt_account" ]; then echo "FATAL: provider account must be referenced using option 'account'" exit 1 fi #pids=$(pidof -o $$ adsl) pids= [ -e "$pidfile" ] && pids=$(<"$pidfile") if [ -n "$pids" ]; then echo "ADSL already started (pid $pids)" exit 0 fi exec &0 2>&0 echo "enabled" >$opt_statefile ( while : ; do if [ -e "$opt_statefile" ]; then state="$(<"$opt_statefile")" else state="" fi if [ $state = "enabled" ]; then case $opt_mode in pppoa) /usr/sbin/pppd plugin $PPPOAPLG ${opt_vpi}.${opt_vci} \ noipdefault noauth default-asyncmap ${opt_defaultroute:+defaultroute} \ mtu $opt_mtu mru $opt_mru noaccomp noccp nobsdcomp nodeflate nopcomp \ novj novjccomp user $opt_account lcp-echo-interval 20 lcp-echo-failure 3 \ persist nodetach holdoff 0 ${opt_unit:+unit $opt_unit} /dev/null 2>&1 ;; pppoe) /usr/sbin/pppd plugin $PPPOEPLG $opt_device \ noipdefault noauth default-asyncmap ${opt_defaultroute:+defaultroute} \ mtu $opt_mtu mru $opt_mru noaccomp noccp nobsdcomp nodeflate nopcomp \ novj novjccomp user $opt_account lcp-echo-interval 20 lcp-echo-failure 3 \ persist nodetach holdoff 0 ${opt_unit:+unit $opt_unit} /dev/null 2>&1 ;; esac elif [ $state = "disabled" ]; then killall pppd >/dev/null 2>&1 killall -CONT pppd >/dev/null 2>&1 retry=0 while [ $retry -lt 3 ] && pidof pppd >/dev/null; do usleep $[ 100000 << $retry ] retry=$[ $retry + 1 ] done killall -9 pppd >/dev/null 2>&1 killall -CONT pppd >/dev/null 2>&1 fi sleep 1 done rm -f "$pidfile" ) & echo $! >"$pidfile" disown return 0 } load_config