From 95ddfe15982f0cfe27518619b81654860a3db512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=A5=E5=BE=AE?= Date: Wed, 8 Jul 2026 23:10:06 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0deploy=5Fsync.sh=20+?= =?UTF-8?q?=20post-commit=20hook=E8=87=AA=E5=8A=A8=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy_sync.sh | 62 ++++++++++++++++++++++++++++++++++++++++ scripts/test_sync_marker | 0 2 files changed, 62 insertions(+) create mode 100755 scripts/deploy_sync.sh create mode 100644 scripts/test_sync_marker diff --git a/scripts/deploy_sync.sh b/scripts/deploy_sync.sh new file mode 100755 index 00000000..8d597583 --- /dev/null +++ b/scripts/deploy_sync.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# deploy_sync.sh — 将MoFin脚本同步到知微cron部署目录 +# MoFin是源码源头, ~/.hermes/profiles/position-analyst/scripts/ 是运行副本 +# 用法: ./deploy_sync.sh [--check] [--diff] + +SRC="/home/hmo/MoFin/scripts" +DST="/home/hmo/.hermes/profiles/position-analyst/scripts" +EXCLUDE="prepare_recommendation.py" # profile独有,不覆盖 + +# 排除文件列表(用|分隔) +EXCLUDE_RE="" +for f in $EXCLUDE; do + [ -n "$EXCLUDE_RE" ] && EXCLUDE_RE="$EXCLUDE_RE|" + EXCLUDE_RE="$EXCLUDE_RE$f" +done + +# 检查是否有差异 +if [ "$1" = "--diff" ] || [ "$1" = "--check" ]; then + changed=0 + for f in "$SRC"/*.py "$SRC"/*.sh; do + base=$(basename "$f") + # 跳过排除文件 + [ -n "$EXCLUDE_RE" ] && echo "$base" | grep -qE "^($EXCLUDE_RE)$" && continue + dst="$DST/$base" + if [ ! -f "$dst" ]; then + echo " ➕ $base (仅MoFin有)" + changed=1 + elif ! diff -q "$f" "$dst" >/dev/null 2>&1; then + echo " 🔄 $base (有差异)" + changed=1 + fi + done + [ $changed -eq 0 ] && echo " 一致" + exit 0 +fi + +# 实际同步 +count=0 +for f in "$SRC"/*.py "$SRC"/*.sh; do + base=$(basename "$f") + # 跳过排除文件 + [ -n "$EXCLUDE_RE" ] && echo "$base" | grep -qE "^($EXCLUDE_RE)$" && continue + dst="$DST/$base" + if [ ! -f "$dst" ]; then + cp "$f" "$dst" + echo " ➕ $base → 已复制" + count=$((count+1)) + elif ! diff -q "$f" "$dst" >/dev/null 2>&1; then + cp "$f" "$dst" + echo " 🔄 $base → 已同步" + count=$((count+1)) + fi +done + +# 确保权限一致 +chmod 600 "$DST"/*.py "$DST"/*.sh 2>/dev/null + +if [ $count -eq 0 ]; then + echo "✅ 全部一致,无需同步" +else + echo "✅ 同步了 $count 个文件" +fi diff --git a/scripts/test_sync_marker b/scripts/test_sync_marker new file mode 100644 index 00000000..e69de29b