#!/bin/bash -e

. ../../xi-sys.cfg

pkgversion=1.0.1
pkgname="nagios-mod-gearman-${pkgversion}"

if [ "$distro" == "Debian" ] && [ "$ver" -eq 11 ]; then
    apt install -y "./debs/11/nagios-mod-gearman-doc_${pkgversion}_all.deb"
    apt install -y "./debs/11/nagios-mod-gearman-module_${pkgversion}_amd64.deb"
    apt install -y "./debs/11/nagios-mod-gearman-tools_${pkgversion}_amd64.deb"
    apt install -y "./debs/11/nagios-mod-gearman-worker_${pkgversion}_amd64.deb"
elif [ "$distro" == "Debian" ] || [ "$distro" == "Ubuntu" ]; then
    apt install -y "./debs/nagios-mod-gearman-doc_${pkgversion}_all.deb"
    apt install -y "./debs/nagios-mod-gearman-module_${pkgversion}_amd64.deb"
    apt install -y "./debs/nagios-mod-gearman-tools_${pkgversion}_amd64.deb"
    apt install -y "./debs/nagios-mod-gearman-worker_${pkgversion}_amd64.deb"
else
    dnf install -y "${pkgname}"
fi

set +e
if [ `command -v firewall-cmd` ]; then
    firewall-cmd --zone=public --add-port=4730/tcp --permanent
    firewall-cmd --reload
else
    iptables -A INPUT -p tcp --dport 4730 -j ACCEPT
fi
set -e

echo "Nagios Mod-Gearman upgraded OK"
