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

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
}

if [[ "${os_version}" = "6" ]];then
        cd $CPWD
        gcc_4_9_2_inst
	if [[ ${kernel_pre_version} == 4 ]];then
		if [[ ${kernel_sub_version} == 1 ]];then
        		scl enable devtoolset-3 "./afulnx_64 bios.bin /p /b /n /x /l /me"
		elif [[ ${kernel_sub_version} == 14 ]];then
			scl enable devtoolset-3 "./afulnx_64_4.14 bios.bin /p /b /n /x /l /me"
		fi
	elif [[ ${kernel_pre_version} == 5 ]];then
		if [[ ${kernel_sub_version} == 10 ]];then
			scl enable devtoolset-3 "./afulnx_64_5.14.03.0039_2021 bios.bin /p /b /n /x /l /me"
		fi
	fi
elif [[ "${os_version}" = "7" ]];then
	cd $CPWD
	if [[ ${kernel_pre_version} == 4 ]];then
                if [[ ${kernel_sub_version} == 1 ]];then
			./afulnx_64 /makedrv
			./afulnx_64 bios.bin /p /b /n /x /l /me
		elif [[ ${kernel_sub_version} == 14 ]];then 
			./afulnx_64_4.14 /makedrv
			./afulnx_64_4.14 bios.bin /p /b /n /x /l /me
		fi
	elif [[ ${kernel_pre_version} == 5 ]];then
		if [[ ${kernel_sub_version} == 10 ]];then
                	./afulnx_64_5.14.03.0039_2021 bios.bin /p /b /n /x /l /me
		fi
	fi
fi
