-
Notifications
You must be signed in to change notification settings - Fork 3
/
nvidia
executable file
·211 lines (195 loc) · 6.2 KB
/
nvidia
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
# Define some color variables
TEAL='\e[1;38;2;0;128;128m'
PEACH='\e[1;38;2;255;204;153m'
GREEN='\033[1m\033[38;2;0;255;0m'
RED='\033[1m\033[38;5;196m'
NC='\033[0m' # No Color
# Function to display a menu with options
display_menu() {
clear
echo ""
COLUMNS=$(tput cols)
t1="======================="
t2="NVIDIA Driver Manager"
printf "${TEAL}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
printf "${TEAL}%*s\n${NC}" $(((${#t2} + $COLUMNS) / 2)) "$t2"
printf "${TEAL}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
echo ""
echo -e "${PEACH}Select Your Choice:${NC}"
echo " 1. Detect NVIDIA GPU"
echo " 2. Install NVIDIA Drivers"
echo " 3. List Installed NVIDIA Packages"
echo " 4. Uninstall NVIDIA Drivers"
echo " 5. Go Back to Main Menu"
echo ""
echo -n "Enter your choice: "
}
# Function to detect NVIDIA GPU
detect_nvidia_gpu() {
lspci | grep -i nvidia >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "${GREEN}NVIDIA GPU detected.${NC}"
sleep 3
return 0
else
echo -e "${RED}No NVIDIA GPU detected.${NC}"
sleep 3
return 1
fi
}
# Function to install drivers on Debian-based distributions
install_drivers_debian() {
echo -e "${GREEN}Installing NVIDIA drivers on Debian-based system...${NC}"
sudo apt update
sudo apt install -y dkms build-essential linux-headers-$(uname -r)
sudo apt install -y nvidia-driver
echo -e "${GREEN}NVIDIA drivers installed on Debian-based system.${NC}"
sleep 1
read -rp "Press Enter to continue..."
}
# Function to install drivers on Red Hat-based distributions
install_drivers_redhat() {
echo -e "${GREEN}Installing NVIDIA drivers on Red Hat-based system...${NC}"
sudo dnf update -y
sudo dnf install -y dkms kernel-devel gcc
sudo dnf config-manager --add-repo=https://negativo17.org/repos/fedora-nvidia.repo
sudo dnf install -y nvidia-driver
echo -e "${GREEN}NVIDIA drivers installed on Red Hat-based system.${NC}"
sleep 1
read -rp "Press Enter to continue..."
}
# Function to install drivers on Arch-based distributions
install_drivers_arch() {
echo -e "${GREEN}Installing NVIDIA drivers on Arch-based system...${NC}"
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm nvidia-dkms nvidia-utils
echo -e "${GREEN}NVIDIA drivers installed on Arch-based system.${NC}"
sleep 1
read -rp "Press Enter to continue..."
}
# Function to install drivers on SUSE-based distributions
install_drivers_suse() {
echo -e "${GREEN}Installing NVIDIA drivers on SUSE-based system...${NC}"
sudo zypper refresh
sudo zypper install -y dkms kernel-default-devel gcc
sudo zypper addrepo --refresh https://download.nvidia.com/opensuse/leap/\$releasever NVIDIA
sudo zypper install -y x11-video-nvidiaG05
echo -e "${GREEN}NVIDIA drivers installed on SUSE-based system.${NC}"
sleep 1
read -rp "Press Enter to continue..."
}
# Function to install NVIDIA drivers
install_drivers() {
if detect_nvidia_gpu; then
local package_manager
if command -v apt &>/dev/null; then
package_manager="apt"
elif command -v dnf &>/dev/null; then
package_manager="dnf"
elif command -v pacman &>/dev/null; then
package_manager="pacman"
elif command -v zypper &>/dev/null; then
package_manager="zypper"
else
echo -e "${RED}Unsupported package manager.${NC}"
sleep 1
exit 1
fi
case "$package_manager" in
apt) install_drivers_debian ;;
dnf) install_drivers_redhat ;;
pacman) install_drivers_arch ;;
zypper) install_drivers_suse ;;
*)
echo -e "${RED}Unsupported package manager.${NC}"
sleep 1
exit 1
;;
esac
else
sleep 1
read -rp "Press Enter to continue..."
fi
}
# Function to list installed NVIDIA packages
list_nvidia_packages() {
echo -e "${GREEN}Listing installed NVIDIA packages...${NC}"
local package_manager
if command -v apt &>/dev/null; then
package_manager="apt"
elif command -v dnf &>/dev/null; then
package_manager="dnf"
elif command -v pacman &>/dev/null; then
package_manager="pacman"
elif command -v zypper &>/dev/null; then
package_manager="zypper"
else
echo -e "${RED}Unsupported package manager.${NC}"
sleep 1
exit 1
fi
case "$package_manager" in
apt) dpkg -l | grep -i nvidia ;;
dnf) rpm -qa | grep -i nvidia ;;
pacman) pacman -Qs nvidia ;;
zypper) zypper se --installed-only nvidia ;;
*)
echo -e "${RED}Unsupported package manager.${NC}"
sleep 1
exit 1
;;
esac
sleep 1
read -rp "Press Enter to continue..."
}
# Function to uninstall NVIDIA drivers
uninstall_nvidia_drivers() {
echo -e "${GREEN}Uninstalling NVIDIA drivers...${NC}"
local package_manager
if command -v apt &>/dev/null; then
package_manager="apt"
elif command -v dnf &>/dev/null; then
package_manager="dnf"
elif command -v pacman &>/dev/null; then
package_manager="pacman"
elif command -v zypper &>/dev/null; then
package_manager="zypper"
else
echo -e "${RED}Unsupported package manager.${NC}"
sleep 1
exit 1
fi
case "$package_manager" in
apt) sudo apt remove --purge -y nvidia-* ;;
dnf) sudo dnf remove -y nvidia-driver ;;
pacman) sudo pacman -Rns --noconfirm nvidia-dkms nvidia-utils ;;
zypper) sudo zypper rm -y x11-video-nvidiaG05 ;;
*)
echo -e "${RED}Unsupported package manager.${NC}"
sleep 1
exit 1
;;
esac
echo -e "${GREEN}Task completed.${NC}"
sleep 1
read -rp "Press Enter to continue..."
}
# Function to go back to main menu
main_menu() {
chmod +x manager
./manager
}
# Main loop
while true; do
display_menu # Display the menu
read -r choice
case $choice in
1) detect_nvidia_gpu ;;
2) install_drivers ;;
3) list_nvidia_packages ;;
4) uninstall_nvidia_drivers ;;
5) main_menu ;;
*) echo -e "${RED}Invalid choice. Please try again.${NC}" && sleep 3 ;;
esac
done