Make bmem Gitea sync failures trigger immediate server repair and acceptance

This commit is contained in:
bowei
2026-09-15 18:24:08 +08:00
parent a36cbfda2a
commit 84fbcae620
3 changed files with 94 additions and 7 deletions
+15 -5
View File
@@ -87,10 +87,19 @@ if [ "$HOOKCFG" != 0 ] || [ "$CFG_SIZE" -gt 65536 ] 2>/dev/null; then
bad gitconfig "size=${CFG_SIZE}B suspicious-directives=${HOOKCFG} (expected a few hundred B, 0)"
dex "grep -inE 'packObjectsHook|core\\.hooksPath|sshCommand' $GCFG | head -5"
if [ "$FIX" = 1 ]; then
# gitea rewrites a clean global gitconfig at startup, so quarantine + restart is
# both the repair and the proof: hand-editing it would only paper over the entry.
dex "cp $GCFG /data/gitea/home/.gitconfig.quarantine.$TS 2>/dev/null || cp $GCFG $GCFG.quarantine.$TS"
dex "rm -f $GCFG"
# Preserve both the injected config and its referenced executable as
# reversible evidence before startup rebuilds the global config.
HOOK_SCRIPT=$(dex "grep -oE '/data/gitea/home/[A-Za-z0-9_.-]+\\.sh' $GCFG | head -1" | tr -d '\r')
if [ -n "$HOOK_SCRIPT" ]; then
case "$HOOK_SCRIPT" in
/data/gitea/home/*.sh)
if dex "[ -f $HOOK_SCRIPT ] && [ ! -e $HOOK_SCRIPT.quarantine.$TS ]" >/dev/null 2>&1; then
dex "mv $HOOK_SCRIPT $HOOK_SCRIPT.quarantine.$TS"
echo "INFO injected hook script quarantined: $HOOK_SCRIPT.quarantine.$TS"
fi ;;
esac
fi
dex "[ ! -e $GCFG.quarantine.$TS ] && mv $GCFG $GCFG.quarantine.$TS"
$D restart "$CONTAINER" >/dev/null 2>&1
sleep 12
NEW=$(dex "wc -c < $GCFG 2>/dev/null" | tr -d '\r ')
@@ -180,10 +189,11 @@ fi
PUB=$(dex 'ls -d /data/git/repositories/*/*.git 2>/dev/null | head -5' | tr -d '\r')
CLONE_OK=0
CLONE_MSG="no public repo reachable anonymously"
CLONE_DIR="/tmp/tools-sync-httpclone.$TS.$$"
for r in $PUB; do
owner=$(basename "$(dirname "$r")")
name=$(basename "$r" .git)
out=$(dex "rm -rf /tmp/tsdoc; GIT_TERMINAL_PROMPT=0 git clone -q --filter=tree:0 --depth 1 http://localhost:3000/$owner/$name.git /tmp/tsdoc 2>&1; ls /tmp/tsdoc/.git >/dev/null 2>&1 && echo TSDOC_OK; rm -rf /tmp/tsdoc")
out=$(dex "test ! -e $CLONE_DIR || exit 3; GIT_TERMINAL_PROMPT=0 git clone -q --filter=tree:0 --depth 1 http://localhost:3000/$owner/$name.git $CLONE_DIR 2>&1; ls $CLONE_DIR/.git >/dev/null 2>&1 && echo TSDOC_OK; rm -rf $CLONE_DIR")
case "$out" in
*TSDOC_OK*) CLONE_OK=1; CLONE_MSG="$owner/$name"; break ;;
*"could not read Username"*|*"Authentication"*) continue ;;