chore: 添加deploy_sync.sh + post-commit hook自动同步

This commit is contained in:
知微
2026-07-08 23:10:06 +08:00
parent b13259df5f
commit 95ddfe1598
2 changed files with 62 additions and 0 deletions
+62
View File
@@ -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