#!/usr/bin/env bash
# Public Aurion CLI installer. Usage: curl -fsSL https://qmai.dev/aurion/download/install.sh | bash
set -euo pipefail
PREFIX="${AURION_INSTALL_PREFIX:-$HOME/.local}"
BIN="$PREFIX/bin"
SHARE="$PREFIX/share/qmai-aurion"
BASE="${AURION_DOWNLOAD_BASE:-https://qmai.dev/aurion/download}"
mkdir -p "$BIN" "$SHARE"
curl -fsSL "$BASE/aurion-cli.tar.gz" | tar -xz -C "$SHARE"
cat > "$BIN/aurion" <<WRAP
#!/usr/bin/env bash
export PATH="\$HOME/.local/bin:/usr/local/bin:\$PATH"
exec python3 "$SHARE/bin/aurion_cli.py" "\$@"
WRAP
chmod +x "$BIN/aurion"
mkdir -p "$HOME/.config/aurion"
if [[ ! -f "$HOME/.config/aurion/env" ]]; then
  cat > "$HOME/.config/aurion/env" <<'ENV'
AURION_GATEWAY_URL=https://llm-gateway.206.189.177.49.sslip.io
AURION_API_KEY=
AURION_MODEL=aurion-text
AURION_PRODUCT=aurion-commercial
ENV
  chmod 600 "$HOME/.config/aurion/env"
  echo "Created ~/.config/aurion/env — paste your Fuel key from https://qmai.dev/aurion"
fi
case ":$PATH:" in
  *":$BIN:"*) ;;
  *) echo "Add to PATH: export PATH=\"$BIN:\$PATH\"" ;;
esac
echo "Installed aurion → $BIN/aurion"
echo "  aurion              # commercial chat"
echo "  aurion \"your task\"  # one-shot"
