#!/bin/bash
# This is the script to install the tio program
#

. /etc/autobench.conf || . functions

WEB_LOCATION="http://easynews.dl.sourceforge.net/sourceforge/tiobench/tiobench-0.3.3.tar.gz"
WEB_LOCATION2="ftp://ausgsa.austin.ibm.com/projects/l/ltcperformance/2003benchmarks/tiobench/tiobench-latest.tar.gz"
. $AUTODIR/var/server-repository

wget -q -O $AUTODIR/sources/io-latest.tar.gz $SERVER_REPO/sources/tiobench-latest.tar.gz
if [ $? -ne 0 ]; then
  # Didn't find it on the repo, try the web location
  echo "Fetching from the network"
  wget -q -O $AUTODIR/sources/tio-latest.tar.gz $WEB_LOCATION
  if [ $? -ne 0 ]; then
    wget -q -O $AUTODIR/sources/tio-latest.tar.gz $WEB_LOCATION2
    if [ $? -ne 0 ]; then
		# Couldn't get the source -- complain
		echo "WARNING: could not download the source for tio"
		exit 1
    fi
  fi
fi


# Uncompress it
pushd $AUTODIR/sources > /dev/null
rm -rf tiobench 2> /dev/null

DST_DIR=`dirname $(tar ztf tio-latest.tar.gz | head -n 1)`
tar zxf tio-latest.tar.gz
ln -sf $DST_DIR tiobench

# build it...
popd > /dev/null
pushd $AUTODIR/sources/tiobench > /dev/null
export DEFINES=-DLARGEFILES
make
if [ $? -ne 0 ]; then
  echo "ERROR: unable to make tio"
  popd > /dev/null
  exit 1
fi
popd > /dev/null


