#!/bin/bash

# changes the bw limit for thinc. Very specific to shape-create, one
# day we'll make it generic
# pass in the new bw (see shape-create for details)

DEFDEV=eth0

TEMP=`getopt -o d: -n '$0' -- "$@"`
if [ $? -ne 0 ]; then
	echo "usage: $0 [-d dev] bw"
	exit 1
fi

eval set -- "$TEMP"

DEV=""

while true; do
	case "$1" in
		-d) DEV=$2; echo "using device $DEV"; shift 2;;
		--) shift; break;;
		*)  echo "Internal error. Help, i don't know what to do!!!"; 
		   exit 1;;
	esac
done

if [ $# -ne 1 ]; then
	echo "You did not specify the new bandwidth!!"
	echo "Usage: $0 [-p port] [-d device] bw"
	exit 1
fi

BW=$1

if [ "$DEV" == "" ]; then
	DEV=$DEFDEV
	echo "using default device $DEV"
fi

echo -n "Changing bandwidth limit in device $DEV to $BW..."
tc class change dev $DEV parent 1: classid 1:1 htb rate $BW
if [ $? -ne 0 ]; then
	echo ""
	echo "Error: I apologize. I could not change traffic shaping on device $DEV :("
	exit 1
else
	echo "done."
fi
