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

if ! command -v curl >/dev/null 2>&1; then
  echo "ERROR: curl is required." >&2
  exit 1
fi

# Official OpenAI standalone installer for Linux/macOS.
curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_NON_INTERACTIVE=1 sh

if command -v codex >/dev/null 2>&1; then
  echo "Codex installed: $(command -v codex)"
  codex --version || true
else
  echo "Codex was installed but is not currently on PATH."
  echo "Open a new SSH session, then run: command -v codex"
fi

echo
echo "For headless authentication, try: codex login --device-auth"
echo "Run Codex only from the staging repository, never from your full cPanel home directory."
