#!/bin/bash

SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)"
OS_VERSION=$(uname -r | awk -F"el" '{print $2}' | awk -F"." '{print $1}')
BIOS_VERSION=$(dmidecode -t 0 | awk '/Version/{print $NF}' | tr -d '[:space:]')
PRODUCT_NAME=$(ipmitool fru print 0 | awk -F":" '/Product Name/{print $NF}' | sed 's/^\s*//g')


update_bios_config() {
    local config_file=$1
    if [[ "${OS_VERSION}" == "7" ]]  && [[ "${BIOS_VERSION}" == "14.03.03" ]]; then
        ./SCELNX_64_5.05.01.0002_2021 /i /s "$config_file"
    elif [[ "${OS_VERSION}" == "7" ]]  && [[ "${BIOS_VERSION}" == "T1DMGEP09.00" ]]; then
        ./SCELNX_64_5.05.01.0002_2021 /i /s "$config_file"
    else
        echo "BIOS update not applicable for this system configuration."
        exit 1
    fi
}

if [[ "${PRODUCT_NAME}" == "Chaoqiang N810T A2" ]]; then
    update_bios_config "Chaoqiang_N810T_A2_250526_EFI.cfg"
elif [[ "${PRODUCT_NAME}" == "D870T" ]]; then
    update_bios_config "iSoftStone_D870T_251106_EFI.cfg"
else
    echo "This ${PRODUCT_NAME} does not have a BIOS configuration file."
    exit 1
fi


