#!/bin/sh
#
#
####################################################################
# Fusion Producer NEB module install
####################################################################
# Copyright (c) 2026 Nagios Enterprises, LLC. All rights reserved.
####################################################################
#
#


pkgname=`grep pkgname= ../nagioscore/install  | cut -f2 -d"="`

# printf "\n pkgname == $pkgname \n"

if [ ! -d "../nagioscore/$pkgname/include" ]; then
    echo "Error: ../nagioscore/$pkgname/include directory not found"
    exit 0
else
	cp -R ../nagioscore/"$pkgname"/include .
fi

if [ ! -d "../nagioscore/$pkgname/lib" ]; then
    echo "Error: ../nagioscore/nagios/lib directory not found"
    exit 0
else
    cp -R ../nagioscore/"$pkgname"/lib .
fi


cd module || { echo "Error: module directory not found"; exit 0; }

make
if [ $? -ne 0 ]; then
    echo "Error: make command failed"
    exit 0
fi

make install
if [ $? -ne 0 ]; then
    echo "Error: make install command failed"
    exit 0
fi

make clean
if [ $? -ne 0 ]; then
    echo "Error: make clean command failed"
    exit 0
fi

cd ..

if [ -d "/usr/local/nagiosxi/scripts" ]; then
    cp setup_fusion.sh /usr/local/nagiosxi/scripts/
    if [ $? -ne 0 ]; then
        echo "Error: Failed to copy setup_fusion.sh to /usr/local/nagiosxi/scripts/"
    else
    	echo "Copied setup_fusion.sh to /usr/local/nagiosxi/scripts/"
    fi
fi
