#!/bin/bash

parent_dir="/root/my_webs/static/SDDB/storage"
missing_count=0

echo "检查目录: $parent_dir"
echo "------------------------"

# 遍历所有 SD* 目录
for sd_dir in "$parent_dir"/SD*; do
    if [ -d "$sd_dir" ]; then
        sd_id=$(basename "$sd_dir")
        echo "检查: $sd_id"
        
        # 遍历 SD* 下的所有子目录
        for sub_dir in "$sd_dir"/*; do
            if [ -d "$sub_dir" ]; then
                sub_id=$(basename "$sub_dir")
                
                # 检查 plotdata.csv 是否存在
                if [ ! -f "$sub_dir/plotdata.csv" ]; then
                    echo -e "  \033[1;31m缺少: $sd_id/$sub_id\033[0m"
                    ((missing_count++))
                else
                    echo -e "  \033[1;32m存在: $sd_id/$sub_id\033[0m"
                fi
            fi
        done
        echo "---"
    fi
done

echo "------------------------"
echo "检查完成"
echo "总缺少 plotdata.csv 的子目录数: $missing_count"

if [ "$missing_count" -gt 0 ]; then
    exit 1
else
    exit 0
fi
