-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
nvidia-driver.plg
442 lines (364 loc) · 17 KB
/
nvidia-driver.plg
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "nvidia-driver">
<!ENTITY author "ich777">
<!ENTITY version "2024.12.08">
<!ENTITY launch "Settings/nvidia-driver">
<!ENTITY gitURL "https://github.com/&author;/unraid-&name;/raw/master">
<!ENTITY pluginURL "&gitURL;/&name;.plg">
<!ENTITY md5 "e6ec2dd2f61754b62b5eabb87324f61c">
<!ENTITY plugin "/boot/config/plugins/&name;">
<!ENTITY emhttp "/usr/local/emhttp/plugins/&name;">
<!ENTITY packages "/boot/config/plugins/&name;/packages">
]>
<PLUGIN name="&name;" author="&author;" version="&version;" launch="&launch;" pluginURL="&pluginURL;" min="6.9.0-beta31" support="https://forums.unraid.net/topic/98978-plugin-nvidia-driver/">
<CHANGES>
###2024.12.08
- Display Readme and modprobe warning for OpenSource driver only up to Unraid 7.0.0-rc.1
###2024.07.10
- Fixed a bug in update check routine for Production and New Feature Branch
###2024.01.19
- Style changes
- Remove System Info from plugin page
###2023.09.03
- Fix for Unraid 6.12.4 config.toml
###2023.08.31
- If a legacy driver is chosen in the plugin settings and no local driver is found, download the newest available legacy driver on boot
###2023.07.06
- Change log level from nvidia-container-runtime from info to warning
###2023.05.16
- Bugfix for download and update check from latest driver versions if minor version numbers consist either of two or three digit version numbers
###2023.05.02
- Fixed an issue where the driver in the latest section is not detected properly if driver versions consist either of two or three digits in minor
###2023.03.02
- Always show legacy driver version 470.xx on plugin page regardless of how many drivers are available for current Unraid version
###2022.10.05
- Added Nvidia Open Source drivers (packages will be available after a bug in the Nvidia Open Source Kernel modules is fixed)
###2022.09.27a
- Bugfix re-added missing variables to plugin file
###2022.09.27
- Bugfix for Update Check not updating
###2022.09.22
- Bugfix for old package directories
###2022.08.04
- Bugfix for Latest Production and New Feature Branch downloads
###2022.08.02a
- Bugfix version numbers not displayed in notifications from automatic update
###2022.08.02
- Bugfix in Download routine, driver won't download again if download failed once
- Bugfix for automatic update, download URL was missing
###2022.07.22
- Necessary changes for unRAID 6.11+
- Plugin page improvements
- Cleanup
###2022.05.06
- When notifications via Mail is setup don't send message about download progress anymore
###2022.04.29
- Changed default driver download from Latest Production Branch back to Latest
###2022.04.11
- Removed warning messages from console on boot
###2022.01.20
- Changed default driver download from Latest to Latest Production Branch
###2021.09.17
- Fixed plugin to escape variables properly
###2021.09.15
- Added message to New Feature and Production Branch if no driver package is found for current unRAID version
###2021.07.30
- Bugfix, thanks to cybrnook
###2021.07.29
- Added Plugin Update Helper when up-/downgrading unRAID version
###2021.06.23
- Fixed error message on boot after upgrade to newer unRAID version
- Corrected a few typos
###2021.06.23
- Changed package download repo
###2021.05.19
- Added driver update notification
###2021.04.29
- Added options to select latest version from 'Production Branch' and 'New Feature Branch'
###2021.04.16
- Fixed bug where local_version wasn't updated in settings file when driver was downloaded through WebUI
- Fixed plugin showing no version numbers when drivers where not found on Github
- Show only last 8 Drivers on plugin page
###2021.03.22
- Use IP address instead of hostname for online check
- Fixed Plugin Error with fallback URL if no internet connection is available on boot
###2021.03.19
- Fixed restart message shown if the version is changed from the latest to the latest driver version number and vice versa - reported by binhex
- Driver numbers file is updated now once every 5 minutes if the Plugin page is accessed several times within a short period of time
###2021.03.17
- Added detection if unRAID is booted into GUI-Mode
###2021.03.16
- Added option to disable creation of xorg.conf file - requested by TechGeek01
###2021.03.12
- Fixed Permissions
- Added wait for network including timeout
###2021.03.10
- Fixed error when booting into GUI mode that the screen only shows blinking cursor
###2021.03.09
- Fixed Radio Buttons not showing current selected driver version - reported by binhex
- Added Fallback URL until update handling is sorted
###2021.03.07
- Added Download button to WebGUI to download the Nvidia Driver instantly if no internet connection is available at boot
- Corrected a few typos
- Display Warning message only when downloading the Nvidia Driver
###2021.03.04
- Changed download repo to Github
###2020.12.13
- Fixed bug where the plugin folder isn't removed on a failed download
###2020.11.15
- Added addtional warning to not close the window until the DONE button is displayed at the first installation
- Added link to support thread
###2020.10.27
- Added check if enough space is available on USB boot device
- Description of Plugin page and link changed
- Added driver version selection
- Added check for old packages
###2020.10.24
- Json parsing
- MD5 hash check
- Fallback to latest Nvidia version if version for current Kernel isn't found
- Fallback to local Nvidia version if no Internet connection is available or parsing of release.json failed
###2020.10.23
- Initial release
</CHANGES>
<FILE Run="/bin/bash">
<INLINE>
rm -f $(ls /boot/config/plugins/&name;/&name;*.txz 2>/dev/null|grep -v '&version;')
</INLINE>
</FILE>
<FILE Name="/boot/config/plugins/&name;/&name;-&version;.txz" Run="upgradepkg --install-new">
<URL>&gitURL;/packages/&name;-&version;.txz</URL>
<MD5>&md5;</MD5>
</FILE>
<FILE Name="&emhttp;/README.md">
<INLINE>
**Nvidia Driver**
This plugin will install the Nvidia drivers to utilize your Nvidia graphics card in your Docker container(s).
This plugin satisfies installation prerequisites of the GPU Statistics plugin from Community Apps. With both plugins installed you can display Nvidia GPU utilization on the unRAID Dashboard.
</INLINE>
</FILE>
<FILE Run="/bin/bash">
<INLINE>
download() {
#Download Nvidia Driver Package
if wget -q -nc --show-progress --progress=bar:force:noscroll -O "&packages;/${KERNEL_V%%-*}/${LAT_PACKAGE}" "${DL_URL}/${LAT_PACKAGE}" ; then
wget -q -nc --show-progress --progress=bar:force:noscroll -O "&packages;/${KERNEL_V%%-*}/${LAT_PACKAGE}.md5" "${DL_URL}/${LAT_PACKAGE}.md5"
if [ "$(md5sum &packages;/${KERNEL_V%%-*}/${LAT_PACKAGE} | awk '{print $1}')" != "$(cat &packages;/${KERNEL_V%%-*}/${LAT_PACKAGE}.md5 | awk '{print $1}')" ]; then
echo
echo "-----ERROR - ERROR - ERROR - ERROR - ERROR - ERROR - ERROR - ERROR - ERROR------"
echo "--------------------------------CHECKSUM ERROR!---------------------------------"
rm -rf &plugin; &emhttp;
exit 1
fi
echo
if [ "${LEGACY_DRV}" == "true" ]; then
sed -i "/driver_version=/c\driver_version=$(echo $LAT_PACKAGE | cut -d '-' -f2)" "&plugin;/settings.cfg"
else
sed -i '/driver_version=/c\driver_version=latest' "&plugin;/settings.cfg"
fi
echo "----Successfully downloaded Nvidia ${OS}Driver Package v$(echo $LAT_PACKAGE | cut -d '-' -f2), please wait!----"
else
echo
echo "--------------Can't download Nvidia ${OS}Driver Package v$(echo $LAT_PACKAGE | cut -d '-' -f2)-----------------"
rm -rf &plugin; &emhttp;
exit 1
fi
}
get_version() {
#If SET_DRV_V is set to anything that starts with 47, fall back to the legacy driver as latest driver
if [[ "${SET_DRV_V}" = 47* ]]; then
LAT_PACKAGE="$(wget -qO- https://api.github.com/repos/ich777/unraid-nvidia-driver/releases/tags/${KERNEL_V} | jq -r '.assets[].name' | grep "${PACKAGE}" | grep -E -v '\.md5$' | grep "\-47" | sort -V | tail -1)"
if [ -z "${LAT_PACKAGE}" ]; then
LAT_PACKAGE="$(wget -qO- https://api.github.com/repos/ich777/unraid-nvidia-driver/releases/tags/${KERNEL_V} | jq -r '.assets[].name' | grep "${PACKAGE}" | grep -E -v '\.md5$' | sort -V | tail -1)"
else
LEGACY_DRV="true"
fi
else
LAT_PACKAGE="$(wget -qO- https://api.github.com/repos/ich777/unraid-nvidia-driver/releases/tags/${KERNEL_V} | jq -r '.assets[].name' | grep "${PACKAGE}" | grep -E -v '\.md5$' | sort -V | tail -1)"
fi
if [ -z "$LAT_PACKAGE" ]; then
if [ -z "$CUR_V" ]; then
echo
echo "-----ERROR - ERROR - ERROR - ERROR - ERROR - ERROR - ERROR - ERROR - ERROR------"
echo "---Can't get latest Nvidia ${OS}driver version and found no installed local driver---"
rm -rf &plugin; &emhttp;
exit 1
else
LAT_PACKAGE=${CUR_V}
fi
fi
}
#Check if driver is already downloaded
check() {
if ! ls -1 &packages;/${KERNEL_V%%-*}/ | grep -q "${PACKAGE}" ; then
get_version
echo
echo "+=============================================================================="
echo "| WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"
echo "|"
echo "| Don't close this window with the red 'X' in the top right corner until the 'DONE' button is displayed!"
echo "|"
echo "| WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"
echo "+=============================================================================="
echo
echo "-----------------Downloading Nvidia ${OS}Driver Package v$(echo $LAT_PACKAGE | cut -d '-' -f2)------------------"
echo "----------This could take some time, please don't close this window!------------"
download
else
LAT_PACKAGE=$CUR_V
echo
echo "--------------------Nvidia ${OS}driver v$(echo $LAT_PACKAGE | cut -d '-' -f2) found locally---------------------"
fi
}
#Install driver package
install() {
/sbin/installpkg "&packages;/${KERNEL_V%%-*}/${PACKAGE}*.txz"
depmod >> /dev/null
modprobe nvidia >> /dev/null
}
activate() {
if [ "$(which Xorg 2>/dev/null)" ] && [ "$(cat /boot/config/plugins/nvidia-driver/settings.cfg | grep "disable_xconfig" | cut -d '=' -f2)" != "true" ]; then
nvidia-xconfig --output-xconfig=/etc/X11/xorg.conf --silent 2>/dev/null
fi
if [[ "$SET_DRV_V" != "latest" && "$SET_DRV_V" != "latest_prb" && "$SET_DRV_V" != "latest_nfb" ]]; then
sed -i '/update_check=/c\update_check=false' "&plugin;/settings.cfg"
fi
}
#Create settings file if not found
if [ ! -f "&plugin;/settings.cfg" ]; then
echo 'first_installation=true
driver_version=latest
disable_xconfig=false
update_check=true' > "&plugin;/settings.cfg"
fi
#Add update check entry if not exists
if ! grep -q "update_check=" &plugin;/settings.cfg; then
sed -i '$ a\update_check=true' &plugin;/settings.cfg
fi
if [ "$(grep -q "local_version=" &plugin;/settings.cfg)" ]; then
sed -i '/local_version=/d' &plugin;/settings.cfg
fi
#Set variables
KERNEL_V="$(uname -r)"
SET_DRV_V="$(grep "driver_version" "&plugin;/settings.cfg" | cut -d '=' -f2)"
if [ "${SET_DRV_V}" == "latest_nos" ]; then
export PACKAGE="nvos"
export OS="Open Source "
else
export PACKAGE="nvidia"
fi
DL_URL="https://github.com/ich777/unraid-nvidia-driver/releases/download/${KERNEL_V}"
UPDATE_CHECK="$(grep "update_check" &plugin;/settings.cfg | head -1 | cut -d '=' -f2)"
if [ ! -d "&packages;/${KERNEL_V%%-*}" ]; then
mkdir -p "&packages;/${KERNEL_V%%-*}"
CUR_V=""
else
CUR_V="$(ls -p &packages;/${KERNEL_V%%-*} 2>/dev/null | grep -E -v '\.md5' | sort -V | tail -1)"
fi
#Move old package directory to new package directory to be compliant with 6.11
if find &packages; -maxdepth 1 -type f -name "*.txz" 2>/dev/null ; then
mv $(find &packages; -maxdepth 1 -type f -name "*.txz") &packages;/${KERNEL_V%%-*}/ 2>/dev/null
CUR_V="$(ls -p &packages;/${KERNEL_V%%-*} 2>/dev/null | grep -E -v '\.md5' | sort -V | tail -1)"
fi
#Check if Nvidia Driver Package is already downloaded
check
#Check for old packages that are not suitable for this Kernel and not suitable for the current Nvidia driver version
rm -rf $(ls -d &packages;/* 2>/dev/null | grep -v "${KERNEL_V%%-*}")
rm -f $(ls &packages;/${KERNEL_V%%-*}/* 2>/dev/null | grep -v "$LAT_PACKAGE")
#Install Nvidia Driver Package
if ! modinfo nvidia -0 >/dev/null 2>&1 ; then
echo
echo "-----------------Installing Nvidia ${OS}Driver Package v$(echo $LAT_PACKAGE | cut -d '-' -f2)-------------------"
install > /dev/null
activate
else
activate
fi
#Enable update check
if [ "$UPDATE_CHECK" == "true" ]; then
if [ ! "$(crontab -l | grep "/usr/local/emhttp/plugins/nvidia-driver/include/update-check.sh")" ]; then
(crontab -l ; echo ""$((0 + $RANDOM % 59))" "$(shuf -i 8-9 -n 1)" * * * /usr/local/emhttp/plugins/nvidia-driver/include/update-check.sh &>/dev/null 2>&1") | crontab -
fi
fi
#Display message to disable and enable Docker on first installation or display successful message
if [ "$(grep "first_installation=" "&plugin;/settings.cfg" | cut -d '=' -f2)" == "true" ]; then
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "Nvidia Driver" -d "Please make sure to disable and enable Docker if you installed the Nvidia ${OS}driver for the first time! Settings -> Docker -> Enable Docker 'No' -> Apply -> Enable Docker 'Yes' -> Apply" -i "alert" -l "/Settings/DockerSettings"
sed -i '/first_installation=true/c\first_installation=false' "&plugin;/settings.cfg"
echo
echo "------------Installation of Nvidia ${OS}driver v$(echo $LAT_PACKAGE | cut -d '-' -f2) successful----------------"
echo
echo "Please make sure to disable and enable Docker if you installed the Nvidia ${OS}driver for the first time! Settings -> Docker -> Enable Docker 'No' -> Apply -> Enable Docker 'Yes' -> Apply"
else
sed -i '/first_installation=true/c\first_installation=false' "&plugin;/settings.cfg"
echo
echo "--------------Installation of Nvidia ${OS}driver v$(echo $LAT_PACKAGE | cut -d '-' -f2) successful--------------"
fi
#Check if Plugin Update Helper is downloaded and up-to-date
if [ ! -f &plugin;/plugin_update_helper ]; then
wget -q -T 5 -O &plugin;/plugin_update_helper "https://raw.githubusercontent.com/ich777/unraid-plugin_update_helper/master/plugin_update_helper"
else
CUR_V="$(grep -E "Plugin-Update-Helper version:" &plugin;/plugin_update_helper | awk '{print $4}')"
if [ ! -s /tmp/update-helper ]; then
echo "$(wget -T5 -qO- https://raw.githubusercontent.com/ich777/unraid-plugin_update_helper/master/plugin_update_helper | grep -E "Plugin-Update-Helper version:" | awk '{print $4}')" > /tmp/update-helper
AVAIL_V="$(cat /tmp/update-helper)"
else
AVAIL_V="$(cat /tmp/update-helper)"
fi
if [ ! -z "$AVAIL_V" ]; then
COMPARE="$(sort -V <(echo -e "${AVAIL_V}\n$CUR_V") | tail -1)"
if [ "$CUR_V" != "$COMPARE" ]; then
wget -q -T 5 -O &plugin;/plugin_update_helper "https://raw.githubusercontent.com/ich777/unraid-plugin_update_helper/master/plugin_update_helper"
fi
fi
fi
#Fix if config.toml is missing
if [ ! -f /etc/nvidia-container-runtime/config.toml ]; then
if [ ! -d /etc/nvidia-container-runtime ]; then
mkdir -p /etc/nvidia-container-runtime
fi
touch /etc/nvidia-container-runtime/config.toml
echo '[nvidia-container-runtime]
log-level = "warning"' > /etc/nvidia-container-runtime/config.toml
fi
#Change log level from nvidia-container-runtime from info to warning if it isn't already set to warning
sed -i "/log-level = \"info\"/c\log-level = \"warning\"" /etc/nvidia-container-runtime/config.toml
#Check if Plugin Update Helper is installed and up to date
if [ ! -f /usr/bin/plugin_update_helper ]; then
cp &plugin;/plugin_update_helper /usr/bin/plugin_update_helper
chmod +x /usr/bin/plugin_update_helper
else
PLUGIN_V="$(grep -E "Plugin-Update-Helper version:" &plugin;/plugin_update_helper | awk '{print $4}')"
INST_V="$(grep -E "Plugin-Update-Helper version:" /usr/bin/plugin_update_helper | awk '{print $4}')"
COMPARE="$(sort -V <(echo -e "${PLUGIN_V}\n$INST_V") | tail -1)"
if [ "$INST_V" != "$COMPARE" ]; then
kill $(ps aux | grep -E "inotifywait -q /boot/changes.txt -e move_self,delete_self" | grep -v "grep -E inotifywait" | awk '{print $2}') 2>/dev/null
sleep 1
cp &plugin;/plugin_update_helper /usr/bin/plugin_update_helper
chmod +x /usr/bin/plugin_update_helper
fi
fi
#Start Plugin Update Helper
if [ -z "$(ps aux | grep -E "inotifywait -q /boot/changes.txt -e move_self,delete_self" | grep -v "grep -E inotifywait" | awk '{print $2}')" ]; then
echo "/usr/bin/plugin_update_helper" | at now -M > /dev/null 2>&1
fi
</INLINE>
</FILE>
<FILE Run="/bin/bash" Method="remove">
<INLINE>
echo "----------------------------------------"
echo "---Uninstalling Nvidia driver package---"
echo "----------------------------------------"
# Remove plugin related files
removepkg &name;-&version;
crontab -l | grep -v '/usr/local/emhttp/plugins/nvidia-driver/include/update-check.sh &>/dev/null 2>&1' | crontab -
rm -rf /usr/local/emhttp/plugins/&name;
rm -rf &plugin;
echo
echo "--------------------------------------------------------------------------------"
echo "-------------Nvidia Driver uninstalled, please reboot your server!--------------"
echo "--------------------------------------------------------------------------------"
echo
</INLINE>
</FILE>
</PLUGIN>