#!/usr/bin/env bash # Manage the license key on an already-installed rocks-ad-agent host. # # Usage: # license.sh status — check current activation state # license.sh set — replace the key and restart the agent set -euo pipefail BUNDLE_DIR="${BUNDLE_DIR:-$HOME/rocks-ad-agent}" CMD="${1:-status}" if [ ! -d "$BUNDLE_DIR" ]; then echo "ERROR: $BUNDLE_DIR not found. Run install.sh first." >&2 exit 1 fi cd "$BUNDLE_DIR" case "$CMD" in status) if curl -fsS http://localhost:4108/status 2>/dev/null; then echo "" else echo "ERROR: could not reach the local agent on :4108 — is the bundle running? ('docker compose ps')" >&2 exit 1 fi ;; set) NEW_KEY="${2:-}" if [ -z "$NEW_KEY" ]; then echo "Usage: license.sh set " >&2 exit 1 fi if [ ! -f .env ]; then echo "ERROR: .env not found in $BUNDLE_DIR" >&2 exit 1 fi # Portable in-place sed (works the same on GNU and BSD sed with the # explicit backup-suffix form) — replaces the LICENSE_KEY line only, # leaves GATEWAY_URL/OBS_WS_PASSWORD untouched. sed -i.bak "s|^LICENSE_KEY=.*|LICENSE_KEY=$NEW_KEY|" .env rm -f .env.bak echo "==> Restarting license-agent with the new key..." docker compose up -d --force-recreate license-agent echo "==> Waiting for activation..." for i in $(seq 1 15); do if curl -fsS http://localhost:4108/status 2>/dev/null | grep -q '"connected":true'; then echo "✓ Activated." exit 0 fi sleep 2 done echo "Not connected after 30s — check: docker compose logs license-agent" >&2 exit 1 ;; *) echo "Usage: license.sh [status|set ]" >&2 exit 1 ;; esac