#!/bin/sh
set -e

# Create socktop user and group if they don't exist
if ! getent group socktop >/dev/null; then
    addgroup --system socktop
fi

if ! getent passwd socktop >/dev/null; then
    adduser --system --ingroup socktop --home /var/lib/socktop \
            --no-create-home --disabled-password --disabled-login \
            --gecos "Socktop Agent" socktop
fi

# Create state directory
mkdir -p /var/lib/socktop
chown socktop:socktop /var/lib/socktop
chmod 755 /var/lib/socktop

# Create config directory if it doesn't exist
mkdir -p /etc/socktop
chmod 755 /etc/socktop

#DEBHELPER#

# Print helpful message to the user
cat <<EOF

┌─────────────────────────────────────────────────────────────────────┐
│ socktop-agent has been installed successfully!                      │
├─────────────────────────────────────────────────────────────────────┤
│                                                                      │
│ The systemd service has been installed but is NOT enabled by        │
│ default. To enable and start the service:                           │
│                                                                      │
│   sudo systemctl enable --now socktop-agent                         │
│                                                                      │
│ To start without enabling on boot:                                  │
│                                                                      │
│   sudo systemctl start socktop-agent                                │
│                                                                      │
│ To check service status:                                            │
│                                                                      │
│   sudo systemctl status socktop-agent                               │
│                                                                      │
│ Default settings:                                                   │
│   - Port: 3000 (use -p or --port to change)                        │
│   - SSL/TLS: disabled (use --enableSSL to enable)                  │
│                                                                      │
│ For more information, see:                                          │
│   /usr/share/doc/socktop_agent/README.md                            │
│                                                                      │
└─────────────────────────────────────────────────────────────────────┘

EOF

exit 0
