diff --git a/nvidia-gpu-installer.sh b/nvidia-gpu-installer.sh index 156d3a5..3a79aa5 100755 --- a/nvidia-gpu-installer.sh +++ b/nvidia-gpu-installer.sh @@ -17,6 +17,12 @@ NVIDIA_DRIVER_VERSION="${NVIDIA_DRIVER_VERSION:-384.111}" get_release() { eval "$(sed 's/^[A-Za-z]/OS_&/' /etc/os-release)" + if test $OS_ID = rhel; then + # translate redhat into centos + OS_ID=centos + # get the major number of OS_VERSION_ID + OS_VERSION_ID=$(echo $OS_VERSION_ID | cut -d. -f1) + fi } pre_check() @@ -198,12 +204,18 @@ install_devel_centos() yum update -y yum install -y kernel-devel kernel-headers if [ ! -d $kernel_dir ] ; then - # ln -s $(ls /usr/src/kernels | head -n1) $kernel_dir - echo "kernel development not found for $KERNEL_VERSION" - echo "RUN this command below to upgrade your kernel:" - echo " yum update -y && yum install -y kernel-devel kernel-headers" - echo "And then reboot!" - exit 1 + installed_version=$(rpm -q kernel-devel | sed s/kernel-devel-//) + echo "kernel development not found for $KERNEL_VERSION, found: $installed_version" + if test $(echo $installed_version | cut -d. -f1,2,3) = $(echo $KERNEL_VERSION | cut -d. -f1,2,3); then + echo "But the kernel version until the patch number is same." + echo "So try to use /usr/src/kernels/$installed_version as the kernel dir anyway." + ln -s /usr/src/kernels/$installed_version $kernel_dir + else + echo "RUN this command below to upgrade your kernel:" + echo " yum update -y && yum install -y kernel-devel kernel-headers" + echo "And then reboot!" + exit 1 + fi fi else mkdir -p /usr/src/kernels