Files
opantoantro/cc-remote.sh
T
Beyhan Ogur a408821410 first commit
2026-05-11 15:08:50 +03:00

74 lines
2.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
# ──────────────────────────────────────────────
# optoant Remote Gateway → Claude Code Launcher
# ──────────────────────────────────────────────
# Tüm yapılandırma .env dosyasından okunur.
# GATEWAY_URL tanımlandıysa parametresiz çalışır.
#
# .env'de olması gerekenler:
# GATEWAY_URL=http://sunucu-ip:8000 (zorunlu)
# OPENAI_KEY=... (API anahtarı)
#
# Opsiyonel override:
# ./cc-remote.sh http://10.0.0.5:8000 (URL override)
# ./cc-remote.sh --print (sadece env'leri göster)
# ──────────────────────────────────────────────
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
# ── .env'yi yükle (API key için) ──
if [[ -f "$SCRIPT_DIR/.env" ]]; then
set -a
source "$SCRIPT_DIR/.env"
set +a
fi
# ── Gateway URL: ilk argüman (-- ile başlamıyorsa) ya da GATEWAY_URL env ──
GATEWAY_URL="${GATEWAY_URL:-}"
if [[ "${1:-}" != "" && "$1" != -* ]]; then
GATEWAY_URL="$1"
shift
fi
if [[ -z "$GATEWAY_URL" ]]; then
echo "❌ GATEWAY_URL tanımlı değil."
echo " .env dosyasına ekleyin: GATEWAY_URL=http://sunucu-ip:8000"
echo " Veya parametreyle: ./cc-remote.sh http://sunucu-ip:8000"
exit 1
fi
ANTHROPIC_ENDPOINT="${ANTHROPIC_BASE_URL:-${GATEWAY_URL}/anthropic}"
ANTHROPIC_KEY="${ANTHROPIC_API_KEY:-${OPENAI_KEY:-}}"
# ── Gateway health check ──
echo "🔍 Gateway kontrol ediliyor: ${GATEWAY_URL}/health"
if curl -sf "${GATEWAY_URL}/health" > /dev/null 2>&1; then
echo "✅ Gateway erişilebilir"
else
echo "⚠️ Gateway'e ulaşılamadı, yine de bağlanmayı deneyeceğim"
fi
# ── Print mode ──
case "${1:-}" in
--print|-p)
echo ""
echo "┌─ optoant Remote → Claude Code Environment"
echo "│ ANTHROPIC_BASE_URL=${ANTHROPIC_ENDPOINT}"
echo "│ ANTHROPIC_API_KEY=${ANTHROPIC_KEY:0:20}... (masked)"
echo "│ Gateway: ${GATEWAY_URL}/health"
echo "└─"
exit 0
;;
esac
# ── Claude Code'u başlat ──
echo "┌─ Claude Code başlatılıyor (remote gateway)..."
echo "│ Gateway: ${ANTHROPIC_ENDPOINT}"
echo "└─"
echo ""
ANTHROPIC_BASE_URL="${ANTHROPIC_ENDPOINT}" \
ANTHROPIC_API_KEY="${ANTHROPIC_KEY}" \
claude "$@"