#!/bin/bash
CPWD=`cd $(dirname  $0);pwd`
#os_version=`uname -r |awk -F"el" '{print $2}' |awk -F"." '{print $1}'`
kernel_pre_version=`uname -r |awk -F"." '{print $1}'`
kernel_sub_version=`uname -r |awk -F"." '{print $2}'`
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'`

MachineType=`cat /tmp/os_init/cmdb.info |grep -i MachineType|cut -d : -f 2` 

cd $CPWD

nps4_rome(){
if [[ "${Pro_name}" == "ESC8000A-E11" ]] && [[ "${BIOS_Ver}" == "0501-PUS0010-24101501" ]];then
	./SCELNX_64_5.05.01.0002_2021 /i /s ESC8000A-E11_20241019.cfg
else
	exit 1
fi
}

nps1_rome(){
if [[ "${Pro_name}" == "ESC8000A-E11" ]] && [[ "${BIOS_Ver}" == "0501-PUS0007-24041201" ]];then
	./SCELNX_64_5.05.01.0002_2021 /i /s ESC8000A-E11_20231114.cfg
else
	exit 1
fi
}

ESC8000A-E12(){
if [[ "${BIOS_Ver}" == "1002-PUS0008-24042601" ]];then
	./SCELNX_64_5.05.01.0002_2021 /i /s ESC8000A-E12_20240510.cfg
else
	exit 1
fi
}

G7666_X6_BiosConfigImport(){
# 改制前 bios版本
if [[ "${BIOS_Ver}" == "1.21.01" ]];then
	./SCELNX_64 /i /s G7666X6_biosConf_20250502.cfg
# 改制后 bios版本
elif [[ "${BIOS_Ver}" == "1.22.12" ]];then
	./SCELNX_64_5.05.01.0002_2021 /i /s G7666_X6_efi_250612.cfg
else
	exit 1
fi
}

TG679V3_BiosConfigImport(){
if [[ "${BIOS_Ver}" == "T1DMGEP08.00" ]];then
        ./SCELNX_64 /i /s TG679V3_biosConf_20250808.cfg
else
        exit 1
fi
}



if [[ "$MachineType" == "G6.U4.A2.34" ]]||[[ "$MachineType" == "G9.U4.A2.34" ]]||[[ "$MachineType" == "G2.U4.A2.34" ]] || [[ "$MachineType" == "G2.U4.A3.34" ]]||[[ "$MachineType" == "G3.U4.A2.34" ]] || [[ "$MachineType" == "G4.U4.A2.34" ]]||[[ "$MachineType" == "G5.U4.A2.34" ]]||[[ "$MachineType" == "G8.U4.A2.34" ]]||[[ "$MachineType" == "G9.U4.A2.34" ]];then
    nps4_rome
elif [[ "$MachineType" == "G1.U4.A2.34" ]] ;then
    nps1_rome
elif [[ "${Pro_name}" == "ESC8000A-E11" ]] && [[ "${BIOS_Ver}" == "1103-PUS0010-24090501" ]];then
    ./SCELNX_64_5.05.01.0002_2021 /i /s ESC8000A-E11_milan_efi_20240927.cfg
elif [[ "$Pro_name" == "ESC8000A-E12" ]] ;then
    ESC8000A-E12
elif [[ "$Pro_name" == "G7666 X6" ]] ;then
    G7666_X6_BiosConfigImport
    echo "5090 platform Watting CFI BIOS&BMC Version...."
elif [[ "$Pro_name" == "TG679V3" ]] ;then
    TG679V3_BiosConfigImport
else
    exit 1	
fi
