#!/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}" == "06.03.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}" == "R8428 G12" ]]; then
    update_bios_config "R8428_G12_250516_EFI.cfg"
else
    echo "This ${PRODUCT_NAME} does not have a BIOS configuration file."
    exit 1
fi


