#!/usr/bin/env bash
# ==============================================================================
# Elastic Stack Certificate Exchange Autopilot Entrypoint (Bash)
# ==============================================================================
# Zero-interaction autopilot runner for local or multi-server cert exchange.
# ==============================================================================

set -euo pipefail

if [ "$EUID" -ne 0 ]; then
  echo -e "\033[1;31mERROR: Autopilot requires root privileges. Run with sudo.\033[0m" >&2
  exit 1
fi

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PYTHON_SCRIPT="$SCRIPT_DIR/autopilot-certs.py"

if command -v python3 >/dev/null 2>&1 && [ -f "$PYTHON_SCRIPT" ]; then
  exec python3 "$PYTHON_SCRIPT" "$@"
else
  exec "$SCRIPT_DIR/propose-cert-exchange.sh" --execute "$@"
fi
