#!/usr/bin/env bash set -euo pipefail PKG_ROOT="$(cd "$(dirname "$0")/.." && pwd)" AIOS_GITOPS_ROOT="${AIOS_GITOPS_ROOT:-/data/aios-gitops}" WORKSPACE="${AIOS_GITOPS_WORKSPACE:-$AIOS_GITOPS_ROOT/workspace}" LOG_DIR="$AIOS_GITOPS_ROOT/logs" BACKUP_DIR="$AIOS_GITOPS_ROOT/backups/pre-v1r1c0-$(date +%Y%m%d-%H%M%S)" mkdir -p "$LOG_DIR" "$BACKUP_DIR" "$WORKSPACE" "$AIOS_GITOPS_ROOT/runtime/secrets" LOG="$LOG_DIR/install-v1r1c0-$(date +%Y%m%d-%H%M%S).log" exec > >(tee -a "$LOG") 2>&1 echo "AIOS V1R1C0 GitOps + Custom LLM overlay installer" echo "PKG_ROOT=$PKG_ROOT" echo "AIOS_GITOPS_ROOT=$AIOS_GITOPS_ROOT" echo "WORKSPACE=$WORKSPACE" echo "== Preflight ==" hostname || true; date -Is; whoami; pwd; df -h || true; free -h || true; docker ps || true; docker compose version || docker-compose version || true; ss -lntp || true echo "== Backup existing important paths ==" cp -a /data/agent "$BACKUP_DIR/data-agent" 2>/dev/null || true cp -a /data/aios "$BACKUP_DIR/data-aios" 2>/dev/null || true cp -a /opt/aios "$BACKUP_DIR/opt-aios" 2>/dev/null || true cp -a /etc/systemd/system "$BACKUP_DIR/systemd-system" 2>/dev/null || true echo "== Copy overlay files into GitOps root ==" mkdir -p "$AIOS_GITOPS_ROOT/adapters" "$AIOS_GITOPS_ROOT/scripts" "$AIOS_GITOPS_ROOT/artifacts" "$AIOS_GITOPS_ROOT/runtime" rsync -a "$PKG_ROOT/adapters/" "$AIOS_GITOPS_ROOT/adapters/" rsync -a "$PKG_ROOT/scripts/" "$AIOS_GITOPS_ROOT/scripts/" rsync -a "$PKG_ROOT/config/" "$AIOS_GITOPS_ROOT/config/" if [ ! -d "$WORKSPACE/.git" ]; then echo "== Initialize workspace git repository from package content ==" rsync -a --delete --exclude 'source-baseline/*.zip' "$PKG_ROOT/" "$WORKSPACE/" cd "$WORKSPACE" git init git config user.name "AIOS GitOps Bot" git config user.email "gitops-bot@cnnetmkt.top" git add . git commit -m "init(baseline): import AIOS V1R1C0 multiuser gitops custom llm baseline" || true git branch -M main git tag -a V1R1C0 -m "AIOS V1R1C0 multiuser gitops custom llm baseline" || true else echo "== Existing workspace git repo found; overlay V1R1C0 files ==" rsync -a "$PKG_ROOT/docs/" "$WORKSPACE/docs/" rsync -a "$PKG_ROOT/config/" "$WORKSPACE/config/" rsync -a "$PKG_ROOT/migrations/" "$WORKSPACE/migrations/" rsync -a "$PKG_ROOT/adapters/" "$WORKSPACE/adapters/" rsync -a "$PKG_ROOT/scripts/" "$WORKSPACE/scripts/" rsync -a "$PKG_ROOT/tests/" "$WORKSPACE/tests/" cd "$WORKSPACE" git add docs config migrations adapters scripts tests VERSION README.md || true git commit -m "feat(gitops): add V1R1C0 multiuser custom LLM registry and runtime selector" || true git tag -a V1R1C0 -m "AIOS V1R1C0 feature release" || true fi echo "== Token initialization ==" TOKEN_FILE="$AIOS_GITOPS_ROOT/runtime/secrets/gitops.tokens" BARE_REPO="$AIOS_GITOPS_ROOT/runtime/gitea-bin/data/repositories/aios/aios-v23.git" if [ ! -s "$TOKEN_FILE" ]; then (openssl rand -hex 32 || python3 -c 'import secrets; print(secrets.token_hex(32))') > "$TOKEN_FILE" chmod 600 "$TOKEN_FILE" fi echo "== Install systemd service for GitOps Model API ==" cat >/etc/systemd/system/aios-gitops-model-api.service < http://127.0.0.1:3000 /api -> http://127.0.0.1:18890/api /base -> http://127.0.0.1:18890/base /ver -> http://127.0.0.1:18890/ver /diff -> http://127.0.0.1:18890/diff /patch -> http://127.0.0.1:18890/patch /run -> http://127.0.0.1:18890/run /model -> http://127.0.0.1:18890/model /hook -> existing OpenClaw/WebOps webhook, or 127.0.0.1:18891 if adapter is enabled EOF echo "== Local health check ==" curl -fsS http://127.0.0.1:18890/health || true echo "AIOS_V1R1C0_INSTALL_DONE log=$LOG backup=$BACKUP_DIR"