VOLC_ACCESS_KEY_ID="your AK"
VOLC_SECRET_KEY="your SK"
CONFIG_FILE="/root/.openclaw/openclaw.json"
ENV_FILE="/root/.openclaw/.env"
if [[ -f "${ENV_FILE}" ]]; then
ARK_CLAW_ID="${CLAW_INSTANCE_ID:OTEL_SERVICE_NAME}"
echo " ARK_CLAW_ID = '${ARK_CLAW_ID}'"
export HOME="${HOME:-/root}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLUGIN_NAME="agent-sentry"
LEGACY_PLUGIN_NAME="claw-sentry"
OLD_PLUGIN_NAME="ai-assistant-security-openclaw"
EXTENSIONS_DIR="${HOME}/.openclaw/extensions"
CS_TOS_BASE_URL="https://claw-sentry.tos-cn-beijing.volces.com"
CS_TEMP_DIR="/tmp/agent-sentry"
GO_BINARY_URL="https://clawsentry-arkclaw-update.tos-cn-beijing.volces.com/clawsentry${TARGET_VERSION}/initgo_arkclaw_online"
GO_BINARY_PATH="/tmp/initgo_arkclaw_online"
if [[ "$REGION" == "cn-hongkong" ]]; then
echo "Using cn-hongkong region download addresses"
CS_TOS_BASE_URL="https://claw-sentry-hongkong.tos-cn-hongkong.volces.com"
GO_BINARY_URL="https://clawsentry-arkclaw-update-hongkong.tos-cn-hongkong.volces.com/clawsentry${TARGET_VERSION}/initgo_arkclaw_online"
echo "Using cn-beijing region download addresses"
echo "======================================="
echo "agent-sentry configure (with Go binary)"
echo "======================================="
echo "[1/5] Checking dependencies..."
if ! command -v wget &>/dev/null; then
echo "Error: wget not found"
echo "Please install wget first"
echo "[2/5] Checking and removing old plugins..."
OLD_PLUGIN_DIR="${EXTENSIONS_DIR}/${OLD_PLUGIN_NAME}"
if [[ -d "$OLD_PLUGIN_DIR" ]]; then
echo "Old plugin found: $OLD_PLUGIN_NAME, uninstalling..."
if command -v openclaw &>/dev/null; then
echo "y" | openclaw plugins uninstall "$OLD_PLUGIN_NAME" 2>/dev/null || true
echo "openclaw command not found, skipping uninstall"
if [[ -d "$OLD_PLUGIN_DIR" ]]; then
echo "Directory $OLD_PLUGIN_DIR still exists, force deleting..."
rm -rf "$OLD_PLUGIN_DIR"
NEW_PLUGIN_DIR="${EXTENSIONS_DIR}/${PLUGIN_NAME}"
if [[ -d "$NEW_PLUGIN_DIR" ]]; then
echo "Existing $PLUGIN_NAME plugin found, removing..."
if command -v openclaw &>/dev/null; then
echo "y" | openclaw plugins uninstall "$PLUGIN_NAME" 2>/dev/null || true
echo "openclaw command not found, skipping uninstall"
if [[ -d "$NEW_PLUGIN_DIR" ]]; then
echo "Directory $NEW_PLUGIN_DIR still exists, force deleting..."
rm -rf "$NEW_PLUGIN_DIR"
LEGACY_PLUGIN_DIR="${EXTENSIONS_DIR}/${LEGACY_PLUGIN_NAME}"
if [[ -d "$LEGACY_PLUGIN_DIR" ]]; then
echo "Legacy plugin found: $LEGACY_PLUGIN_NAME, uninstalling..."
if command -v openclaw &>/dev/null; then
echo "y" | openclaw plugins uninstall "$LEGACY_PLUGIN_NAME" 2>/dev/null || true
echo "openclaw command not found, skipping uninstall"
if [[ -d "$LEGACY_PLUGIN_DIR" ]]; then
echo "Directory $LEGACY_PLUGIN_DIR still exists, force deleting..."
rm -rf "$LEGACY_PLUGIN_DIR"
echo "[3/5] Downloading and installing agent-sentry from TOS..."
CS_TGZ_PATH="/tmp/agent-sentry-${TARGET_VERSION}.tgz"
echo "Downloading from: ${CS_TOS_BASE_URL}/agent-sentry-${TARGET_VERSION}.tgz"
if ! wget -q "${CS_TOS_BASE_URL}/agent-sentry-${TARGET_VERSION}.tgz" -O "$CS_TGZ_PATH"; then
echo "Warning: Failed to download agent-sentry from TOS, will continue with Go binary"
echo "Extracting to: ${CS_TEMP_DIR}"
if ! tar -xzf "$CS_TGZ_PATH" -C "$CS_TEMP_DIR"; then
echo "Warning: Failed to extract agent-sentry, will continue with Go binary"
echo "Installing from local package..."
INSTALL_DIR="${CS_TEMP_DIR}/package"
if command -v openclaw &>/dev/null; then
if ! openclaw plugins install "$INSTALL_DIR" 2>/dev/null; then
echo "Warning: Failed to install agent-sentry, will continue with Go binary"
echo "agent-sentry installed successfully"
echo "openclaw command not found, skipping installation"
echo "Cleaning up TOS download..."
echo "[4/5] Downloading Go binary..."
echo "Downloading from: $GO_BINARY_URL"
if ! wget -q "$GO_BINARY_URL" -O "$GO_BINARY_PATH"; then
echo "Error: Failed to download Go binary"
chmod +x "$GO_BINARY_PATH"
echo "[5/5] Running Go binary..."
export VOLC_ACCESS_KEY_ID="$VOLC_ACCESS_KEY_ID"
export VOLC_SECRET_KEY="$VOLC_SECRET_KEY"
CMD_ARGS+=("-space_id" "$SPACE_ID")
CMD_ARGS+=("-ark_claw_id" "$ARK_CLAW_ID")
CMD_ARGS+=("-region" "$REGION")
CMD_ARGS+=("-config_file" "$CONFIG_FILE")
if [[ -n "$TOKEN" ]]; then
CMD_ARGS+=("-token" "$TOKEN")
if [[ -n "$NAME" ]]; then
CMD_ARGS+=("-name" "$NAME")
if [[ -n "$USER_UID" ]]; then
CMD_ARGS+=("-user_uid" "$USER_UID")
echo "Executing: $GO_BINARY_PATH ${CMD_ARGS[*]}"
if ! "$GO_BINARY_PATH" "${CMD_ARGS[@]}"; then
echo "Error: failed to execute: $GO_BINARY_PATH ${CMD_ARGS[*]} (exit_code=${rc})" >&2
echo "Checking openclaw version and setting hooks..."
echo "======================================="
if command -v openclaw &>/dev/null; then
if version_output=$(openclaw --version 2>&1); then
echo "Openclaw version command output: $version_output"
if [[ "$version_output" =~ OpenClaw[[:space:]]+([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
month=${BASH_REMATCH[2]}
patch=${BASH_REMATCH[3]}
echo "Openclaw version $year.$month.$patch detected"
if (( year > 2026 )); then
elif (( year == 2026 )); then
if (( month > 4 )); then
elif (( month == 4 )) && (( patch >= 27 )); then
if [ "$should_set_hook" = true ]; then
echo "Setting allowConversationAccess hook..."
openclaw config set plugins.entries.agent-sentry.hooks.allowConversationAccess true 2>/dev/null || echo "Warning: Failed to set hook configuration"
echo "Openclaw version $year.$month.$patch is older than 2026.4.27, skipping hook configuration"
echo "Could not parse openclaw version from: $version_output"
echo "Could not get openclaw version, skipping hook configuration"
echo "openclaw command not found, skipping hook configuration"
echo "======================================="
echo "Restarting OpenClaw gateway..."
if command -v openclaw &>/dev/null; then
openclaw gateway restart
echo "Warning: openclaw command not found, skipping gateway restart"