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

. /etc/autobench.conf || . functions

WEB_LOCATION="http://voxel.dl.sourceforge.net/sourceforge/sysbench/sysbench-0.3.0.tar.gz"
. $AUTODIR/var/server-repository

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


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

DST_DIR=$(tar ztf sysbench-latest.tar.gz | head -n 1)
tar zxf sysbench-latest.tar.gz
ln -sf $DST_DIR sysbench

# build it...
popd > /dev/null
pushd $AUTODIR/sources/sysbench > /dev/null
./configure --without-mysql
make
if [ $? -ne 0 ]; then
  echo "ERROR: unable to make sysbench"
  popd > /dev/null
  exit 1
fi
popd > /dev/null


