#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin

if [ "$1" != daemon ] ; then
  $0 daemon $*&
  exit 0
fi

shift

. $1

if [ "foo$2" = "fooboot" -a ${ONBOOT} = "no" ]
then
	exit
fi

[ -x /usr/sbin/dip ] || {
  echo "/usr/sbin/dip does not exist or is not executable"
  echo "ifup-sl for $DEVICE exiting"
  logger -p daemon.info -t ifup-sl \
    "/usr/sbin/dip does not exist or is not executable for $DEVICE"
  exit 1
}

[ -f /etc/sysconfig/network-scripts/dip-$DEVICE ] || {
  echo "/etc/sysconfig/network-scripts/dip-$DEVICE does not exist"
  echo "ifup-sl for $DEVICE exiting"
  logger -p daemon.info -t ifup-sl \
    "/etc/sysconfig/network-scripts/dip-$DEVICE does not exist for $DEVICE"
  exit 1
}

echo $$ > /var/run/ifup-sl-$DEVICE.pid
while : ; do
  (logger -p daemon.info -t ifup-sl \
    "dip started for $DEVICE on $MODEMPORT at $LINESPEED" &)&
  /usr/sbin/dip /etc/sysconfig/network-scripts/dip-$DEVICE
  if [ "$PERSIST" != "yes" ] ; then
    exit 0
  fi
  # FIXME: tunable parameter
  sleep 30 || {
    # sleep was killed
    exit 0
  }
done

