#! /bin/bash

_install() {
    if [[ $RaidType = "LSI_RAID" ]];then
        # 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
        # sync time
        $STORCLI /call set time=systemtime 1>/dev/null 2>&1
        # check and set cc cron
        local timenow=$(date +%s)
        local CCDAY=$(date -d "@$(($timenow+86400 ))" +%Y/%m/%d)
        $STORCLI /call show cc|grep 'CC Operation Mode'|grep -q 'Disabled'
        if [[ $? -eq 0 ]];then
            $STORCLI /call set cc=conc starttime=$CCDAY 3 1>/dev/null 2>&1
        fi
    elif [[ $RaidType = "PMC_RAID" ]];then
        #暂时不做，P460有差异，待硬件解决
        return 0
        # check and set cc cron
        arcconf getconfig 1 ad|grep -i consistency|grep -q 'Disabled'
        if [[ $? -eq 0 ]];then
            arcconf CONSISTENCYCHECK 1 on
        fi
        # check check period
        local check_period=`arcconf getconfig 1 ad|grep -i 'consistency check period'|sed -n 's/.*:\s*\(\d*\)/\1/p'`
        if [[ $check_period -ne 14 ]];then
            echo y |arcconf CONSISTENCYCHECK 1 period 14
        fi
    fi
}

_check() {
    _check="PASS"

    if [[ $RaidType = "LSI_RAID" ]];then
        # 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
        $STORCLI /call show cc|grep 'CC Operation Mode'|grep -q 'Disabled'
        if [[ $? -eq 0 ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR] "$RaidType" RAID CARD CC NOT ON."
        fi
    elif [[ $RaidType = "PMC_RAID" ]];then
        #暂时不做，P460有差异，待硬件解决
        return 0
        # check cc cron
        arcconf getconfig 1 ad|grep -i consistency|grep -q 'Disabled'
        if [[ $? -eq 0 ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR] "$RaidType" RAID CARD CC NOT ON."
        fi
        # check check period
        local check_period=`arcconf getconfig 1 ad|grep -i 'consistency check period'|sed -n 's/.*:\s*\(\d*\)/\1/p'`
        if [[ $check_period -ne 14 ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR] "$RaidType" RAID CARD CC check period not 14."
        fi
    fi
}
