33 lines
1.0 KiB
Bash
Executable File
33 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
||
# 自动提交 OpenClaw 配置变更到 Gitea
|
||
# 每 6 小时执行一次,没有变更则不提交
|
||
|
||
REPO_DIR="/home/yangxuan/.openclaw"
|
||
cd "$REPO_DIR" || exit 1
|
||
|
||
# 检查是否有变更
|
||
# 检查是否有文件变更(忽略子模块 workspace)
|
||
CHANGES=$(git status --porcelain --ignore-submodules 2>/dev/null)
|
||
if [ -z "$CHANGES" ]; then
|
||
# 无变更,静默退出
|
||
exit 0
|
||
fi
|
||
|
||
# 有变更,记录日志
|
||
LOG_FILE="$REPO_DIR/.git/auto-commit.log"
|
||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 检测到变更,开始提交..." >> "$LOG_FILE"
|
||
|
||
# 添加所有变更
|
||
git add -A 2>> "$LOG_FILE" || { echo " git add 失败" >> "$LOG_FILE"; exit 1; }
|
||
|
||
# 提交(没有变更时 git commit 会失败,这正常)
|
||
git commit -m "auto: sync OpenClaw config $(date '+%Y-%m-%d %H:%M')" 2>> "$LOG_FILE" || {
|
||
echo " 无新变更需要提交" >> "$LOG_FILE"
|
||
exit 0
|
||
}
|
||
|
||
# 推送到 Gitea(分支名 314)
|
||
git push origin 2>> "$LOG_FILE" && echo " 推送成功" >> "$LOG_FILE" || echo " 推送失败" >> "$LOG_FILE"
|
||
|
||
exit 0
|