This repository has been archived on 2025-02-03. You can view files and clone it, but cannot push or open issues or pull requests.
Files
unraid-nvidia-driver/nvidia-driver.plg

446 lines
17 KiB
XML

<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "nvidia-driver">
<!ENTITY author "unraid">
<!ENTITY version "2025.02.03">
<!ENTITY launch "Settings/nvidia-driver">
<!ENTITY gitURL "https://github.com/&author;/unraid-&name;/raw/master">
<!ENTITY pluginURL "&gitURL;/&name;.plg">
<!ENTITY md5 "fbdaa1ed52a2ade55e04ad281bb096b8">
<!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>
###2025.02.03
- Switch repo from ich777 to unraid
###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/unraid/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/unraid/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/unraid/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)" ] &amp;&amp; [ "$(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" &amp;&amp; "$SET_DRV_V" != "latest_prb" &amp;&amp; "$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/unraid/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&gt;/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&gt;/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>&amp;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 &amp;&gt;/dev/null 2&gt;&amp;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 &lt;(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 &lt;(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 &gt; /dev/null 2&gt;&amp;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 &amp;&gt;/dev/null 2&gt;&amp;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>