#!/bin/bash set -e APP_DIR="/opt/ai-os/products/ceo/projects/tech/OpenMAIC/app" CEO_DIR="/opt/ai-os/products/ceo" echo "=== [OpenMAIC Sync] Starting at $(date -u) ===" if [ ! -d "$APP_DIR/.git" ]; then echo "Error: $APP_DIR is not a git repository" exit 1 fi cd "$APP_DIR" OLD_HEAD=$(git rev-parse HEAD 2>/dev/null || echo "none") # 1. Pull code mới nhất từ remote openmaic echo "[OpenMAIC Sync] Pulling from origin main..." git pull --rebase origin main || true # 2. Kiểm tra và commit nếu có thay đổi cục bộ tại app if [ -n "$(git status --porcelain)" ]; then echo "[OpenMAIC Sync] Local changes detected, committing..." git add -A git commit -m "chore: auto-sync OpenMAIC from VPS Hermes [HM]" || true fi # 3. Đẩy lên GitHub nhivo2504/openmaic nếu ahead LOCAL_HEAD=$(git rev-parse HEAD) REMOTE_HEAD=$(git rev-parse origin/main 2>/dev/null || echo "") if [ "$LOCAL_HEAD" != "$REMOTE_HEAD" ]; then echo "[OpenMAIC Sync] Pushing to origin main..." git push origin main || true fi NEW_HEAD=$(git rev-parse HEAD) # 4. Nếu có code mới được cập nhật, tự động reload Docker container if [ "$OLD_HEAD" != "$NEW_HEAD" ]; then echo "[OpenMAIC Sync] New code detected ($OLD_HEAD -> $NEW_HEAD). Rebuilding container..." docker compose up -d --build || true fi # 5. Cập nhật con trỏ submodule lên repo mẹ ceo-ai-os cd "$CEO_DIR" if [ -n "$(git status --porcelain projects/tech/OpenMAIC/app)" ]; then echo "[OpenMAIC Sync] Updating submodule pointer in ceo-ai-os..." git add projects/tech/OpenMAIC/app git commit -m "chore: update OpenMAIC submodule pointer [HM]" || true git push origin main || true fi echo "=== [OpenMAIC Sync] Completed successfully ==="