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

. /etc/autobench.conf || . functions

WEB_LOCATION="http://www.iozone.org/src/current/iozone3_196.tar"
. $AUTODIR/var/server-repository

wget -q -O $AUTODIR/sources/iozone-latest.tar.gz $SERVER_REPO/sources/iozone-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/iozone-latest.tar.gz $WEB_LOCATION
  if [ $? -ne 0 ]; then
    # Couldn't get the source -- complain
    echo "WARNING: could not download the source for iozone"
    exit 1
  fi
fi

# Uncompress it
rm -rf $AUTODIR/sources/iozone > /dev/null

mkdir iozone
pushd $AUTODIR/sources/iozone > /dev/null
tar zxf iozone-latest.tar.gz
pushd $AUTODIR/sources/iozone/src/current > /dev/null

ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ \
      -e s/sa110/arm/`
case ARCH in
  ia64)
        SUFFIX="-ia64"
        ;;
  ppc*)
        SUFFIX="-powerpc"
        ;;
  s390)
        SUFFIX="-S390"
        ;;
  s390x)
        SUFFIX="-S390X"
        ;;
  sparc)  # ?
        SUFFIX="-sparc"
        ;;
esac
 
# build it...
make linux$SUFFIX
if [ $? -ne 0 ]; then
  echo "ERROR: unable to make iozone compile"
  popd > /dev/null
  popd > /dev/null
  exit 1
fi
popd > /dev/null
popd > /dev/null
