#!/bin/bash

OP_SOURCE="$BASEDIR/optools"

_install() {
    if [[ $ARCH == 'x86_64' ]];then
        local rpms='lldpd jq filebeat protobuf Arcconf ssacli smartmontools mcelog nvme-cli lldpd sg3_utils'
    else
        local rpms='lldpd jq protobuf smartmontools nvme-cli lldpd sg3_utils storcli'
    fi
    code=0
    for rpm in $rpms
    do
        rpm -V --nomtime $rpm > /dev/null 2>&1
        if [[ $? -ne 0 ]];then
            PRINT_ERR "[ERROR] $rpm verify failed"
            code=1
        fi
    done

    if [[ $ARCH == 'x86_64' ]];then
        local have_miss_rpm='MegaCli perccli storcli'
        for rpm in $have_miss_rpm
        do
            if [[ `rpm -V --nomtime $rpm|wc -l` -gt 1 ]];then
                PRINT_ERR "[ERROR] $rpm verify failed"
                code=1
            fi
        done
    fi
    return $code
}


_check() {
    _check="PASS"

    if [[ $ARCH == 'x86_64' ]];then
        local rpms='lldpd jq filebeat protobuf Arcconf ssacli smartmontools mcelog nvme-cli lldpd sg3_utils'
    else
        local rpms='lldpd jq protobuf smartmontools nvme-cli lldpd sg3_utils storcli'
    fi
    for rpm in $rpms
    do
        rpm -V --nomtime $rpm > /dev/null 2>&1
        if [[ $? -ne 0 ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR] $rpm verify failed"
        fi
    done

    if [[ $ARCH == 'x86_64' ]];then
        local have_miss_rpm='MegaCli perccli storcli'
        for rpm in $have_miss_rpm
        do
            if [[ `rpm -V --nomtime $rpm|wc -l` -gt 1 ]];then
                PRINT_ERR "[ERROR] $rpm verify failed"
            fi
        done
    fi

}
