#!/usr/bin/env bash
set -euo pipefail

echo "==> Installing neowofetch system-wide..."
sudo apt update && sudo apt install -y neowofetch

PROFILE_SCRIPT="/etc/profile.d/neowofetch-ssh.sh"

echo "==> Creating global profile trigger at $PROFILE_SCRIPT..."

sudo tee "$PROFILE_SCRIPT" > /dev/null << 'EOF'
# Auto-run neowofetch on SSH login for all users
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
    # Run only if standard output is a TTY and NOT running under sudo/sudo -i
    if [ -t 1 ] && [ -z "$SUDO_USER" ]; then
        neowofetch
    fi
fi
EOF

# Make sure all users can read the script
sudo chmod 644 "$PROFILE_SCRIPT"

echo "==> Setup complete!"