#!/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}'`
CV=`ipmitool fru print 0 |awk -F":" '/Chassis Part Number/{print $NF}' |sed 's/^\s*//g'`
BIOS_Ver=`dmidecode -t 0 |awk '/Version/{print $NF}'`
Pro_name=`ipmitool fru print 0 |awk -F":" '/Product Name/{print $NF}' |sed 's/^\s*//g'`

gcc_4_9_2_inst(){
yum install policycoreutils-python.x86_64 scl* -y
rpm -ivh \
         devtoolset-3-runtime-3.1-12.el6.x86_64.rpm \
         devtoolset-3-binutils-2.24-18.el6.x86_64.rpm \
         devtoolset-3-gcc-4.9.2-6.2.retpoline.el6.x86_64.rpm \
         devtoolset-3-libstdc++-devel-4.9.2-6.2.retpoline.el6.x86_64.rpm \
         devtoolset-3-gcc-c++-4.9.2-6.2.retpoline.el6.x86_64.rpm
}

#gcc_4_9_2_inst

PR2710P(){
if [[ "${os_version}" = "7" ]] && [[ "${BIOS_Ver}" = "ES165IPL2.17" ]];then
	if [[ "${kernel_pre_version}" = "4" ]] && [[ "${kernel_sub_version}" = "1" ]];then
		./SCELNX_64 /i /s PR2710P_20220218.cfg --skip_bbs
  	else [[ "${kernel_pre_version}" = "4" ]] && [[ "${kernel_sub_version}" = "14" ]]
		./SCELNX_64_4.14 /i /s PR2710P_20220218.cfg --skip_bbs
	fi
fi      
}

PR4908P(){
 ./sum -c ChangeBiosCfg --file PR4908P_20231019.cfg --skip_bbs --skip_unknown
 exit $?

}

active_key(){
 mac=`ipmitool lan print 1|grep -i "MAC Address"|awk  '{print $NF}'`
 key=`echo -n "$mac" | xxd -r -p | openssl dgst -sha1 -mac HMAC -macopt hexkey:8544E3B47ECA58F9583043F8 | awk '{print $2}' | cut -c 1-24`
 real_key=`echo $key| sed 's/.\{4\}/&-/g'|sed 's/\-$//'`
 ./sum -c  ActivateProductKey --key $real_key
}


if [[ "${Pro_name}" == "PR2710P" ]];then
	active_key        
	PR2710P
fi

if [[ "${Pro_name}" == "PR4908P" ]];then
        active_key
	PR4908P
fi
