#!/bin/bash
# This is a freeform script to install a benchmark.
#
. /etc/autobench.conf || . functions

#
# Probably want to fetch a package of some sort first.
#
# You may want to specify a web location as well as sourcing the server repo:
WEB_LOCATION="http://www.coker.com.au/bonnie++/bonnie++-1.03a.tgz"
 . $AUTODIR/var/server-repository
#
# Get it from the server repo first, if it's there
wget -q -O $AUTODIR/sources/bonnie++-latest.tar.gz $SERVER_REPO/sources/bonnie++-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/bonnie++-latest.tar.gz $WEB_LOCATION
  if [ $? -ne 0 ]; then
    # Couldn't get the source -- complain
    echo "WARNING: could not download the source for bonnie++"
    exit 1
  fi
fi

#
# Next you probably want to uncompress the package, and then build it
#
pushd $AUTODIR/sources > /dev/null
rm -rf bonnie++ 2> /dev/null
DST_DIR=`tar ztf bonnie++-latest.tar.gz | head -n 1`
tar zxf bonnie++-latest.tar.gz
ln -sf $DST_DIR bonnie++ 
#
# build it...
pushd bonnie++ > /dev/null
./configure
if [ $? -ne 0 ]; then
  echo "WARNING: unable to configure bonnie++"
  exit 1
fi
make
if [ $? -ne 0 ]; then
  echo "WARNING: unable to make bonnie++"
  exit 1
fi
popd > /dev/null
popd > /dev/null
