#!/bin/bash
VER='0.0.1'
##############################################
# Siege Benchmark installer
# by eva2000 vbtechsupport.com
# code based on centminmod.com siege bench installer
##############################################
# Seiege Benchmark http://www.joedog.org/siege-home/
# Manual http://www.joedog.org/siege-manual
# FAQ http://www.joedog.org/siege-faq
##############################################
SRCDIR='/usr/local/src'

if [ -f /proc/user_beancounters ]; then
CPUS='1'
MAKETHREADS=" -j$CPUS"
else
# speed up make
CPUS=`cat "/proc/cpuinfo" | grep "processor"|wc -l`
MAKETHREADS=" -j$CPUS"
fi

##############################################
echo ""

read -p "Install Siege Benchmark script ? [y/n] " key

if [[ "$key" = [yY] ]];
then
    echo "*************************************************"
    echo "* Installing Siege Benchmark... "
    echo "*************************************************"
    echo "Installing..."

    cd $SRCDIR

    if [ -s siege-latest.tar.gz ]; then
        echo "siege-latest Archive found, skipping download..."
    else
        wget -c http://www.joedog.org/pub/siege/siege-latest.tar.gz --tries=3
    fi

    if [ -s sproxy-latest.tar.gz ]; then
        echo "sproxy-latest Archive found, skipping download..."
    else
        wget -c http://www.joedog.org/pub/sproxy/sproxy-latest.tar.gz --tries=3
    fi

    tar -xzf siege-latest.tar.gz
    cd siege-2.7*
    ./configure
    make$MAKETHREADS
    make install
    mkdir /usr/local/var/

    sed -i 's/# failures =/failures = 2048/g' /usr/local/etc/siegerc

    cd $SRCDIR

    tar -xzf sproxy-latest.tar.gz
    cd sproxy-1.02
    ./configure
    make$MAKETHREADS
    make install

    echo "*************************************************"
    echo "* Siege Benchmark installed "
    echo "*************************************************"

echo ""
echo "siege -v"
siege -v

fi
