BurningTimesAi/scripts/unity_project_sync.sh

88 lines
2.7 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Unity 프로젝트 SessionStart 자동 pull (2026-04-20 PD 옵션 A 승인)
#
# 역할: paths.local.json의 UNITY_PROJECT_ROOT 경로를 읽어 git pull --ff-only 수행
# 근거: C30 git 동기화 점검 의무 · 외부 저장소 Unity 프로젝트 자동 이행
# C34-12 Degraded 운영: 경로 미설정·레포 아님·pull 실패 시 경고만, 작업 차단 금지
set +e # Degraded 운영 — 실패 시 exit 0 보장
# Lock 파일 (race 방지)
LOCK_FILE="$HOME/.claude/.nerdnavis_unity_sync.lock"
LOCK_STALE_SECONDS=300 # 5분 이상 lock = stale
# Stale lock cleanup (trap 이전)
if [ -f "$LOCK_FILE" ]; then
LOCK_MTIME=$(stat -c %Y "$LOCK_FILE" 2>/dev/null || stat -f %m "$LOCK_FILE" 2>/dev/null)
NOW=$(date +%s)
if [ -n "$LOCK_MTIME" ] && [ $((NOW - LOCK_MTIME)) -gt $LOCK_STALE_SECONDS ]; then
rm -f "$LOCK_FILE" 2>/dev/null
echo " [Unity sync] stale lock 제거 ($((NOW - LOCK_MTIME))s)"
else
echo " [Unity sync] 이미 진행 중 (lock 존재) — 스킵"
exit 0
fi
fi
# Lock 획득 + 종료 시 자동 제거 (trap)
touch "$LOCK_FILE"
trap 'rm -f "$LOCK_FILE" 2>/dev/null' EXIT
# paths.local.json 존재 확인
PATHS_FILE="paths.local.json"
if [ ! -f "$PATHS_FILE" ]; then
echo "⚠️ [Unity sync] paths.local.json 부재 — template 복사 후 UNITY_PROJECT_ROOT 설정 필요"
exit 0
fi
# UNITY_PROJECT_ROOT 추출 (jq 없으면 grep 대체)
if command -v jq >/dev/null 2>&1; then
UNITY_ROOT=$(jq -r '.UNITY_PROJECT_ROOT // empty' "$PATHS_FILE" 2>/dev/null)
else
UNITY_ROOT=$(grep -oP '"UNITY_PROJECT_ROOT"\s*:\s*"\K[^"]+' "$PATHS_FILE" 2>/dev/null)
fi
if [ -z "$UNITY_ROOT" ] || [ "$UNITY_ROOT" = "null" ]; then
echo "⚠️ [Unity sync] UNITY_PROJECT_ROOT 미설정"
exit 0
fi
# 경로 실체 확인
if [ ! -d "$UNITY_ROOT" ]; then
echo "⚠️ [Unity sync] 경로 부재: $UNITY_ROOT"
exit 0
fi
# git 레포 확인
if [ ! -d "$UNITY_ROOT/.git" ]; then
echo "⚠️ [Unity sync] git 레포 아님: $UNITY_ROOT (C30 수동 점검 대상 외)"
exit 0
fi
# fetch + pull --ff-only
cd "$UNITY_ROOT" || { echo "⚠️ [Unity sync] cd 실패"; exit 0; }
FETCH_OUT=$(git fetch origin 2>&1)
FETCH_EXIT=$?
if [ $FETCH_EXIT -ne 0 ]; then
echo "⚠️ [Unity sync] fetch 실패 (network·인증 확인 필요)"
echo "$FETCH_OUT" | head -3
exit 0
fi
BEHIND=$(git rev-list --count HEAD..@{u} 2>/dev/null || echo "0")
if [ "$BEHIND" -gt 0 ]; then
PULL_OUT=$(git pull --ff-only 2>&1)
PULL_EXIT=$?
if [ $PULL_EXIT -eq 0 ]; then
echo "✅ [Unity sync] $BEHIND 커밋 pull 완료 — $UNITY_ROOT"
else
echo "⚠️ [Unity sync] pull 실패 (충돌·manual merge 필요): $UNITY_ROOT"
echo "$PULL_OUT" | head -3
fi
else
echo "✅ [Unity sync] 최신 상태 — $UNITY_ROOT"
fi
exit 0