#!/bin/bash
# Haven Blueshore — Wazuh agent 4.8.1 install (Debian/Ubuntu .deb or RHEL .rpm).
# Enrolls on first start against siem.havenblueshore.cloud (TCP 1515) using
# the enrollment password; agent name defaults to the hostname.
# Run as root from the folder containing this script and the packages.
set -euo pipefail
cd "$(dirname "$0")"
[ "$(id -u)" = 0 ] || { echo "Run as root"; exit 1; }

export WAZUH_MANAGER="siem.havenblueshore.cloud"
export WAZUH_REGISTRATION_SERVER="siem.havenblueshore.cloud"
export WAZUH_AGENT_GROUP="default"
export WAZUH_REGISTRATION_PASSWORD="807333e27cfcd64c63349d92ced93d88"

if command -v dpkg >/dev/null 2>&1; then
  dpkg -i wazuh-agent_4.8.1-1_amd64.deb || apt-get install -f -y
elif command -v rpm >/dev/null 2>&1; then
  rpm -ivh wazuh-agent-4.8.1-1.x86_64.rpm
else
  echo "Neither dpkg nor rpm found — unsupported distro."; exit 1
fi
systemctl daemon-reload
systemctl enable --now wazuh-agent
sleep 2
systemctl is-active --quiet wazuh-agent && echo "Wazuh agent 4.8.1 installed and running; enrollment to siem.havenblueshore.cloud in progress."
