#!/bin/bash

echo "========================================="
echo "HX-KI SERVER INVENTORY"
echo "========================================="
echo "HOST: $(hostname)"
echo "DATE: $(date)"
echo ""

echo "===== SYSTEM ====="
uname -a
hostnamectl
uptime

echo ""
echo "===== CPU ====="
lscpu

echo ""
echo "===== MEMORY ====="
free -h

echo ""
echo "===== DISK ====="
df -h
lsblk

echo ""
echo "===== NETWORK INTERFACES ====="
ip -brief addr

echo ""
echo "===== ROUTING ====="
ip route

echo ""
echo "===== LISTENING PORTS ====="
ss -tulpen

echo ""
echo "===== FIREWALL / NAT ====="
iptables -t nat -L -n -v 2>/dev/null || true
nft list ruleset 2>/dev/null || true

echo ""
echo "===== WIREGUARD STATUS ====="
wg show 2>/dev/null || echo "WireGuard nicht aktiv"

echo ""
echo "===== DOCKER INFO ====="
docker info 2>/dev/null

echo ""
echo "===== DOCKER CONTAINERS ====="
docker ps -a 2>/dev/null

echo ""
echo "===== DOCKER IMAGES ====="
docker images 2>/dev/null

echo ""
echo "===== DOCKER NETWORKS ====="
docker network ls 2>/dev/null

echo ""
echo "===== DOCKER NETWORK DETAILS ====="
for net in $(docker network ls --format '{{.Name}}'); do
    echo "--- $net ---"
    docker network inspect $net
done

echo ""
echo "===== DOCKER VOLUMES ====="
docker volume ls 2>/dev/null

echo ""
echo "===== CADDY ====="
systemctl status caddy 2>/dev/null | head -n 20 || true
docker ps --filter "ancestor=caddy" 2>/dev/null

echo ""
echo "===== CADDYFILE ====="
if [ -f /etc/caddy/Caddyfile ]; then
    cat /etc/caddy/Caddyfile
fi

echo ""
echo "===== SYSTEMD SERVICES (RUNNING) ====="
systemctl list-units --type=service --state=running

echo ""
echo "===== HX-KI STRUCTURE ====="
find /opt -maxdepth 3 -type d 2>/dev/null
find /data -maxdepth 3 -type d 2>/dev/null
