#!/usr/bin/env bash
set +e

section() { printf '\n=== %s ===\n' "$1"; }

printf 'StarKube VPS Toolkit - read-only system report\n'
printf 'Generated at: %s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
printf 'Privacy: this script does not upload or modify data. Review output before sharing.\n'

section 'System and virtualization'
cat /etc/os-release 2>/dev/null | head -12
uname -a
uptime
systemd-detect-virt 2>/dev/null || true

section 'CPU'
lscpu 2>/dev/null | grep -E 'Model name|Socket|Core|Thread|CPU\(s\)'
cat /proc/loadavg 2>/dev/null

section 'Memory'
free -h 2>/dev/null
grep -E 'MemTotal|MemAvailable|SwapTotal|SwapFree' /proc/meminfo 2>/dev/null

section 'Disk'
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS 2>/dev/null
df -hT 2>/dev/null

section 'Network'
ip -brief address 2>/dev/null
ip route 2>/dev/null
printf 'Public IPv4: '
curl -4fsS --max-time 8 https://api.ipify.org 2>/dev/null || printf 'unavailable'
printf '\nPublic IPv6: '
curl -6fsS --max-time 8 https://api64.ipify.org 2>/dev/null || printf 'unavailable'
printf '\n'

section 'DNS'
sed -n '1,20p' /etc/resolv.conf 2>/dev/null
getent ahosts star-kube.com 2>/dev/null | head

section 'Services and listening ports'
systemctl is-active ssh sshd qemu-guest-agent 2>/dev/null || true
ss -lntup 2>/dev/null | head -30

printf '\nReport complete. Remove public IPs and hostnames before posting publicly.\n'
