fix: find ssh-monitor in clone via git checkout and broader search

Restore ssh-monitor from HEAD when missing on disk; try git ls-files and
find fallback; log clone root listing on failure.
This commit is contained in:
PTah
2026-05-28 08:20:37 +10:00
parent 7f4d25b91c
commit 731c50b0bc
+48 -9
View File
@@ -488,19 +488,58 @@ sync_sac_client() {
}
find_remote_ssh_monitor_path() {
REMOTE_SCRIPT_PATH="$UPDATE_DIR/$SCRIPT_NAME/src/branch/main/$SCRIPT_NAME"
ALT_REMOTE_PATH="$UPDATE_DIR/$SCRIPT_NAME/$SCRIPT_NAME"
if [ -f "$REMOTE_SCRIPT_PATH" ]; then
log_action "ssh-monitor в клоне: $REMOTE_SCRIPT_PATH (src/branch/main)"
printf '%s\n' "$REMOTE_SCRIPT_PATH"
local repo="$UPDATE_DIR/$SCRIPT_NAME"
local candidates=() git_path="" found="" p
REMOTE_SCRIPT_PATH="$repo/ssh-monitor"
ALT_REMOTE_PATH="$repo/src/branch/main/ssh-monitor"
candidates=(
"$REMOTE_SCRIPT_PATH"
"$ALT_REMOTE_PATH"
)
for p in "${candidates[@]}"; do
if [ -f "$p" ]; then
log_action "ssh-monitor в клоне: $p"
printf '%s\n' "$p"
return 0
fi
if [ -f "$ALT_REMOTE_PATH" ]; then
log_action "ssh-monitor в клоне: $ALT_REMOTE_PATH (корень репозитория)"
printf '%s\n' "$ALT_REMOTE_PATH"
done
if [ -d "$repo/.git" ]; then
if git -C "$repo" cat-file -e "HEAD:ssh-monitor" 2>/dev/null; then
if [ ! -f "$repo/ssh-monitor" ]; then
log_action "ssh-monitor есть в git HEAD, но отсутствует на диске — git checkout HEAD -- ssh-monitor"
git -C "$repo" checkout HEAD -- ssh-monitor >> "$LOG_FILE" 2>&1 || true
fi
if [ -f "$repo/ssh-monitor" ]; then
log_action "ssh-monitor восстановлен: $repo/ssh-monitor"
printf '%s\n' "$repo/ssh-monitor"
return 0
fi
log_action "WARNING: ssh-monitor не найден ни в $REMOTE_SCRIPT_PATH, ни в $ALT_REMOTE_PATH"
fi
git_path=$(git -C "$repo" ls-files 'ssh-monitor' 2>/dev/null | grep -v '^contrib/' | head -1)
if [ -z "$git_path" ]; then
git_path=$(git -C "$repo" ls-files 2>/dev/null | grep -E '/ssh-monitor$' | grep -v contrib | grep -v watchdog | head -1)
fi
if [ -n "$git_path" ] && [ -f "$repo/$git_path" ]; then
log_action "ssh-monitor в клоне (git ls-files): $repo/$git_path"
printf '%s\n' "$repo/$git_path"
return 0
fi
fi
found=$(find "$repo" -maxdepth 4 -type f -name 'ssh-monitor' ! -path '*/contrib/*' 2>/dev/null | head -1)
if [ -n "$found" ] && [ -f "$found" ]; then
log_action "ssh-monitor найден поиском: $found"
printf '%s\n' "$found"
return 0
fi
log_action "WARNING: ssh-monitor не найден в $repo"
if [ -d "$repo" ]; then
log_action "корень клона: $(ls -1 "$repo" 2>/dev/null | tr '\n' ' ')"
fi
return 1
}