#!/bin/bash -e

. ../xi-sys.cfg

echo "Installing Subcomponents..."

mkdir -p /usr/local/nagios/etc

for pkg in nagioscore influx_perfdata nagiosplugins ndo pnp nrpe nsca nrdp ccm extraplugins webinject sshterminal phantomjs chromium mrtg oauth2 mod_security nagios-mod-gearman; do
	# Check installer return code
	if (cd "./$pkg" && ./install  ); then
		echo "Subcomponent '$pkg' installed OK" 
	else
		echo "ERROR: Subcomponent '$pkg' installation failed - exiting."  
		exit 1
	fi
done

# Post-install fixes
chown -R "$nagiosuser:$nagiosgroup" /usr/local/nagios/var/spool

