#!/bin/bash

YUMREPO_PATH=/etc/yum.repos.d
YUM_CONFIGS=$BASEDIR/configs/yum

_install () {
    rm -f $YUMREPO_PATH/*.repo
    if [[ $OS == "CentOS6" ]];then
        local ver=6
        local gpg_key=1
    elif [[ $OS == "CentOS7" ]];then
        local ver=7
        local gpg_key=2
    else
        PRINT_ERR "Not support OS '$OS'"
        return 1
    fi
    wget -P $YUMREPO_PATH http://yum.service.ucloud.cn/custom/CentOS-$ver-all.repo >/dev/null 2>&1

    cp -f $YUM_CONFIGS/$ver/RPM-GPG-KEY-ucloud-$gpg_key  /etc/pki/rpm-gpg/RPM-GPG-KEY-ucloud-$gpg_key
    yum -y -q install yum-utils >/dev/null 2>&1
    if lspci | grep -qi "mellanox" ;then
        yum-config-manager --enable mlnx >/dev/null 2>&1
    fi
}

_check () {
    _check="PASS"
    if [[ $OS == "CentOS6" ]];then
        local ver=6
        local gpg_key=1
    elif [[ $OS == "CentOS7" ]];then
        local ver=7
        local gpg_key=2
    else
        PRINT_ERR "Not support OS '$OS'"
        return 1
    fi

    if [ ! -f /etc/pki/rpm-gpg/RPM-GPG-KEY-ucloud-$gpg_key ];then
        _check="FAIL"
        PRINT_ERR "[ERROR] File /etc/pki/rpm-gpg/RPM-GPG-KEY-ucloud-$gpg_key Not Found."
    fi
    if lspci | grep -qi "mellanox" ;then
        if ! yum repolist |grep -q "^mlnx";then
            check="FAIL"
            PRINT_ERR "[ERROR] Mellanox Repo Not Enabled In Yum Repo ."
        fi
    fi
}
