Files
boshu2__agentops/scripts/install-codex.sh
T
2026-04-11 17:19:04 -04:00

85 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# install-codex.sh — Install AgentOps into the local Codex native plugin cache
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/boshu2/agentops/main/scripts/install-codex.sh | bash
#
# What it does:
# 1. Downloads a temporary AgentOps archive (no local git clone)
# 2. Builds the generated Codex-native skill bundle
# 3. Refreshes the native Codex plugin cache in ~/.codex/plugins/cache
# 4. Archives stale raw skill mirrors in ~/.agents/skills and ~/.codex/skills when found
# 5. Enables the plugin in ~/.codex/config.toml
#
# Update policy:
# Re-run this installer when new AgentOps releases land.
set -euo pipefail
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
info() { echo -e "${GREEN}✓${NC} $*"; }
warn() { echo -e "${YELLOW}!${NC} $*"; }
fail() { echo -e "${RED}✗${NC} $*"; exit 1; }
UPDATE_CMD="curl -fsSL https://raw.githubusercontent.com/boshu2/agentops/main/scripts/install-codex.sh | bash"
SOURCE_ROOT_OVERRIDE="${AGENTOPS_BUNDLE_ROOT:-}"
INSTALL_REF="${AGENTOPS_INSTALL_REF:-main}"
if [[ "$INSTALL_REF" == "main" ]]; then
ARCHIVE_URL="https://codeload.github.com/boshu2/agentops/tar.gz/refs/heads/main"
else
ARCHIVE_URL="https://codeload.github.com/boshu2/agentops/tar.gz/refs/tags/$INSTALL_REF"
fi
echo "Installing AgentOps for Codex..."
echo ""
for cmd in curl tar; do
if ! command -v "$cmd" >/dev/null 2>&1; then
fail "Missing required command: $cmd"
fi
done
if ! command -v codex >/dev/null 2>&1; then
warn "Codex CLI not found in PATH. Install from https://github.com/openai/codex"
warn "Continuing anyway — skills will be ready when Codex is installed."
fi
TMP_DIR="$(mktemp -d)"
cleanup() { rm -rf "$TMP_DIR"; }
trap cleanup EXIT
if [[ -n "$SOURCE_ROOT_OVERRIDE" ]]; then
SRC_ROOT="$SOURCE_ROOT_OVERRIDE"
info "Using provided AgentOps bundle: $SRC_ROOT"
else
ARCHIVE_FILE="${TMP_DIR}/agentops.tar.gz"
info "Downloading AgentOps bundle..."
curl -fsSL "$ARCHIVE_URL" -o "$ARCHIVE_FILE"
tar -tzf "$ARCHIVE_FILE" > "${TMP_DIR}/archive-files.txt"
ARCHIVE_ROOT="$(awk -F/ 'NR == 1 { print $1 }' "${TMP_DIR}/archive-files.txt")"
[ -n "$ARCHIVE_ROOT" ] || fail "Could not determine archive root directory"
tar -xzf "$ARCHIVE_FILE" -C "$TMP_DIR"
SRC_ROOT="${TMP_DIR}/${ARCHIVE_ROOT}"
fi
[ -f "$SRC_ROOT/scripts/install-codex-plugin.sh" ] || fail "Native Codex installer not found in bundle"
# skills-codex/ is pre-built in the bundle (manually maintained, no sync needed)
bash "$SRC_ROOT/scripts/install-codex-plugin.sh" \
--repo-root "$SRC_ROOT" \
--version "$INSTALL_REF" \
--update-command "$UPDATE_CMD"
echo ""
echo "Update note:"
echo " AgentOps ships frequent updates."
echo " Re-run this installer regularly to pick up the latest main branch changes:"
echo " $UPDATE_CMD"