🔄 同步 2026-03-12 15:55 | 一场soul的创业实验(书稿)

This commit is contained in:
卡若
2026-03-12 15:55:42 +08:00
parent 7994e19cda
commit fac8888dc0
302 changed files with 13584 additions and 31197 deletions

View File

@@ -1,51 +0,0 @@
#!/usr/bin/env bash
set -u
cd "$(dirname "$0")/.."
POLL_SECONDS="${POLL_SECONDS:-60}"
log() {
printf "[%s] %s\n" "$(date '+%F %T')" "$*"
}
pull_once() {
git remote get-url origin >/dev/null 2>&1 || return 0
local branch
branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
[ -n "$branch" ] || return 0
git pull --rebase origin "$branch" || true
}
push_once() {
git remote get-url origin >/dev/null 2>&1 || return 0
git push || true
}
while true; do
fswatch -1 -r --exclude '\\.git' --exclude 'node_modules' --exclude '.next' --exclude 'android/app/build' . &
fswatch_pid=$!
start_ts="$(date +%s)"
timed_out=0
while kill -0 "$fswatch_pid" >/dev/null 2>&1; do
now_ts="$(date +%s)"
if [ $((now_ts - start_ts)) -ge "$POLL_SECONDS" ]; then
timed_out=1
kill "$fswatch_pid" >/dev/null 2>&1 || true
wait "$fswatch_pid" >/dev/null 2>&1 || true
break
fi
sleep 1
done
if [ "$timed_out" -eq 1 ]; then
log "no local change, polling remote"
pull_once
continue
fi
wait "$fswatch_pid" >/dev/null 2>&1 || true
log "change detected, committing"
git add . || true
git commit -m "chore: auto-sync" || true
pull_once
push_once
done

7
scripts/gitea_push_once.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
# 首次推送 Gitea先设置 export GITEA_TOKEN=你的Token 再执行本脚本
[ -z "$GITEA_TOKEN" ] && echo "请先执行: export GITEA_TOKEN=你的Gitea的Token" && exit 1
cd "$(dirname "$0")/.."
git remote set-url gitea "http://fnvtk:${GITEA_TOKEN}@open.quwanzhi.com:3000/fnvtk/Mycontent.git"
export HTTP_PROXY=http://127.0.0.1:7897 HTTPS_PROXY=http://127.0.0.1:7897
git push -u gitea main

90
scripts/gitea_sync.sh Executable file
View File

@@ -0,0 +1,90 @@
#!/bin/bash
# ============================================
# 《一场soul的创业实验》→ Gitea 自动同步(与 GitHub fnvtk/Mycontent 同路径)
# 用法:有更新时在项目根目录执行 bash scripts/gitea_sync.sh
# 可选export GITEA_HTTP_PROXY=http://127.0.0.1:7897 外网时走代理
# ============================================
set -euo pipefail
REPO_DIR="${1:-$(cd "$(dirname "$0")/.." && pwd)}"
BRANCH="main"
REMOTE_GITEA="gitea"
REMOTE_ORIGIN="origin"
cd "$REPO_DIR" || exit 1
# 外网推送时可走代理与卡若AI Gitea 一致)
if [ -n "${GITEA_HTTP_PROXY:-}" ]; then
export HTTP_PROXY="$GITEA_HTTP_PROXY" HTTPS_PROXY="$GITEA_HTTP_PROXY" ALL_PROXY="$GITEA_HTTP_PROXY"
fi
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "[gitea_sync] 当前目录不是 Git 仓库:$REPO_DIR"
exit 1
fi
# 确保在 main避免把内容提交到错误分支
current_branch="$(git branch --show-current 2>/dev/null || true)"
if [ "$current_branch" != "$BRANCH" ]; then
echo "[gitea_sync] 当前分支=$current_branch,切换到 $BRANCH"
git checkout "$BRANCH" >/dev/null
fi
has_remote() {
local r="$1"
git remote get-url "$r" >/dev/null 2>&1
}
ff_merge_remote_branch() {
local remote="$1"
if ! has_remote "$remote"; then
return 0
fi
git fetch "$remote" "$BRANCH" --prune >/dev/null 2>&1 || true
# 仅允许快进合并,避免脚本自动制造复杂历史
if git show-ref --verify --quiet "refs/remotes/${remote}/${BRANCH}"; then
git merge --ff-only "${remote}/${BRANCH}" >/dev/null 2>&1 || {
echo "[gitea_sync] ❌ 无法 ff-only 合并 ${remote}/${BRANCH}(可能已分叉或有冲突),请手动处理后再同步。"
exit 1
}
fi
}
commit_if_needed() {
git add -A >/dev/null 2>&1 || true
if ! git diff --cached --quiet 2>/dev/null; then
local ts msg
ts="$(date '+%Y-%m-%d %H:%M')"
msg="🔄 同步 ${ts} | 一场soul的创业实验书稿"
git commit -m "$msg" --quiet 2>/dev/null || true
fi
}
# 1) 先把本地新增/删除提交掉,保证 pull 时可 rebase/ff
commit_if_needed
# 2) 再拉取远端新增GitHub / Gitea 任一端有新提交都能合进来)
ff_merge_remote_branch "$REMOTE_ORIGIN"
ff_merge_remote_branch "$REMOTE_GITEA"
# 3) 拉完后如果又产生本地变更(例如 merge 带来的更新),再补一次提交(一般不会)
commit_if_needed
# 4) 推送到 Gitea必须可选推送到 GitHub若配置了 origin
if has_remote "$REMOTE_GITEA"; then
git push "$REMOTE_GITEA" "$BRANCH" >/dev/null 2>&1 && \
echo "[gitea_sync] ✅ 已推送到 Gitea"
else
echo "[gitea_sync] ❌ 未配置 gitea 远程"
exit 1
fi
if has_remote "$REMOTE_ORIGIN"; then
git push "$REMOTE_ORIGIN" "$BRANCH" >/dev/null 2>&1 && \
echo "[gitea_sync] ✅ 已推送到 GitHuborigin"
fi
echo "[gitea_sync] 📌 仓库:$REPO_DIR"
echo "[gitea_sync] 🔚 完成"
exit 0