#!/bin/bash # mirror.techlabs.co.kr 동기화 상태 확인 스크립트 # 이 스크립트는 미러의 동기화 상태를 확인합니다 set -e # 색상 정의 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}=== mirror.techlabs.co.kr 동기화 상태 확인 스크립트 ===${NC}" echo "" # 미러 상태 정보 가져오기 echo -e "${YELLOW}미러 서버 상태 정보를 가져오는 중...${NC}" # API 상태 확인 함수 check_api_status() { echo -e "${BLUE}미러 서버 API를 통한 상태 확인...${NC}" # 미러 상태 API 호출 if wget -q -O /tmp/mirror_status.json "https://mirror.techlabs.co.kr/mirror_status.json" 2>/dev/null; then echo -e "${GREEN}✓ 미러 상태 정보를 성공적으로 가져왔습니다${NC}" # jq가 있는지 확인 if command -v jq &> /dev/null; then # jq로 JSON 파싱 echo -e "\n${YELLOW}== 미러 저장소 상태 요약 ==${NC}" echo -e "${BLUE}마지막 확인 시간:${NC} $(jq -r '.last_check' /tmp/mirror_status.json)" echo "" # 저장소별 상태 출력 for repo in $(jq -r '.repos | keys[]' /tmp/mirror_status.json); do status=$(jq -r ".repos.\"${repo}\".status" /tmp/mirror_status.json) message=$(jq -r ".repos.\"${repo}\".message" /tmp/mirror_status.json) last_sync=$(jq -r ".repos.\"${repo}\".last_sync" /tmp/mirror_status.json) # 상태에 따라 색상 결정 if [ "$status" = "success" ]; then echo -e "${GREEN}✓ ${repo}:${NC} ${message} (마지막 동기화: ${last_sync})" elif [ "$status" = "syncing" ]; then echo -e "${BLUE}⟳ ${repo}:${NC} ${message}" elif [ "$status" = "outdated" ]; then echo -e "${YELLOW}⚠ ${repo}:${NC} ${message} (마지막 동기화: ${last_sync})" else echo -e "${RED}✗ ${repo}:${NC} ${message}" fi done else echo -e "${YELLOW}jq가 설치되어 있지 않아 JSON을 파싱할 수 없습니다.${NC}" echo -e "${YELLOW}수동으로 확인하려면: cat /tmp/mirror_status.json${NC}" fi rm -f /tmp/mirror_status.json else echo -e "${RED}✗ 미러 상태 정보를 가져올 수 없습니다. 개별 저장소를 확인합니다.${NC}" check_individual_repos fi } # 개별 저장소 확인 함수 check_individual_repos() { echo -e "\n${YELLOW}== 개별 저장소 타임스탬프 확인 ==${NC}" # 타임스탬프 파일 체크 함수 check_timestamp() { local repo=$1 local repo_url=$2 echo -e "${BLUE}[${repo}] 저장소 확인 중...${NC}" # last-updated 파일 또는 타임스탬프 확인 if wget -q --spider "${repo_url}/last-updated" || wget -q --spider "${repo_url}/timestamp" || wget -q --spider "${repo_url}/project/trace/${repo}"; then # 타임스탬프 파일 다운로드 시도 if wget -q -O /tmp/timestamp_${repo} "${repo_url}/last-updated" 2>/dev/null || wget -q -O /tmp/timestamp_${repo} "${repo_url}/timestamp" 2>/dev/null || wget -q -O /tmp/timestamp_${repo} "${repo_url}/project/trace/${repo}" 2>/dev/null; then # 타임스탬프 확인 local timestamp=$(cat /tmp/timestamp_${repo} | head -n 1) local current_time=$(date +%s) # 시간 포맷 변환 시도 local timestamp_epoch="" if [[ $timestamp =~ ^[0-9]{10}$ ]]; then # 이미 epoch 형식 timestamp_epoch=$timestamp else # 날짜 문자열 시도 timestamp_epoch=$(date -d "$timestamp" +%s 2>/dev/null || echo "") fi if [ -n "$timestamp_epoch" ]; then local diff=$(( (current_time - timestamp_epoch) / 3600 )) if [ $diff -lt 8 ]; then echo -e "${GREEN}✓ ${repo} 저장소가 최근 ${diff}시간 전에 업데이트되었습니다 (동기화 양호)${NC}" elif [ $diff -lt 24 ]; then echo -e "${YELLOW}⚠ ${repo} 저장소가 ${diff}시간 전에 업데이트되었습니다 (동기화 지연)${NC}" else echo -e "${RED}✗ ${repo} 저장소가 ${diff}시간 전에 업데이트되었습니다 (동기화 문제 있음)${NC}" fi else echo -e "${RED}✗ ${repo} 저장소의 타임스탬프를 해석할 수 없습니다${NC}" fi rm -f /tmp/timestamp_${repo} else echo -e "${RED}✗ ${repo} 저장소의 타임스탬프 파일을 가져올 수 없습니다${NC}" fi else echo -e "${RED}✗ ${repo} 저장소에 타임스탬프 파일이 없습니다${NC}" fi echo "" } # 각 저장소별 동기화 상태 확인 check_timestamp "ubuntu" "https://mirror.techlabs.co.kr/ubuntu" check_timestamp "kali" "https://mirror.techlabs.co.kr/kali" check_timestamp "alpine" "https://mirror.techlabs.co.kr/alpine" check_timestamp "debian" "https://mirror.techlabs.co.kr/debian" check_timestamp "proxmox" "https://mirror.techlabs.co.kr/proxmox" check_timestamp "opnsense" "https://mirror.techlabs.co.kr/opnsense" check_timestamp "rocky" "https://mirror.techlabs.co.kr/rocky" check_timestamp "AlamaLinux" "https://mirror.techlabs.co.kr/AlamaLinux" } # 먼저 API 상태를 확인하고, 실패하면 개별 저장소 확인 check_api_status echo -e "${BLUE}모든 저장소 확인 완료${NC}" echo -e "${YELLOW}문제가 있는 경우 mirror@techlabs.co.kr로 연락주세요${NC}" exit 0