#!/bin/bash

# Only For LSI_3108, LSI_3316 RaidCard

_install() {
    if [[ $VMFLAG = 1 ]];then
        return 0
    fi
}

_check() {
    _check="PASS"
    # check dell
    dmidecode -t1|grep Manufacturer|grep -q -i dell
    if [[ $? -ne 0 ]];then
        STORCLI=/opt/MegaRAID/storcli/storcli64
    else
        STORCLI=/opt/MegaRAID/perccli/perccli64
    fi
    
    if [[ $VMFLAG = 1 ]];then
        return 0
    fi
    $STORCLI /call/eall/sall show|grep -q SSD
    if [[ $? -eq 0 ]];then
        DataDiskType='SSD'
    else
        DataDiskType='HDD'
    fi
    local SysDiskSize=$(grep -r UCLOUD_SYS_DISK_SIZE /ucloud/exports.ini|awk -F '=' '{print $2}'|tail -n1)
    local DataDisk_512e=$($STORCLI /call/eall/sall show all|grep 'Physical Sector Size'|grep -c '4 KB')
    
    if [[ $DataDiskType == "HDD" ]] && [[ $RaidChip == "3108" || $RaidChip == "3316" ]];then
        if [[ $CpuModel == "CpuV3" ]] && [[ $DataDisk_512e -ne 0 ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR] DataDisk Is 512e Format."
        elif [[ $CpuModel == "CpuV4" ]] && [[ $DataDisk_512e -eq 0 ]];then
            if [[ $MachineType == 'H1.U2.V4.12.22' ]]
            then
                return 0
            fi
            _check="FAIL"
            PRINT_ERR "[ERROR] DataDisk Is Not 512e Format."
        elif [[ $CpuModel == "CpuV5" ]] && [[ $DataDisk_512e -eq 0 ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR] DataDisk Is Not 512e Format."
        fi 
    fi
}
