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

. /etc/autobench.conf || . functions

WEB_LOCATION="ftp://ftp.bitmover.com/lmbench/lmbench-2.0.4.tgz"
. $AUTODIR/var/server-repository

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

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

DST_DIR=`tar ztf lmbench-latest.tar.gz | head -n 1`
tar zxf lmbench-latest.tar.gz
ln -sf $DST_DIR lmbench 

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