#!/bin/bash -e

pkgname="nagios-plugins-2.4.12"

echo "UPGRADE: Nagios Plugins is being upgraded..."

# Delete the old directory
rm -rf "$pkgname"

# Extract archive
tar -xzf "$pkgname.tar.gz"

# Apply our patches
./apply-patches "$pkgname"

(
	cd "./$pkgname"
	time ./configure
	time make clean
	time make
	time make install
)

# Do a simple sanity check to make sure some key files exist...
for f in /usr/local/nagios/libexec/check_ping ; do
	if [ ! -f "$f" ]; then
		echo "ERROR: Nagios Plugins upgrade appears to have failed - exiting.  Missing file = $f"
		exit 1
	fi
done

# Things are okay
echo "UPGRADE: Nagios Plugins upgraded OK."
