#!/bin/bash
set +x

CurInspectNum="503"
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 SystemDiskCfgRepair
{
    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="PASS"
    if [ ${platform} != "aarch64" ];then
        result="NO_NEED_CHECK"
    else
        cat ${checkFile} | grep 'sysDiskGotVer=[0-9]' > /dev/null 2>&1
        if [ $? -ne 0 ];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
        fi
    fi
    sed -i 's/^fi#/fi #/g'  ${checkFile}
    echo "NodeType:${platform}||CheckResult:${result}" >>${RESULTFILE} 2>&1
    echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
}

SystemDiskCfgRepair
exit 0