#!/bin/bash
###################################################################################
#V1.0
#Author:Sviper.Yan
#Used to import Inspur server BIOS setting file.
#Date:2022/02/17
##################################################################################

#ManufacturerType=$1
#action=$2

CPWD=`cd $(dirname  $0);pwd`
cd $CPWD
Name=`cat /tmp/os_init/cmdb.info |grep 'ManufactureType'|awk -F : '{print $NF}'`
os_version=`cat /etc/redhat-release |awk '{print $3}' |awk -F"." '{print $1}'`
Architecture=`uname -r |awk -F "." '{print $6}'`
Pro_name=`ipmitool fru print 0 |awk -F":" '/Product Name/{print $NF}' |sed 's/^\s*//g'`
#Pro_name=`cat /tmp/os_init/cmdb.info |grep 'ManufactureType'|awk -F : '{print $NF}'`
CPU=`lscpu|grep 'Model name: '|awk '{print $6}'`

#import file for use
INSPUR_NF5170M4_CfgFile="NF5170M4_20211220.cfg"
INSPUR_NF5180M4_CfgFile="NF5180M4_20211220.cfg"
INSPUR_NF5280M4_CfgFile="NF5280M4_20211220.cfg"
INSPUR_NF5460M4_CfgFile="NF5460M4_20211220.cfg"
INSPUR_SA5112M4_CfgFile="SA5112M4_20211220.cfg"
INSPUR_SA5212M4_CfgFile="SA5212M4_20211209.cfg"
INSPUR_NF5466M5_CfgFile="NF5466M5_20211220.cfg"
INSPUR_NF5468M5_CfgFile="NF5468M5_20211220.cfg"
INSPUR_SA5112M5_CfgFile="SA5112M5_20211220.cfg"
INSPUR_NF5180M5_CfgFile="NF5180M5_20230609.cfg"
INSPUR_SA5212M5_CfgFile="SA5212M5_20230915.cfg"
INSPUR_SA5212M6_CfgFile="SA5212M6_20220906.cfg"
INSPUR_NF5260M6_CfgFile="NF5260M6_20220906.cfg"
INSPUR_NF5280R6_CfgFile="NF5280R6_20220221.cfg"
INSPUR_NF5688M6_CfgFile="NF5688M6_20230915.cfg"
INSPUR_NF5568M4_CfgFile="NF5568M4_20240417.cfg"
INSPUR_SA5211M5_CfgFile="SA5211M5_20240920.cfg"
INSPUR_SA5212M6_efiCfgFile="SA5212M6_20250515_EFI.cfg"


gcc_4_9_2_inst(){
if [  ! -e /usr/bin/expect ];then
        yum install expect -y
else
        echo "expect tool is already installed"
fi
yum install policycoreutils-python.x86_64 scl* devtoolset-3-runtime devtoolset-3-binutils devtoolset-3-gcc devtoolset-3-libstdc++ devtoolset-3-gcc-c++ -y
}
if [[ ${os_version} =~ 6 ]] && [[ ${Architecture} == "x86_64" ]];then
        gcc_4_9_2_inst
        scl enable devtoolset-3 
	./SCELNX_64 /makedrv
	./SCELNX_64 /i /s `eval echo '$'"INSPUR_${Name}_CfgFile"`
elif [[ "${Pro_name}" == "NF5568M4" ]];then
	./sum -c ChangeBiosCfg --file NF5568M4_20240417.cfg
	exit $?
elif [[ "${Pro_name}" == "NF5260M6" ]] || [[ "${Pro_name}" == "SA5212M6" ]];then
        if [ -d '/sys/firmware/efi' ];then
	 ./SCELNX_64 /i /s  $INSPUR_SA5212M6_efiCfgFile
	else
	 ./SCELNX_64 /i /s  $INSPUR_SA5212M6_CfgFile
	fi	

elif [[ ${os_version} == "release" ]] && [[ ${Architecture} == "x86_64" ]];then
	if [ $? -eq 0 ];then
	./SCELNX_64 /makedrv
	./SCELNX_64 /i /s `eval echo '$'"INSPUR_${Name}_CfgFile"`
	fi	
elif [[ ${os_version} == "release" ]] && [[ ${Architecture} == "aarch64" ]];then
	./SceLnxArm /i /s `eval echo '$'"INSPUR_${Name}_CfgFile"`
#elif [[ ${Name} == "SA5212M6" ]] && [[ ${CPU} == "4314" ]];then
#        ./SceLnxArm /i /s ${INSPUR_SA5212M6_efiCfgFile}
fi
