#! /bin/sh
#
# Name: ppp 
# Date: 2003-06-26 15:40
# Author: MontaVista Software, Inc. <source@mvista.com>
# Copyright: Copyright 1999-2003 MontaVista Software, Inc.
# License: 2003 (c) MontaVista Software, Inc. This file is licensed
#          under the terms of the GNU General Public License version 2.
#          This program is licensed "as is" without any warranty of any
#          kind, whether express or implied.
#
# Copyright 2002, 2003, 2004 Sony Corporation
# Copyright 2002, 2003, 2004 Matsushita Electric Industrial Co., Ltd.
#
### BEGIN INIT INFO
# Required-Start: 
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start or stop PPP link.
# Description: start or stop PPP link.
### END INIT INFO 
# chkconfig: S 41 0

# Init script information
INIT_NAME=pppd
DESC="PPP link"

# Individual Daemon information
DAEMON1=/usr/sbin/pppd
ARGS1="call provider"
BASENAME1=${DAEMON1##*/}
DAEMON2=/etc/ppp/ppp_on_boot
DAEMON3=/usr/bin/poff
ARGS3="provider"

# Load init script configuration
[ -f /etc/default/$INIT_NAME ] && . /etc/default/$INIT_NAME

# Source the init script functions
. /etc/init.d/init-functions

# Verify daemons are installed
[ "$1" = "status" ] && NFOUND=4 || NFOUND=5
test -f $DAEMON1 -a -f $DAEMON2 -a -f $DAEMON3 || exit $NFOUND

[ -x $DAEMON2 ] && RUNFILE=1

start() {
	local RET ERROR=

	log_status_msg "Starting up $DESC: " -n
	log_status_msg "$BASENAME1" -n
	[ "$RUNFILE" = "1" ] && $DAEMON2 || start_daemon $DAEMON1 $ARGS1
	RET=$?
	if [ $RET -eq 0 ]; then
		log_success_msg "done. " 
      else
		log_failure_msg " failed ($RET: $ERROR)."
		return 1
      fi
	
	log_status_msg ""
	return 0
}

stop () {
	local RET ERROR=

	log_status_msg "Stutting down $DESC: " -n
	log_status_msg "$BASENAME1" -n
	[ "$RUNFILE" = "1" ] && $DAEMON3 || $DAEMON3 $ARGS3
	RET=$?
	if [ $RET -eq 0 ]; then
		log_success_msg "done. " 
      else
		log_failure_msg "failed ($RET: $ERROR). " -n
		return 1
      fi

	log_status_msg ""
	return 0
}

restart() {
	local RET

	log_status_msg "Restarting $DESC..."
	$DAEMON3 -r
	RET=$?

	return $RET
}

tryrestart() {
	local RET

	pidstatus $BASENAME
	RET=$?
	if [ $RET -eq 0 ]; then
		restart
		RET=$?
    else                  
		RET=7
    fi

	return $RET
}

#
# if the service does not support reload return code 3 should
# be the result...
#
reload() {
	local RET

	log_status_msg "Reloading $DESC configuration..." -n
	# killproc $BASENAME -HUP
	#
	# repeat as necessary...
	#
	log_success_msg "done."

	return 0
}

forcereload() {
	local RET

	reload
	RET=$?
	if [ $RET -ne 0 ]; then
		restart
		RET=$?
	fi
	
	return $RET
}

status() {
	local RET
	
	printstatus $BASENAME
	RET=$?

	return $RET
}

#
# Everything after this should be the same for all init scripts
#
# See the policy manual for information on actions and return codes.
#

parse() {
	case "$1" in
		start)
			start
			return $?
			;;
		stop)
			stop
			return $?
			;;
		restart | force-reload)
			restart
			return $?
			;;
		try-restart)
			tryrestart
			return $?
			;;
		reload)
			reload
			return $?
			;;
		status)
			status
			return $?
    ;;
  *)
			echo "Usage: $INIT_NAME " \
			"{start|stop|restart|try-restart|reload|" \
			"force-reload|status}" >&2
    ;;
	esac
	
	return 1
}

parse $@

