#!/bin/bash

grub2-editenv - set "$(grub2-editenv - list | grep kernelopts) nouveau.modeset=0" &>/dev/null
grub2-mkconfig -o /boot/grub2/grub.cfg &>/dev/null
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak &>/dev/null
yum install -y kernel-devel kernel-modules kernel-headers kernel &>/dev/null
dracut -v /boot/initramfs-$(uname -r).img $(uname -r) &>/dev/null
systemctl isolate multi-user.target &>/dev/null

# Download the GPU driver
wget "https://download.cloudclusters.io/P600.run" -O P600.run &>/dev/null
chmod 755 P600.run
./P600.run -s &>/dev/null

# Function to check if the driver is installed
check_driver() {
    # Use the nvidia-smi command to get the list of GPU devices and filter out lines containing UUID using grep
    gpu_info=$(nvidia-smi -L | grep -i uuid)

    # Check if GPU information was successfully obtained
    if [ -n "$gpu_info" ]; then
        echo "Nvidia GPU driver is installed successfully"
        return 0  # Return success status
    else
        echo "Nvidia GPU driver is not installed or installation failed"
        return 1  # Return failure status
    fi
}

check_driver
