#!/bin/bash

# 使用: ./check_sync.sh php

REPO_NAME="${1:-php}"  # 默认检查 php 仓库
LOG_FILE="/var/log/sury_${REPO_NAME}_rsync.log"
LOCK_FILE="/var/lock/sury_${REPO_NAME}_rsync.lock"
DEST="/opt/mirrors/sury/$REPO_NAME"

echo "===== $REPO_NAME 仓库同步状态 ====="

if [ -e "$LOCK_FILE" ]; then
    echo "状态: 同步正在进行中"
    echo "锁文件创建时间: $(stat -c %y "$LOCK_FILE")"
else
    echo "状态: 空闲"
fi

if [ -e "$DEST/.last_synced" ]; then
    echo "上次同步: $(cat "$DEST/.last_synced")"
fi

if [ -e "$LOG_FILE" ]; then
    echo -e "\n最近日志:"
    tail -n 10 "$LOG_FILE"
else
    echo "未找到日志文件"
fi
