#!/bin/sh

if [ $# -eq 0 ] ; then
 echo "____________________________________________________________________"
 echo " Herminux ppp connecter & debugger"
 echo " Herminux ppp Syntax:  'ppp' (if modem is given in /etc/ppp/options)"
 echo "                 or:  'ppp modemname'   (without '/dev/' prefix)"
 echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
 exit 0
fi

#check if given modem exists in /dev
if [ $# -eq 1 ] ; then
 if [ -e /dev/$1 ] ; then echo "Modem /dev/$1 found."
 else echo "Modem /dev/$1 not found! Can't connect. Please check if the modem is under another name in /dev.";
      exit 1;
 fi
fi

#initialize pppd debugfile
echo "Herminux ppp connection..." > /var/log/ppplog

#start/restart syslogd
syslogdpid=$( pidof syslogd )
if [ ${#syslogdpid} -eq 0 ] ; then
 syslogd
else
 pkill -HUP -x syslogd
fi

#debug pppd and chat outputs
tailpid=$( pidof tail )
if [ ${#tailpid} -eq 0 ] ; then
 tail -f /var/log/ppplog  &
fi

#connect
if [ $# -eq 1 ] ; then
 pppd /dev/$1
else
 pppd
fi


