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

set -e

echo "=== Installing Glances monitoring service ==="
pacman -S --noconfirm glances python-fastapi uvicorn python-jinja

echo "=== Creating glances user ==="
useradd -r -s /bin/false glances 2>/dev/null || echo "User glances already exists"

echo "=== Deploying Glances systemd service ==="
cp /home/hoborg/homelab/config/systemd/glances-web.service /etc/systemd/system/
systemctl daemon-reload

echo "=== Enabling and starting Glances service ==="
systemctl enable glances-web
systemctl start glances-web

echo "=== Checking Glances service status ==="
systemctl status glances-web --no-pager -l

echo ""
echo "=== Glances installation complete! ==="
echo "Local access: http://127.0.0.1:61208/"
echo "External access: https://ak-homelab.duckdns.org/glances/ (requires nginx config)"
echo "Basic auth: admin / AdminPass2024!"