#!/bin/bash -e
# this script will run all of the other tests
# any error will cause the entire build to fail
# we use the workspace var to change directories relative to our jenkins location

if [[ $# -eq 0 ]]; then
	echo "More arguments, please"
	exit 1
fi

WORKSPACE="$1"

# function for printing steps so we can determine where we are at in failed output (console gets messy)
print_step() {
	echo -e "**********************************************************************"
	echo -e "* $@"
	echo -e "**********************************************************************\n"
}

# basic tests for now
ssh 192.168.7.32 "userdel nagios && groupdel nagios && rm -rf /usr/local/nagiosfusion && rm -rf /var/spool/mail/nagios && rm -rf /home/nagios && rm -rf /var/lib/mysql/fusion && rm -rf /tmp/nagiosfusion" ||:
ssh 192.168.7.32 "wget -q https://assets.nagios.com/downloads/nagiosfusion/revision/get_latest_rev.php -O /tmp/fusion-latest.tar.gz && cd /tmp && tar xf fusion-latest.tar.gz && cd /tmp/nagiosfusion && ./install -n"