#!/bin/bash
CPWD=$(cd "$(dirname "$0")"; pwd)
os_version=$(uname -r | awk -F"el" '{print $2}' | awk -F"." '{print $1}')
BIOS_Ver=$(dmidecode -t 0 | awk '/Version/{print $NF}' | sed 's/\s*//g')
Pro_name=$(ipmitool fru print 0 | awk -F":" '/Product Name/{print $NF}' | sed 's/^\s*//g')
cpu_model=$(lscpu | grep "Model name:" | awk -F: '{print $2}' | sed 's/^[ \t]*//' | awk -F' ' '{for (i=1; i<=NF; i++) if ($i ~ /^[0-9]+$/) print $i}')

if [ -z "$cpu_model" ]; then
    echo "No model number found."
    exit 1
fi

last_digit=${cpu_model: -1}

update_bios_cfg() {
    local config_file=$1
    if [[ "${os_version}" == "7" ]] && [[ "${BIOS_Ver}" == "L3.60E" ]]; 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 [[ "${Pro_name}" == "SuperSvr G5208-A" ]] && [[ "$last_digit" == "2" ]]; then
    update_bios_cfg "G5208-A01_20250412_A2_Legacy.cfg"
#elif [[ "${Pro_name}" == "SuperSvr G5208-A" ]] && [[ "$last_digit" == "3" ]]; then
#    update_bios_cfg "G5208-A01_20241029_A3_UEFI.cfg"
#elif [[ "${Pro_name}" == "ESC8000A-E12" ]]; then
#    ./SCELNX_64_5.05.01.0002_2021 /i /s ESC8000A-E12_20240510.cfg 
     

else
    echo "this machine don't have BIOScfg file"
    exit 1
fi
