#!/bin/bash if type update-alternatives 2>/dev/null >&1; then # Remove previous link if it doesn't use update-alternatives if [ -L '/usr/bin/nvidia-ai-workbench' -a -e '/usr/bin/nvidia-ai-workbench' -a "`readlink '/usr/bin/nvidia-ai-workbench'`" != '/etc/alternatives/nvidia-ai-workbench' ]; then rm -f '/usr/bin/nvidia-ai-workbench' fi update-alternatives --install '/usr/bin/nvidia-ai-workbench' 'nvidia-ai-workbench' '/opt/NVIDIA AI Workbench/nvidia-ai-workbench' 100 || ln -sf '/opt/NVIDIA AI Workbench/nvidia-ai-workbench' '/usr/bin/nvidia-ai-workbench' else ln -sf '/opt/NVIDIA AI Workbench/nvidia-ai-workbench' '/usr/bin/nvidia-ai-workbench' fi # Check if user namespaces are supported by the kernel and working with a quick test: if ! { [[ -L /proc/self/ns/user ]] && unshare --user true; }; then # Use SUID chrome-sandbox only on systems without user namespaces: chmod 4755 '/opt/NVIDIA AI Workbench/chrome-sandbox' || true else chmod 0755 '/opt/NVIDIA AI Workbench/chrome-sandbox' || true fi if hash update-mime-database 2>/dev/null; then update-mime-database /usr/share/mime || true fi if hash update-desktop-database 2>/dev/null; then update-desktop-database /usr/share/applications || true fi # Install apparmor profile. (Ubuntu 24+) # First check if the version of AppArmor running on the device supports our profile. # This is in order to keep backwards compatibility with Ubuntu 22.04 which does not support abi/4.0. # In that case, we just skip installing the profile since the app runs fine without it on 22.04. # # Those apparmor_parser flags are akin to performing a dry run of loading a profile. # https://wiki.debian.org/AppArmor/HowToUse#Dumping_profiles # # Unfortunately, at the moment AppArmor doesn't have a good story for backwards compatibility. # https://askubuntu.com/questions/1517272/writing-a-backwards-compatible-apparmor-profile APPARMOR_PROFILE_SOURCE='/opt/NVIDIA AI Workbench/resources/apparmor-profile' APPARMOR_PROFILE_TARGET='/etc/apparmor.d/nvidia-ai-workbench' if test -d "/etc/apparmor.d"; then if apparmor_parser --skip-kernel-load --debug "$APPARMOR_PROFILE_SOURCE" > /dev/null 2>&1; then cp -f "$APPARMOR_PROFILE_SOURCE" "$APPARMOR_PROFILE_TARGET" if hash apparmor_parser 2>/dev/null; then # Extra flags taken from dh_apparmor: # > By using '-W -T' we ensure that any abstraction updates are also pulled in. # https://wiki.debian.org/AppArmor/Contribute/FirstTimeProfileImport apparmor_parser --replace --write-cache --skip-read-cache "$APPARMOR_PROFILE_TARGET" fi else echo "Skipping the installation of the AppArmor profile as this version of AppArmor does not seem to support the bundled profile" fi fi