#!/bin/sh
#
# wshaperx                 This script starts or stops a traffic shaper
#
# chkconfig: 345 78 22
# processname: /usr/sbin/wshaperx
# config: /etc/wshaperx.conf
# description: Enables traffic shaping, which may dramatically \
#	       improve the usability of many network connections, \
#	       especially residential broadband. The traffic shaper \
#	       should only be running while the network is up; \
#	       therefore, this service is not appropriate for most \
#	       pppoe and similar systems.
# 
# LIC: GPL
#
### BEGIN INIT INFO
# Provides: wshaperx
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Short-Description: A traffic shaper
# Description: Enables traffic shaping, which may dramatically
#              improve the usability of many network connections,
#              especially residential broadband. The traffic shaper
#              should only be running while the network is up;
#              therefore, this service is not appropriate for most
#              pppoe and similar systems.
### END INIT INFO

NAME=wshaperx
BINPATH=/usr/sbin/${NAME}
CONFIG=/etc/${NAME}.conf

# Source function library (may not be this simple on all distros)
. /etc/rc.d/init.d/functions
 
# Check networking (same comment)
. /etc/sysconfig/network
[ $NETWORKING = "yes" ] || exit 0

# Make sure we have a valid config file.
[ -f $CONFIG ] || exit 0
. $CONFIG
[ "$DOWNLINK" = "" -o "$UPLINK" = "" -o "$DEV" = "" ] && exit 0;

# Now do our thing. Note that /usr/sbin/wshaperx manages the
# lockfile itself, so we don't have to here.
case "$1" in
	start)
		gprintf "Starting traffic shaper"
		$BINPATH start > /dev/null 2>&1
		if [ $? = 0 ] ; then
			echo_success
		else
			echo_failure
		fi
		echo
		;;
	stop)
		gprintf "Shutting down traffic shaper"
		$BINPATH stop > /dev/null 2>&1
		if [ $? = 0 ] ; then
			echo_success
		else
			echo_failure
		fi
		echo
		;;
	restart)
		$0 stop
		$0 start
		;;
	status)
		$BINPATH status
		;;
	reload)
		gprintf "Reloading traffic shaper settings"
		$BINPATH reload > /dev/null 2>&1
		if [ $? = 0 ] ; then
			echo_success
		else
			echo_failure
		fi
		echo
		;;
	*)
		gprintf "Usage: $NAME {start|stop|restart|reload|status}\n"
		exit 1
esac

exit 0
