#!/bin/sh

INSTALL_DIR=`pwd`
SOFTWARE=rrdtool
VERSION=1.2.11

function cleanupandexit {
  echo "Installation failed.  Look above for errors."
  cd $INSTALL_DIR
  rm -rf ${SOFTWARE}-${VERSION}
  exit 1
}

tar xzf ${SOFTWARE}-${VERSION}.tar.gz
cd $INSTALL_DIR/${SOFTWARE}-${VERSION}

./configure --prefix=/opt/${SOFTWARE}/current || cleanupandexit

make || cleanupandexit
make install || cleanupandexit

cd /opt/${SOFTWARE}
mv current ${SOFTWARE}-${VERSION}
ln -s ${SOFTWARE}-${VERSION} current

ln -s /opt/${SOFTWARE}/current/bin/* /usr/local/bin/

echo ""
echo "RRDTool Installation Complete"

