#!/bin/bash

echo "********Server requirements checking*********"
#Check OS Version
os_version=`cat /etc/issue|awk -F. '{print $1}'`
if [[ $os_version == "Ubuntu 22" ]]; then
	echo "OS version checking ................................. OK!"
else
	echo "OS version checking ................................. faild"
	echo "The current os version is $os_version, the required version is Ubuntu 20 "
fi

#Check vfio
vfio_info=`cat /lib/modules/$(uname -r)/modules.builtin | grep vfio`
if [[ $vfio_info != "" ]];then
	echo "Linux kernel support vfio checking .................. OK!"
else
	echo "Linux kernel support vfio checking .................. faild"
	echo "Vfio drivers not built into Linux kernel, please check it!"
fi

#Check CPU IOMMU Support
cpu_info=`egrep -o "vmx|svm"  /proc/cpuinfo`
if [[ $cpu_info != "" ]];then
	echo "CPUIOMMU Support checking ........................... OK!"
else
	echo "CPU IOMMU Support checking .......................... faild!"
	echo "Please check BIOS settings"
fi

#Check GPU 
gpu_info=`lspci -nnk|grep NVIDIA`
if [[ $gpu_info != "" ]];then
        echo "GPU checking ........................................ OK!"
else
        echo "GPU checking ........................................ faild!"
        echo "No GPU card found on this server, please check it"
fi

#Check Disks Number
disk_num=`lsblk --output NAME,TYPE |grep disk |wc -l`
if [[ $disk_num == "4" ]];then
        echo "Disks Number checking ............................... OK!"
else
        echo "Disks Number checking ............................... faild!"
        echo "The number of disks does not meet requirements, please check it"
fi

