Skip to content

Commit

Permalink
Merge pull request #11 from bash-bandicoot/coding/ubuntu
Browse files Browse the repository at this point in the history
removed nvidia-prime, added nvidia-persistenced
  • Loading branch information
bash-bandicoot authored Nov 25, 2024
2 parents 8c52667 + 0f155f3 commit 91288ad
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions nv_driver_cuda_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ CHECK_LAPTOP3=$(dmidecode -t chassis | grep Convertible >/dev/null); CHECK_LAPTO
SB_STATE=$(mokutil --sb-state | grep enabled >/dev/null); SB_STATE=$?
IS_CUDA_KEYRING=$(dpkg -l | grep cuda-keyring >/dev/null); IS_CUDA_KEYRING=$?

function nv_cuda ()
function nv_cuda_deb ()
{
while true; do
read -rp "[1] Install NVIDIA CUDA toolkit, NVIDIA GPU driver, docker, and nvidia-container-toolkit
[2] Install NVIDIA CUDA Toolkit and NVIDIA GPU driver
read -rp "[1] Install NVIDIA GPU driver, NVIDIA CUDA toolkit, docker, and nvidia-container-toolkit
[2] Install NVIDIA GPU driver and NVIDIA CUDA Toolkit
[3] Install NVIDIA GPU driver
[4] Uninstall NVIDIA CUDA toolkit and NVIDIA GPU driver
[4] Uninstall NVIDIA GPU driver
[E] Exit
Your choice: " -a array
for choice in "${array[@]}"; do
Expand Down Expand Up @@ -73,9 +73,12 @@ fi

echo -e "${YELLOW}Installing CUDA toolkit, NVIDIA driver, docker, and nvidia-container-toolkit. Please wait...${ENDCOLOR}"
apt update
apt install cuda-toolkit "$(nvidia-detector)" "$(nvidia-detector | sed 's/driver/dkms/g')" nvidia-prime docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin nvidia-container-toolkit -y
apt -y install cuda-toolkit "$(nvidia-detector)" "$(nvidia-detector | sed 's/driver/dkms/g')" docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin nvidia-container-toolkit
nvidia-ctk runtime configure --runtime=docker
systemctl enable docker
if [[ $CHECK_LAPTOP -eq 0 || $CHECK_LAPTOP2 -eq 0 || $CHECK_LAPTOP3 -eq 0 ]]; then
sytemctl disable nvidia-persistenced
fi
echo -e "${GREEN}Done! Please reboot your computer.${ENDCOLOR}"
sleep 1
exit 0
Expand All @@ -99,10 +102,10 @@ fi
echo -e "${YELLOW}Installing CUDA toolkit and NVIDIA driver. Please wait...${ENDCOLOR}"
sleep 1
apt update
apt install cuda-toolkit "$(nvidia-detector)" "$(nvidia-detector | sed 's/driver/dkms/g')" nvidia-prime -y
if [[ $CHECK_LAPTOP -eq 0 || $CHECK_LAPTOP2 -eq 0 || $CHECK_LAPTOP3 -eq 0 ]]; then
prime-select on-demand
fi
apt -y install cuda-toolkit "$(nvidia-detector)" "$(nvidia-detector | sed 's/driver/dkms/g')"
if [[ $CHECK_LAPTOP -eq 0 || $CHECK_LAPTOP2 -eq 0 || $CHECK_LAPTOP3 -eq 0 ]]; then
sytemctl disable nvidia-persistenced
fi
echo -e "${GREEN}Done! Please reboot your computer.${ENDCOLOR}"
sleep 1
exit 0
Expand All @@ -111,20 +114,20 @@ exit 0
echo -e "${YELLOW}Installing latest NVIDIA driver. Please wait...${ENDCOLOR}"
sleep 1
apt update
apt -y install "$(nvidia-detector)" "$(nvidia-detector | sed 's/driver/dkms/g')" nvidia-prime
if [[ $CHECK_LAPTOP -eq 0 || $CHECK_LAPTOP2 -eq 0 || $CHECK_LAPTOP3 -eq 0 ]]; then
prime-select on-demand
fi
apt -y install "$(nvidia-detector)" "$(nvidia-detector | sed 's/driver/dkms/g')"
if [[ $CHECK_LAPTOP -eq 0 || $CHECK_LAPTOP2 -eq 0 || $CHECK_LAPTOP3 -eq 0 ]]; then
sytemctl disable nvidia-persistenced
fi
echo -e "${GREEN}Done! Please reboot your computer.${ENDCOLOR}"
sleep 1
exit 0
;;
[4])
echo -e "${YELLOW}Removing NVIDIA CUDA toolkit and NVIDIA driver. Please wait...${ENDCOLOR}"
echo -e "${YELLOW}Removing NVIDIA driver. Please wait...${ENDCOLOR}"
sleep 1
apt remove cuda-toolkit ^nvidia-* ^libnvidia-* -y
apt -y remove ^nvidia-* ^libnvidia-*
apt autoremove --purge
apt install nvidia-container-toolkit -y
apt -y install nvidia-container-toolkit
nvidia-ctk runtime configure --runtime=docker
echo -e "${GREEN}Done! Please reboot your computer.${ENDCOLOR}"
sleep 1
Expand All @@ -142,24 +145,24 @@ done
}


if [[ $IS_NOMODESET = 0 ]];then
if [[ $IS_NOMODESET -eq 0 ]];then
sed -i 's/ nomodeset//g' /etc/default/grub
update-grub >/dev/null 2>&1
fi

if [[ $SB_STATE = 0 ]]; then
if [[ $SB_STATE -eq 0 ]]; then
mokutil --timeout 1000
fi

if dpkg --compare-versions "$UBUNTU_VER" ge "20.04" && [ $IS_NVGPU -eq 0 ]; then
service systemd-resolved restart
nv_cuda
nv_cuda_deb
elif dpkg --compare-versions "$UBUNTU_VER" lt "20.04"; then
echo -e "${RED}This OS version is no longer supported, please upgrade it to at least Ubuntu 20.04.${ENDCOLOR}"
echo -e "${RED}This Ubuntu version is no longer supported, please upgrade to at least Ubuntu 20.04.${ENDCOLOR}"
echo -e "${RED}Exiting...${ENDCOLOR}"
exit 1
elif
[[ $IS_NVGPU != 0 ]]; then
[[ $IS_NVGPU -ne 0 ]]; then
echo -e "${YELLOW}This computer does not have an NVIDIA GPU. NVIDIA GPU driver is not required.${ENDCOLOR}"
echo -e "${YELLOW}Exiting...${ENDCOLOR}"
exit 1
Expand Down

0 comments on commit 91288ad

Please sign in to comment.