#!/bin/bash
###################################################
# fou4s-bench - Test several SuSE FTP Servers for speed
#
# Copyright (C) 2002 Guenther Sommer <gue@rettung.at>
#
# 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.
#
QUIET=0
if [ "$1" = "-q" ] ; then
	QUIET=1
fi

SUSEVERSION=`cat /etc/SuSE-release | grep ^VERSION`
SUSEVERSION=${SUSEVERSION##VERSION = }
SUSEVERSION=${SUSEVERSION%%-SERVER} # for SLE/Email Server II
ARCH=`cat /etc/SuSE-release | grep ^SuSE | tr 'A-Z' 'a-z'`
ARCH=${ARCH##suse linux*\(}
ARCH=${ARCH%%\)}
SERVERPATH=$ARCH/update/$SUSEVERSION/
if [ "$SUSEVERSION" = "" ]; then
         echo "Cannot determine SuSE-version from /etc/SuSE-release"
         echo "exiting..."
         exit 2
fi

if [ ! -f /etc/suseservers ] ; then
	echo "The file /etc/suseservers was not found. Please run fou4s --server -w to get it"
	exit 1
fi

if [ $QUIET -eq 0 ] ; then
	echo "Note, that only servers from /etc/suseservers will be checked. The server(s) configured in fou4s.conf are not checked right now. If you would like to get this feature, please send me a fixed version of fou4s-benchmark, thanks." | fmt
	echo Detected SuSE $SUSEVERSION
	echo
	echo "Starting benchmark. This can take a while, please be patient..."
fi

function startwget()
{
	wget --output-document=/dev/null -q $server/$SERVERPATH
	if [ $? -ne 0 ] ; then
		continue
	fi
}

#for server in `( cat /etc/suseservers | grep -v "^#"; awk -F = '/^Server=/ {print $2}' </etc/fou4s.conf ) | sort | uniq`; do
#fixme use above?!
for server in `cat /etc/suseservers |grep -v "^#"`; do
   echo `(time -p startwget) 2>&1 \
   >/dev/null| grep real | sed 's/real//g'` "   " $server
done | sort -n
