#!/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}' | xargs)


update_bios_config() {
    local config_file=$1
    if [[ "${OS_VERSION}" == "7" ]]  && [[ "${BIOS_VERSION}" == "1.05.024" ]]; then
        ./SCELNX_64 /i /d /s "$config_file"
    else
        echo "BIOS update not applicable for this system configuration."
        exit 1
    fi
}

if [[ "${PRODUCT_NAME}" == "Reech R740H" ]]; then
    update_bios_config "Reech_R740H_260204_EFI.cfg"
else
    echo "This ${PRODUCT_NAME} does not have a BIOS configuration file."
    exit 1
fi


