#!/bin/sh
#
#	$Id: ifup-ppp,v 1.13 2000/06/12 08:38:15 waszi Exp $
#
# ifup-ppp script for pppd-2.3.5 (with persist & demand options) ver 0.2
# Grzegorz Stanislawski <stangrze@open.net.pl>
# Features:
#  - since persist option is included to pppd it''s no need to do werid loops
#    ifup-ppp script. This also makes your logfile grow slower when Your link
#    is down.
#  - chat-ppp? file with script for chat is now parsed by shell, so You can
#    include in it shell variables (for example $PHONE, $USERNAME)
#    You can define any variable in ifcfg-ppp? file and use it in chat-ppp?
#    You only have to add it's name into DATAFORCHAT variable
#    Note, that chat-ppp file is now parsed by shell, so you have to escape
#    with "\" all shell special characters like \$;:)(& etc.
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin

# ifup-post for PPP is handled through /etc/ppp/ip-up

CONFIG=$1
. /etc/sysconfig/network
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network-scripts/.functions

source_config
[ -z "$HOLDOFF" ] && HOLDOFF=30

if [ "$2" = "boot" ] && is_no "${ONBOOT}"; then
  exit
fi
[ -x /usr/sbin/pppd ] || {
  echo "/usr/sbin/pppd does not exist or is not executable"
  echo "ifup-ppp for $DEVICE exiting"
    logger -p daemon.info -t ifup-ppp \
    "/usr/sbin/pppd does not exist or is not executable for $DEVICE"
  exit 1
}

opts="lock"
if is_yes "${PERSIST}"; then
  if [ -z "${MAXFAIL}" ]; then 
  MAXFAIL="0"
  fi
  opts="$opts persist holdoff $HOLDOFF maxfail $MAXFAIL"
fi
if is_yes "${DEMAND}"; then
  if [ -z "${IDLE}" ]; then
  IDLE="0"
  fi
  opts="$opts demand idle ${IDLE}"
fi
if is_yes "${HARDFLOWCTL}"; then
  opts="$opts modem crtscts"
fi
if is_yes "${ESCAPECHARS}"; then
  opts="$opts asyncmap FFFFFFFF"
elif [ "${ESCAPECHARS}" = no ] ; then
  opts="$opts asyncmap 00000000"
fi
if is_yes "${DEFROUTE}" = yes; then
  opts="$opts defaultroute"
fi
if [ -n "${MRU}" ] ; then
  opts="$opts mru ${MRU}"
fi
if [ -n "${MTU}" ] ; then
  opts="$opts mtu ${MTU}"
fi
if [ -n "${IPADDR}${REMIP}" ] ; then
  # if either IP address is set, the following will work.
  opts="$opts ${IPADDR}:${REMIP}"
fi
if [ -n "${PAPNAME}" ] ; then
  opts="$opts name ${PAPNAME}"
fi
if [ -n "${REMOTENAME}" ] ; then
  opts="$opts remotename ${REMOTENAME}"
fi
if is_yes "${DEBUG}"; then
  opts="$opts debug"
  chatdbg="-v"
fi
case "${AUTH}" in
  yes) opts="$opts auth"
  ;;
  no) opts="$opts noauth"
  ;;
  *)
  ;;
esac
if [ -n "${REPORTFILE}"  ] ; then
  chatrpt="-r ${REPORTFILE}"
fi

(logger -p daemon.info -t ifup-ppp \
    "pppd started for $DEVICE on $MODEMPORT at $LINESPEED" &)&
if [ -n "${CHATSCRIPT}"  ] ; then
  export chatdbg chatrpt CHATSCRIPT
  export $DATAFORCHAT
  /usr/sbin/pppd $opts $MODEMPORT $LINESPEED \
    connect 'eval /usr/sbin/chat $chatdbg $chatrpt \
    `grep -v ^# ${CHATSCRIPT}`' \
    linkname "${DEVICE}" ipparam "${CONFIG}" \
    ${PPPOPTIONS}
else
  /usr/sbin/pppd $opts $MODEMPORT $LINESPEED \
    linkname "${DEVICE}" ipparam "${CONFIG}" \
    ${PPPOPTIONS}
fi

