#!/bin/bash
set +x

CurInspectNum="408"
G_INSPECT_MMLPATH="/opt/product/snas/script/inspect_mml"
source "${G_INSPECT_MMLPATH}/CheckItems"
source "${G_INSPECT_MMLPATH}/CommonFunc.sh"
CurInspectFun="$(GetInspectType $CurInspectNum)"
RESULTFILE="/tmp/tmpResult${CurInspectFun}"
>"${RESULTFILE}"

LOG_FILE="/var/log/inspect.log"

function LOG
{
   time=$(date)
   echo [${time}][$$][$CurInspectFun]$@ >> $LOG_FILE
}

function CheckSystemDiskCfg
{
    local isPass=0
    local checkFile="/opt/print_system_disk_list.sh"
    local bakFile="/opt/print_system_disk_list.sh.bak"
    local platform=$( arch )
    local result="CHECK_PASS"
    if [ ${platform} != "aarch64" ];then
        result="NO_NEED_CHECK"
        echo "NodeType:${platform}||CheckResult:${result}" >>${RESULTFILE} 2>&1
    else
        cat ${checkFile} | grep 'sysDiskGotVer=[0-9]' > /dev/null 2>&1
        if [ $? -ne 0 ];then
            if [ ! -f /opt/inspect/toolkit.app.zh.version ] || [ "$(cat /opt/inspect/toolkit.app.zh.version | grep true)" != "" ];then
                if [ -f "${G_INSPECT_MMLPATH}/print_system_disk_list.sh" ];then
                    cp ${checkFile} ${bakFile}
                    cp ${G_INSPECT_MMLPATH}/print_system_disk_list.sh ${checkFile}
                    cat ${bakFile} >>${checkFile}
                    chown root:root ${checkFile}
                    chmod 755 ${checkFile}
                    cat ${checkFile} | grep 'sysDiskGotVer=[0-9]' > /dev/null 2>&1
                    if [ $? -ne 0 ];then
                        isPass=1
                        result="CHECK_FAIL. cp ${G_INSPECT_MMLPATH}/print_system_disk_list.sh ${checkFile}"
                    else
                        result="CHECK_SUCCESS"
                    fi
                else
                    isPass=1
                    result="File does not exist."
                    echo "[ERR]INFO:The file ${G_INSPECT_MMLPATH}/print_system_disk_list.sh does not exist." >>${RESULTFILE}
                fi
            else
                result="CHECK_DONE. cp ${G_INSPECT_MMLPATH}/print_system_disk_list.sh ${checkFile}"
            fi
        fi
        echo "NodeType:${platform}||CheckResult:${result}" >>${RESULTFILE} 2>&1
    fi
    echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
}

CheckSystemDiskCfg
exit 0