From 2f78a77c44053a77cb56aa00dea3e7da44794f11 Mon Sep 17 00:00:00 2001 From: Sprite Date: Sun, 8 Feb 2026 04:39:34 +0000 Subject: [PATCH] Add Civo gptme agent script --- aws-lightsail/opencode.sh | 60 +++++++++++++++++++++++++++++++++++++ civo/gptme.sh | 58 +++++++++++++++++++++++++++++++++++ e2b/opencode.sh | 56 ++++++++++++++++++++++++++++++++++ gcp/opencode.sh | 63 +++++++++++++++++++++++++++++++++++++++ modal/opencode.sh | 61 +++++++++++++++++++++++++++++++++++++ 5 files changed, 298 insertions(+) create mode 100644 aws-lightsail/opencode.sh create mode 100644 civo/gptme.sh create mode 100644 e2b/opencode.sh create mode 100644 gcp/opencode.sh create mode 100644 modal/opencode.sh diff --git a/aws-lightsail/opencode.sh b/aws-lightsail/opencode.sh new file mode 100644 index 00000000..bda5e982 --- /dev/null +++ b/aws-lightsail/opencode.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# shellcheck disable=SC2154 +set -eo pipefail + +# Source common functions - try local file first, fall back to remote +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)" +# shellcheck source=aws-lightsail/lib/common.sh + +if [[ -f "${SCRIPT_DIR}/lib/common.sh" ]]; then + source "${SCRIPT_DIR}/lib/common.sh" +else + eval "$(curl -fsSL https://raw.githubusercontent.com/OpenRouterTeam/spawn/main/aws-lightsail/lib/common.sh)" +fi + +log_info "OpenCode on AWS Lightsail" +echo "" + +# 1. Ensure AWS CLI is configured +ensure_aws_cli + +# 2. Generate + register SSH key +ensure_ssh_key + +# 3. Get instance name and create server +SERVER_NAME=$(get_server_name) +create_server "${SERVER_NAME}" + +# 4. Wait for SSH and cloud-init +verify_server_connectivity "${LIGHTSAIL_SERVER_IP}" +wait_for_cloud_init "${LIGHTSAIL_SERVER_IP}" 60 + +# 5. Install OpenCode +log_warn "Installing OpenCode..." +run_server "${LIGHTSAIL_SERVER_IP}" "curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/refs/heads/main/install | bash" +log_info "OpenCode installed" + +# 6. Get OpenRouter API key +echo "" +if [[ -n "${OPENROUTER_API_KEY:-}" ]]; then + log_info "Using OpenRouter API key from environment" +else + OPENROUTER_API_KEY=$(get_openrouter_api_key_oauth 5180) +fi + +# 7. Inject environment variables into ~/.zshrc +log_warn "Setting up environment variables..." + +inject_env_vars_ssh "${LIGHTSAIL_INSTANCE_IP}" upload_file run_server \ + "OPENROUTER_API_KEY=${OPENROUTER_API_KEY}" + +echo "" +log_info "Lightsail instance setup completed successfully!" +log_info "Instance: ${SERVER_NAME} (IP: ${LIGHTSAIL_SERVER_IP})" +echo "" + +# 8. Start OpenCode interactively +log_warn "Starting OpenCode..." +sleep 1 +clear +interactive_session "${LIGHTSAIL_SERVER_IP}" "source ~/.zshrc && opencode" diff --git a/civo/gptme.sh b/civo/gptme.sh new file mode 100644 index 00000000..1e738786 --- /dev/null +++ b/civo/gptme.sh @@ -0,0 +1,58 @@ +#!/bin/bash +set -eo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)" +# shellcheck source=civo/lib/common.sh +if [[ -f "${SCRIPT_DIR}/lib/common.sh" ]]; then + source "${SCRIPT_DIR}/lib/common.sh" +else + eval "$(curl -fsSL https://raw.githubusercontent.com/OpenRouterTeam/spawn/main/civo/lib/common.sh)" +fi + +log_info "gptme on Civo" +echo "" + +ensure_civo_token +ensure_ssh_key + +SERVER_NAME=$(get_server_name) +create_server "${SERVER_NAME}" +verify_server_connectivity "${CIVO_SERVER_IP}" + +log_warn "Waiting for cloud-init to complete..." +generic_ssh_wait "root" "${CIVO_SERVER_IP}" "${SSH_OPTS} -o ConnectTimeout=5" "test -f /root/.cloud-init-complete" "cloud-init" 60 5 + +log_warn "Installing gptme..." +run_server "${CIVO_SERVER_IP}" "pip install gptme 2>/dev/null || pip3 install gptme" + +# Verify installation succeeded +if ! run_server "${CIVO_SERVER_IP}" "command -v gptme &> /dev/null && gptme --version &> /dev/null"; then + log_error "gptme installation verification failed" + log_error "The 'gptme' command is not available or not working properly on server ${CIVO_SERVER_IP}" + exit 1 +fi +log_info "gptme installation verified successfully" + +echo "" +if [[ -n "${OPENROUTER_API_KEY:-}" ]]; then + log_info "Using OpenRouter API key from environment" +else + OPENROUTER_API_KEY=$(get_openrouter_api_key_oauth 5180) +fi + +# Get model preference +MODEL_ID=$(get_model_id_interactive "openrouter/auto" "gptme") || exit 1 + +log_warn "Setting up environment variables..." +inject_env_vars_ssh "${CIVO_SERVER_IP}" upload_file run_server \ + "OPENROUTER_API_KEY=${OPENROUTER_API_KEY}" + +echo "" +log_info "Civo instance setup completed successfully!" +log_info "Server: ${SERVER_NAME} (ID: ${CIVO_SERVER_ID}, IP: ${CIVO_SERVER_IP})" +echo "" + +log_warn "Starting gptme..." +sleep 1 +clear +interactive_session "${CIVO_SERVER_IP}" "source ~/.zshrc && gptme -m openrouter/${MODEL_ID}" diff --git a/e2b/opencode.sh b/e2b/opencode.sh new file mode 100644 index 00000000..f75d8602 --- /dev/null +++ b/e2b/opencode.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# shellcheck disable=SC2154 +set -eo pipefail + +# Source common functions - try local file first, fall back to remote +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)" +# shellcheck source=e2b/lib/common.sh +if [[ -f "${SCRIPT_DIR}/lib/common.sh" ]]; then + source "${SCRIPT_DIR}/lib/common.sh" +else + eval "$(curl -fsSL https://raw.githubusercontent.com/OpenRouterTeam/spawn/main/e2b/lib/common.sh)" +fi + +log_info "OpenCode on E2B" +echo "" + +# 1. Ensure E2B CLI and API token +ensure_e2b_cli +ensure_e2b_token + +# 2. Get sandbox name and create sandbox +SERVER_NAME=$(get_server_name) +create_server "${SERVER_NAME}" + +# 3. Wait for base tools +wait_for_cloud_init + +# 4. Install OpenCode +log_warn "Installing OpenCode..." +run_server "curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/refs/heads/main/install | bash" +log_info "OpenCode installed" + +# 5. Get OpenRouter API key +echo "" +if [[ -n "${OPENROUTER_API_KEY:-}" ]]; then + log_info "Using OpenRouter API key from environment" +else + OPENROUTER_API_KEY=$(get_openrouter_api_key_oauth 5180) +fi + +# 6. Inject environment variables into ~/.zshrc +log_warn "Setting up environment variables..." + +inject_env_vars_local upload_file run_server \ + "OPENROUTER_API_KEY=${OPENROUTER_API_KEY}" + +echo "" +log_info "E2B sandbox setup completed successfully!" +log_info "Sandbox: ${SERVER_NAME} (ID: ${E2B_SANDBOX_ID})" +echo "" + +# 7. Start OpenCode interactively +log_warn "Starting OpenCode..." +sleep 1 +clear +interactive_session "source ~/.zshrc && opencode" diff --git a/gcp/opencode.sh b/gcp/opencode.sh new file mode 100644 index 00000000..3e25a1ab --- /dev/null +++ b/gcp/opencode.sh @@ -0,0 +1,63 @@ +#!/bin/bash +set -eo pipefail + +# Source common functions - try local file first, fall back to remote +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)" +# shellcheck source=gcp/lib/common.sh +if [[ -f "${SCRIPT_DIR}/lib/common.sh" ]]; then + source "${SCRIPT_DIR}/lib/common.sh" +else + eval "$(curl -fsSL https://raw.githubusercontent.com/OpenRouterTeam/spawn/main/gcp/lib/common.sh)" +fi + +# Variables exported by create_server() in lib/common.sh +# shellcheck disable=SC2154 +: "${GCP_SERVER_IP:?}" "${GCP_INSTANCE_NAME_ACTUAL:?}" "${GCP_ZONE:?}" + + +log_info "OpenCode on GCP Compute Engine" +echo "" + +# 1. Ensure gcloud is configured +ensure_gcloud + +# 2. Generate + register SSH key +ensure_ssh_key + +# 3. Get server name and create server +SERVER_NAME=$(get_server_name) +create_server "${SERVER_NAME}" + +# 4. Wait for SSH and cloud-init +verify_server_connectivity "${GCP_SERVER_IP}" +wait_for_cloud_init "${GCP_SERVER_IP}" 60 + +# 5. Install OpenCode +log_warn "Installing OpenCode..." +run_server "${GCP_SERVER_IP}" "curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/refs/heads/main/install | bash" +log_info "OpenCode installed" + +# 6. Get OpenRouter API key +echo "" +if [[ -n "${OPENROUTER_API_KEY:-}" ]]; then + log_info "Using OpenRouter API key from environment" +else + OPENROUTER_API_KEY=$(get_openrouter_api_key_oauth 5180) +fi + +# 7. Inject environment variables into ~/.zshrc +log_warn "Setting up environment variables..." + +inject_env_vars_ssh "${GCP_SERVER_IP}" upload_file run_server \ + "OPENROUTER_API_KEY=${OPENROUTER_API_KEY}" + +echo "" +log_info "GCP instance setup completed successfully!" +log_info "Instance: ${GCP_INSTANCE_NAME_ACTUAL} (Zone: ${GCP_ZONE}, IP: ${GCP_SERVER_IP})" +echo "" + +# 8. Start OpenCode interactively +log_warn "Starting OpenCode..." +sleep 1 +clear +interactive_session "${GCP_SERVER_IP}" "source ~/.zshrc && opencode" diff --git a/modal/opencode.sh b/modal/opencode.sh new file mode 100644 index 00000000..782c1489 --- /dev/null +++ b/modal/opencode.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# shellcheck disable=SC2154 +set -eo pipefail + +# Source common functions - try local file first, fall back to remote +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)" +# shellcheck source=modal/lib/common.sh +if [[ -f "${SCRIPT_DIR}/lib/common.sh" ]]; then + source "${SCRIPT_DIR}/lib/common.sh" +else + eval "$(curl -fsSL https://raw.githubusercontent.com/OpenRouterTeam/spawn/main/modal/lib/common.sh)" +fi + +log_info "OpenCode on Modal" +echo "" + +# 1. Ensure Modal CLI +ensure_modal_cli + +# 2. Get sandbox name and create sandbox +SERVER_NAME=$(get_server_name) +create_server "${SERVER_NAME}" || { + log_error "Failed to create Modal sandbox" + exit 1 +} +if [[ -z "${MODAL_SANDBOX_ID}" ]]; then + log_error "MODAL_SANDBOX_ID not set after create_server" + exit 1 +fi + +# 3. Wait for base tools +wait_for_cloud_init + +# 4. Install OpenCode +log_warn "Installing OpenCode..." +run_server "curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/refs/heads/main/install | bash" +log_info "OpenCode installed" + +# 5. Get OpenRouter API key +echo "" +if [[ -n "${OPENROUTER_API_KEY:-}" ]]; then + log_info "Using OpenRouter API key from environment" +else + OPENROUTER_API_KEY=$(get_openrouter_api_key_oauth 5180) +fi + +# 6. Inject environment variables into ~/.zshrc +log_warn "Setting up environment variables..." +inject_env_vars_local upload_file run_server \ + "OPENROUTER_API_KEY=${OPENROUTER_API_KEY}" + +echo "" +log_info "Modal sandbox setup completed successfully!" +log_info "Sandbox: ${SERVER_NAME} (ID: ${MODAL_SANDBOX_ID})" +echo "" + +# 7. Start OpenCode interactively +log_warn "Starting OpenCode..." +sleep 1 +clear +interactive_session "source ~/.zshrc && opencode"