#!/bin/bash

echo "=== 存储设备信息 ==="

# 收集NVME设备信息
echo "NVME设备:"
NVME_COUNT=0
NVME_CAPACITY=0
for device in $(lsblk -d -o NAME,TYPE | grep disk | awk '{print $1}'); do
    if [[ $device == nvme* ]]; then
        size=$(lsblk -d -o NAME,SIZE | grep "^$device " | awk '{print $2}')
        # 转换容量为GB
        if [[ $size == *G ]]; then
            capacity=${size%G}
        elif [[ $size == *T ]]; then
            capacity=$(echo "${size%T} * 1024" | bc)
        else
            capacity=0
        fi
        echo "  $device: $size"
        ((NVME_COUNT++))
        NVME_CAPACITY=$(echo "$NVME_CAPACITY + $capacity" | bc)
    fi
done

# 收集SATA-SSD和HDD设备信息
echo "SATA设备:"
SATA_SSD_COUNT=0
SATA_SSD_CAPACITY=0
HDD_COUNT=0
HDD_CAPACITY=0
for device in $(lsblk -d -o NAME,TYPE | grep disk | awk '{print $1}'); do
    if [[ $device == sd* ]] || [[ $device == hd* ]]; then
        # 通过ROTA判断是否为SSD（0）或HDD（1）
        rota=$(lsblk -d -o NAME,ROTA | grep "^$device " | awk '{print $2}')
        size=$(lsblk -d -o NAME,SIZE | grep "^$device " | awk '{print $2}')
        # 转换容量为GB
        if [[ $size == *G ]]; then
            capacity=${size%G}
        elif [[ $size == *T ]]; then
            capacity=$(echo "${size%T} * 1024" | bc)
        else
            capacity=0
        fi
        if [[ $rota -eq 0 ]]; then
            echo "  $device: $size (SSD)"
            ((SATA_SSD_COUNT++))
            SATA_SSD_CAPACITY=$(echo "$SATA_SSD_CAPACITY + $capacity" | bc)
        else
            echo "  $device: $size (HDD)"
            ((HDD_COUNT++))
            HDD_CAPACITY=$(echo "$HDD_CAPACITY + $capacity" | bc)
        fi
    fi
done

# 汇总信息输出
echo "=== 汇总信息 ==="
echo "CPU核数: $(nproc)"
echo "内存大小(GB): $(free -g | grep Mem: | awk '{print $2}')"
echo "NVME数量: $NVME_COUNT"
echo "NVME容量(GB): $NVME_CAPACITY"
echo "SATA-SSD数量: $SATA_SSD_COUNT"
echo "SATA-SSD容量(GB): $SATA_SSD_CAPACITY"
echo "HDD数量: $HDD_COUNT"
echo "HDD容量(GB): $HDD_CAPACITY"