#!/bin/sh DAEMON=ppp DAEMON_LONG_NAME=PPP . /etc/init.d/modlibrc disconnect() { killall -9 ppp_dialer 2>/dev/null killall pppd 2>/dev/null sleep 2 cnt=17 while [ -n "$(pidof pppd)" ] && [ $cnt -gt 0 ]; do killall -9 pppd 2>/dev/null let cnt-- sleep 1 done [ -z "$PPP_LOGFILE" ] || echo -e "TERMINATED\n$(date "+%Y-%m-%d %H:%M,%S")\n##\n" >> $PPP_LOGFILE [ -e "$PPP_SCRIPT_HUP" ] && . $PPP_SCRIPT_HUP echo "#" > /etc/ppp/resolv.conf [ -n "$(pidof pppd)" ] && return 1 return 0 } start() { echo -n 'Starting $DAEMON_LONG_NAME ... ' if [ -n "$(pidof ppp_observer ppp_dialer pppd)" ]; then echo 'already running.' exit 1 fi modprobe option modprobe ppp_generic modprobe ppp_async modprobe ppp-deflate modprobe slhc start-stop-daemon -n ppp_observer -a /mod/etc/default.ppp/ppp_observer -b -q -S [ -n "$PPP_DIAGTTY" ] && start-stop-daemon -n ppp_logger -a /mod/etc/default.ppp/ppp_logger -b -q -S echo 'done.' } stop() { echo -n 'Stopping $DAEMON_LONG_NAME ... ' if [ -z "$(pidof ppp_observer ppp_dialer pppd)" ]; then echo 'not running.' return 1 fi killall -9 ppp_observer 2>/dev/null killall -9 ppp_logger 2>/dev/null kill $(cat /var/run/ppp_logger.pid 2>/dev/null) 2>/dev/null rm -rf /tmp/ppp_logger.tmp 2>/dev/null disconnect if [ $? -ne 0 ]; then echo 'failed.' return 1 else echo 'done.' fi } case $1 in ""|load) [ ! -d "/mod/etc/ppp" ] && mkdir -p /mod/etc/ppp [ ! -d "/tmp/flash/ppp/peers" ] && mkdir -p /tmp/flash/ppp/peers [ ! -e "/mod/etc/ppp/peers" ] && ln -s /tmp/flash/ppp/peers /mod/etc/ppp/peers [ ! -e "/tmp/flash/ppp/peers/dun" ] && /mod/etc/default.${DAEMON}/peers_options > /tmp/flash/ppp/peers/dun [ ! -e "/tmp/flash/ppp/peers/dun.chat" ] && /mod/etc/default.${DAEMON}/peers_chat > /tmp/flash/ppp/peers/dun.chat modreg cgi 'ppp' "$DAEMON_LONG_NAME" modreg daemon $DAEMON modreg status ppp "$DAEMON_LONG_NAME" ppplog modreg file ppp 'peers_options' 'PEERS: options' 0 "peers_options" modreg file ppp 'peers_chat' 'PEERS: chat' 0 "peers_chat" modlib_start $PPP_ENABLED ;; unload) modunreg cgi 'ppp' modunreg daemon $DAEMON modunreg status ppp ppplog modunreg file ppp stop ;; start) start ;; stop) stop ;; restart) stop sleep 2 start ;; status) if [ -n "$(pidof ppp_observer ppp_dialer pppd)" ]; then echo 'running' else echo 'stopped' fi ;; disconnect) disconnect exit $? ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0