#!/bin/bash

# source /ucloud/exports.ini

# To update kernel of BF or not,It's up to "BFKernel_Flag".
# BF 1st Generation -->MT416842.
# BF 2nd Generation -->MT42822.
Card_Info=$(lspci -nn -d 15b3::0604 )
if [[ $Card_Info =~ "MT416842" ]];then
    BfKernel_Flag=1 
elif [[ $Card_Info =~ "MT42822" ]];then
    BfKernel_Flag=2
elif [[ $Card_Info =~ "MT43244" ]];then
    BfKernel_Flag=3
fi

_install() {
    if [[ $BFFLAG = 0 ]] || [[ $BfKernel_Flag -ne 1 ]];then
        return 0
    fi
    wget -P $BASEDIR -c http://softlib.service.ucloud.cn/usa/driver/bf1_hw_offload_issue_online_update_20210408.tgz > /dev/null 2>&1
    tar xf $BASEDIR/bf1_hw_offload_issue_online_update_20210408.tgz -C $BASEDIR/
    cd $BASEDIR/bf1_hw_offload_issue_online_update_20210408/
    bash update.sh 
    result=$?
    service network stop
    ifup bond0
    ifup net2
    cd $BASEDIR/modules
    if [[ $result -ne 0 ]];then
        _check="FAIL"
        PRINT_ERR "[ERROR] update-bluefield-kernel-module run update.sh failed"
    fi
    return $result
}

_check() {
    _check="PASS"
}
