#!/bin/bash
# Install and configure Netdata monitoring service
# Run with: sudo -A ./scripts/setup-netdata.sh

set -e

echo "=== Installing Netdata monitoring service ==="
pacman -S --noconfirm netdata

echo "=== Enabling and starting Netdata service ==="
systemctl enable netdata
systemctl start netdata

echo "=== Checking Netdata service status ==="
systemctl status netdata --no-pager -l

echo "=== Stopping and disabling Cockpit services ==="
systemctl stop cockpit cockpit.socket 2>/dev/null || echo "Cockpit services not running"
systemctl disable cockpit cockpit.socket 2>/dev/null || echo "Cockpit services not enabled"

echo "=== Deploying updated landing page ==="
cp /home/hoborg/homelab/config/www/index.html /var/www/homelab/
echo "✅ Landing page updated with Netdata link"

echo ""
echo "=== Netdata installation complete! ==="
echo "Local access: http://127.0.0.1:19999/"
echo "External access: https://ak-homelab.duckdns.org/netdata/ (after nginx config deploy)"
echo ""
echo "To deploy nginx config separately:"
echo "sudo cp /home/hoborg/homelab/config/nginx/homelab.conf /etc/nginx/sites-available/homelab"
echo "sudo nginx -t && sudo systemctl reload nginx"