#!/bin/bash
# $Id: eu_init,v 1.15 2005/01/16 22:04:34 Tux Exp $

# Copyright (C) 2003-2005 Olivier Borowski
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

# Goal :
#	Startup script for eagle-usb ADSL modems.
# Params :
#	$1 = start/stop/status/restart/force-reload/reload/{none}
# Params set by setvars :
#	$DISTRIB

#================== Mandrake, RedHat... ==================
# chkconfig: 235 99 01
# description: Launch ADSL connexion
#========================= SuSE ==========================
### BEGIN INIT INFO
# Provides:       eagle-usb
# Required-Start: syslog
# Required-Stop:
# Default-Start:  2 3 5
# Default-Stop:
# Description:   Launch ADSL connexion
### END INIT INFO
#=========================================================

# the following line will be replaced by the absolute path of setvars
exit 123
PARAM="$1"
PATH_SAV="$PATH"

if [ "$DISTRIB" = "Slackware" ] ; then
	echo_failure() { return 1 ; }
	echo_success() { return 0 ; }
	CMDECHO="echo -en"
	# assume "no param" = "start"
	test -z "$PARAM" && PARAM="start"
elif [ -f /etc/rc.d/init.d/functions ] ; then
	# Source function library.
	. /etc/rc.d/init.d/functions
	CMDECHO="echo -en"
elif [ -e /etc/rc.status ] ; then
	. /etc/rc.status
	echo_failure() {
		rc_failed 1
		rc_status -v
		return 1
	}
	echo_success() {
		rc_status -v
		return 0
	}
	CMDECHO="echo -en"
else
	echo_failure() {
		echo "[FAILED]"
		return 1
	}
	echo_success() {
		echo "[  OK  ]"
		return 0
	}
	CMDECHO="doInUtf8 echo -e"
fi
PATH="$PATH_SAV"

# See how we were called.
case "$PARAM" in
	start)
		$CMDECHO $START_SERVICE_MSG
		mkdir -p `dirname $SYSCONF_FILE`
		touch $SYSCONF_FILE
		if [ $ASYNCHRONOUS_START -eq 0 ] ; then
			if fctStartAdsl ; then
				echo_success
			else
				echo_failure
			fi
		else
			fctStartAdsl &
			echo_success
			#if fctStartAdsl ; then
			#	echo_success
			#else
			#	echo_failure
			#fi &
		fi
		echo
		#$CMDECHO
		;;
	stop)
		$CMDECHO $STOP_SERVICE_MSG
		rm -f $SYSCONF_FILE
		fctStopAdsl
		echo_success
		echo
		#$CMDECHO
		;;
	status)
		eaglediag
		#if [ "$DISTRIB" = "Fedora" ] && [ "$PPPOX" != "none" ] ; then
		#	status pppd
		#fi
		;;
	restart|force-reload)
		$0 stop
		sleep 1
		$0 start
		;;
	reload)
		$CMDECHO $RELOAD_SERVICE_MSG
		$0 start
		echo
		#$CMDECHO
		;;
	*)
		$CMDECHO $USAGE_SERVICE_MSG
		exit 1
esac

exit 0

#***************************************************************************
# $Log: eu_init,v $
# Revision 1.15  2005/01/16 22:04:34  Tux
# - add license header
#
# Revision 1.14  2005/01/04 21:14:05  Tux
# - switch strings to utf-8
#
# Revision 1.13  2004/11/21 15:29:41  Tux
# - replaced == with -eq
#
# Revision 1.12  2004/09/28 19:43:46  Tux
# - prevent PATH from being modified by "/etc/rc.d/init.d/functions" on Aurox
#
# Revision 1.11  2004/09/23 20:37:59  Tux
# - add support for slackware (we do not use rc.eagle-usb anymore)
#
# Revision 1.10  2004/09/16 20:48:24  Tux
# - removed useless $SYSCONF_DIR variable
#
# Revision 1.9  2004/09/15 19:25:03  Tux
# - make sure that parent folders of the lock file exist
#
# Revision 1.8  2004/09/14 20:59:16  Tux
# *** empty log message ***
#
# Revision 1.7  2004/09/14 20:42:25  Tux
# - useless to create lock file's parents folders (should be done before)
# - echo_success/echo_failure sould not be called asynchronously
#
# Revision 1.6  2004/07/16 21:52:51  Tux
# - use $SYSCONF_FILE
# - asynchronous start should display [OK] / [Error] too
#
# Revision 1.5  2004/05/30 01:55:21  Tux
# - "splash_late" service does not exist on SuSE9.1, using "syslog" instead
#
# Revision 1.4  2004/05/23 19:59:10  Tux
# - "force-reload" now acts as "restart"
#
# Revision 1.3  2004/04/21 20:02:27  Tux
# *** empty log message ***
#
#***************************************************************************/
