mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-16 16:32:03 +00:00
shecllcheck: Update nvidia_chroot.sh
Make shellcheck happy with the new rules new updates needed Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
This commit is contained in:
parent
c4e4e14b32
commit
af1d6c2407
@ -21,14 +21,14 @@ base_os="jammy"
|
||||
|
||||
APT_INSTALL="apt -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' -yqq --no-install-recommends install"
|
||||
|
||||
export KBUILD_SIGN_PIN=$6
|
||||
export KBUILD_SIGN_PIN="${6:-}"
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
is_feature_enabled() {
|
||||
local feature="$1"
|
||||
# Check if feature is in the comma-separated list
|
||||
if [[ ",$nvidia_gpu_stack," == *",$feature,"* ]]; then
|
||||
if [[ ",${nvidia_gpu_stack}," == *",${feature},"* ]]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
@ -38,11 +38,11 @@ is_feature_enabled() {
|
||||
set_driver_version_type() {
|
||||
echo "chroot: Setting the correct driver version"
|
||||
|
||||
if [[ ",$nvidia_gpu_stack," == *",latest,"* ]]; then
|
||||
if [[ ",${nvidia_gpu_stack}," == *",latest,"* ]]; then
|
||||
driver_version="latest"
|
||||
elif [[ ",$nvidia_gpu_stack," == *",lts,"* ]]; then
|
||||
elif [[ ",${nvidia_gpu_stack}," == *",lts,"* ]]; then
|
||||
driver_version="lts"
|
||||
elif [[ "$nvidia_gpu_stack" =~ version=([^,]+) ]]; then
|
||||
elif [[ "${nvidia_gpu_stack}" =~ version=([^,]+) ]]; then
|
||||
driver_version="${BASH_REMATCH[1]}"
|
||||
else
|
||||
echo "No known driver spec found. Please specify \"latest\", \"lts\", or \"version=<VERSION>\"."
|
||||
@ -54,9 +54,9 @@ set_driver_version_type() {
|
||||
echo "chroot: Setting the correct driver type"
|
||||
|
||||
# driver -> enable open or closed drivers
|
||||
if [[ "$nvidia_gpu_stack" =~ (^|,)driver=open($|,) ]]; then
|
||||
if [[ "${nvidia_gpu_stack}" =~ (^|,)driver=open($|,) ]]; then
|
||||
driver_type="-open"
|
||||
elif [[ "$nvidia_gpu_stack" =~ (^|,)driver=closed($|,) ]]; then
|
||||
elif [[ "${nvidia_gpu_stack}" =~ (^|,)driver=closed($|,) ]]; then
|
||||
driver_type=""
|
||||
fi
|
||||
|
||||
@ -76,7 +76,7 @@ install_nvidia_fabricmanager() {
|
||||
return
|
||||
}
|
||||
# if run_fm_file_name exists run it
|
||||
if [ -f /"${run_fm_file_name}" ]; then
|
||||
if [[ -f /"${run_fm_file_name}" ]]; then
|
||||
install_nvidia_fabricmanager_from_run_file
|
||||
else
|
||||
install_nvidia_fabricmanager_from_distribution
|
||||
@ -116,17 +116,17 @@ build_nvidia_drivers() {
|
||||
echo "chroot: Building GPU modules for: ${kernel_version}"
|
||||
cp /boot/System.map-"${kernel_version}" /lib/modules/"${kernel_version}"/build/System.map
|
||||
|
||||
if [ "${arch_target}" == "aarch64" ]; then
|
||||
if [[ "${arch_target}" == "aarch64" ]]; then
|
||||
ln -sf /lib/modules/"${kernel_version}"/build/arch/arm64 /lib/modules/"${kernel_version}"/build/arch/aarch64
|
||||
fi
|
||||
|
||||
if [ "${arch_target}" == "x86_64" ]; then
|
||||
if [[ "${arch_target}" == "x86_64" ]]; then
|
||||
ln -sf /lib/modules/"${kernel_version}"/build/arch/x86 /lib/modules/"${kernel_version}"/build/arch/amd64
|
||||
fi
|
||||
|
||||
make -j "$(nproc)" CC=gcc SYSSRC=/lib/modules/"${kernel_version}"/build > /dev/null
|
||||
|
||||
if [ -n "${KBUILD_SIGN_PIN}" ]; then
|
||||
if [[ -n "${KBUILD_SIGN_PIN}" ]]; then
|
||||
mkdir -p "${certs_dir}" && mv /signing_key.* "${certs_dir}"/.
|
||||
fi
|
||||
|
||||
@ -134,7 +134,7 @@ build_nvidia_drivers() {
|
||||
make -j "$(nproc)" CC=gcc SYSSRC=/lib/modules/"${kernel_version}"/build clean > /dev/null
|
||||
# The make clean above should clear also the certs directory but just in case something
|
||||
# went wroing make sure the signing_key.pem is removed
|
||||
[ -e "${signing_key}" ] && rm -f "${signing_key}"
|
||||
[[ -e "${signing_key}" ]] && rm -f "${signing_key}"
|
||||
done
|
||||
# Save the modules for later so that a linux-image purge does not remove it
|
||||
tar cvfa /lib/modules.save_from_purge.tar.zst /lib/modules
|
||||
@ -142,14 +142,14 @@ build_nvidia_drivers() {
|
||||
}
|
||||
|
||||
install_userspace_components() {
|
||||
if [ ! -f /"${run_file_name}" ]; then
|
||||
if [[ ! -f /"${run_file_name}" ]]; then
|
||||
echo "chroot: Skipping NVIDIA userspace runfile components installation"
|
||||
return
|
||||
fi
|
||||
|
||||
pushd /NVIDIA-* >> /dev/null
|
||||
# if aarch64 we need to remove --no-install-compat32-libs
|
||||
if [ "${arch_target}" == "aarch64" ]; then
|
||||
if [[ "${arch_target}" == "aarch64" ]]; then
|
||||
./nvidia-installer --no-kernel-modules --no-systemd --no-nvidia-modprobe -s --x-prefix=/root
|
||||
else
|
||||
./nvidia-installer --no-kernel-modules --no-systemd --no-nvidia-modprobe -s --x-prefix=/root --no-install-compat32-libs
|
||||
@ -159,10 +159,10 @@ install_userspace_components() {
|
||||
}
|
||||
|
||||
prepare_run_file_drivers() {
|
||||
if [ "${driver_version}" == "latest" ]; then
|
||||
if [[ "${driver_version}" == "latest" ]]; then
|
||||
driver_version=""
|
||||
echo "chroot: Resetting driver version not supported with run-file"
|
||||
elif [ "${driver_version}" == "lts" ]; then
|
||||
elif [[ "${driver_version}" == "lts" ]]; then
|
||||
driver_version=""
|
||||
echo "chroot: Resetting driver version not supported with run-file"
|
||||
fi
|
||||
@ -176,16 +176,16 @@ prepare_run_file_drivers() {
|
||||
|
||||
# Sooner or later RIM files will be only available remotely
|
||||
RIMFILE=$(ls NVIDIA-*/RIM_GH100PROD.swidtag)
|
||||
if [ -e "${RIMFILE}" ]; then
|
||||
if [[ -e "${RIMFILE}" ]]; then
|
||||
cp NVIDIA-*/RIM_GH100PROD.swidtag /usr/share/nvidia/rim/.
|
||||
fi
|
||||
popd >> /dev/null
|
||||
}
|
||||
|
||||
prepare_distribution_drivers() {
|
||||
if [ "${driver_version}" == "latest" ]; then
|
||||
if [[ "${driver_version}" == "latest" ]]; then
|
||||
driver_version=$(apt-cache search --names-only 'nvidia-headless-no-dkms-.?.?.?-open' | awk '{ print $1 }' | tail -n 1 | cut -d'-' -f5)
|
||||
elif [ "${driver_version}" == "lts" ]; then
|
||||
elif [[ "${driver_version}" == "lts" ]]; then
|
||||
driver_version="550"
|
||||
fi
|
||||
|
||||
@ -208,11 +208,11 @@ prepare_distribution_drivers() {
|
||||
prepare_nvidia_drivers() {
|
||||
local driver_source_dir=""
|
||||
|
||||
if [ -f /"${run_file_name}" ]; then
|
||||
if [[ -f /"${run_file_name}" ]]; then
|
||||
prepare_run_file_drivers
|
||||
|
||||
for source_dir in /NVIDIA-*; do
|
||||
if [ -d "${source_dir}" ]; then
|
||||
if [[ -d "${source_dir}" ]]; then
|
||||
driver_source_files="${source_dir}"/kernel${driver_type}
|
||||
driver_source_dir="${source_dir}"
|
||||
break
|
||||
@ -224,7 +224,7 @@ prepare_nvidia_drivers() {
|
||||
prepare_distribution_drivers
|
||||
|
||||
for source_dir in /usr/src/nvidia*; do
|
||||
if [ -d "${source_dir}" ]; then
|
||||
if [[ -d "${source_dir}" ]]; then
|
||||
driver_source_files="${source_dir}"
|
||||
driver_source_dir="${source_dir}"
|
||||
break
|
||||
@ -254,7 +254,7 @@ setup_apt_repositories() {
|
||||
|
||||
# Changing the reference here also means changes needed for cuda_keyring
|
||||
# and cuda apt repository see install_dcgm for details
|
||||
cat <<-CHROOT_EOF > /etc/apt/sources.list.d/${base_os}.list
|
||||
cat <<-CHROOT_EOF > /etc/apt/sources.list.d/"${base_os}".list
|
||||
deb [arch=amd64] http://us.archive.ubuntu.com/ubuntu ${base_os} main restricted universe multiverse
|
||||
deb [arch=amd64] http://us.archive.ubuntu.com/ubuntu ${base_os}-updates main restricted universe multiverse
|
||||
deb [arch=amd64] http://us.archive.ubuntu.com/ubuntu ${base_os}-security main restricted universe multiverse
|
||||
@ -286,13 +286,13 @@ get_supported_gpus_from_run_file() {
|
||||
local source_dir="$1"
|
||||
local supported_gpus_json="${source_dir}"/supported-gpus/supported-gpus.json
|
||||
|
||||
jq . < "${supported_gpus_json}" | grep '"devid"' | awk '{ print $2 }' | tr -d ',"' > ${supported_gpu_devids}
|
||||
jq . < "${supported_gpus_json}" | grep '"devid"' | awk '{ print $2 }' | tr -d ',"' > "${supported_gpu_devids}"
|
||||
}
|
||||
|
||||
get_supported_gpus_from_distro_drivers() {
|
||||
local supported_gpus_json=/usr/share/doc/nvidia-kernel-common-"${driver_version}"/supported-gpus.json
|
||||
|
||||
jq . < "${supported_gpus_json}" | grep '"devid"' | awk '{ print $2 }' | tr -d ',"' > ${supported_gpu_devids}
|
||||
jq . < "${supported_gpus_json}" | grep '"devid"' | awk '{ print $2 }' | tr -d ',"' > "${supported_gpu_devids}"
|
||||
}
|
||||
|
||||
export_driver_version() {
|
||||
@ -315,8 +315,8 @@ install_nvidia_dcgm() {
|
||||
[[ ${base_os} == "jammy" ]] && osver="ubuntu2204" || die "Unknown base_os ${base_os} used"
|
||||
|
||||
keyring="cuda-keyring_1.1-1_all.deb"
|
||||
curl -O https://developer.download.nvidia.com/compute/cuda/repos/${osver}/${arch}/${keyring}
|
||||
dpkg -i ${keyring} && rm -f ${keyring}
|
||||
curl -O "https://developer.download.nvidia.com/compute/cuda/repos/${osver}/${arch}/${keyring}"
|
||||
dpkg -i "${keyring}" && rm -f "${keyring}"
|
||||
|
||||
apt update
|
||||
eval "${APT_INSTALL}" datacenter-gpu-manager
|
||||
@ -328,7 +328,7 @@ cleanup_rootfs() {
|
||||
apt-mark hold libstdc++6 libzstd1 libgnutls30 pciutils
|
||||
# noble=libgnutls30t64
|
||||
|
||||
if [ -n "${driver_version}" ]; then
|
||||
if [[ -n "${driver_version}" ]]; then
|
||||
apt-mark hold libnvidia-cfg1-"${driver_version}" \
|
||||
nvidia-compute-utils-"${driver_version}" \
|
||||
nvidia-utils-"${driver_version}" \
|
||||
@ -355,7 +355,7 @@ cleanup_rootfs() {
|
||||
python3-pip software-properties-common ca-certificates \
|
||||
linux-libc-dev nuitka python3-minimal
|
||||
|
||||
if [ -n "${driver_version}" ]; then
|
||||
if [[ -n "${driver_version}" ]]; then
|
||||
apt purge -yqq nvidia-headless-no-dkms-"${driver_version}${driver_type}" \
|
||||
nvidia-kernel-source-"${driver_version}${driver_type}" -yqq
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user