mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 16:55:37 +02:00
🐛 fix(scripts): fix entrypoint.sh crashes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash -e
|
||||
trap "echo TRAPed signal" HUP INT QUIT TERM
|
||||
|
||||
# Create and modify permissions of XDG_RUNTIME_DIR
|
||||
@@ -7,11 +7,12 @@ sudo chown ubuntu:ubuntu /tmp/runtime-ubuntu
|
||||
sudo -u ubuntu chmod 700 /tmp/runtime-ubuntu
|
||||
# Make user directory owned by the user in case it is not
|
||||
sudo chown ubuntu:ubuntu /home/ubuntu || sudo chown ubuntu:ubuntu /home/ubuntu/* || { echo "Failed to change user directory permissions. There may be permission issues."; }
|
||||
|
||||
# Remove directories to make sure the desktop environment starts
|
||||
sudo rm -rf /tmp/.X* ~/.cache
|
||||
# Change time zone from environment variable
|
||||
sudo ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" | sudo tee /etc/timezone > /dev/null
|
||||
# Add gamescope directory
|
||||
# Add gamescope directories to path
|
||||
export PATH="${PATH:+${PATH}:}/usr/local/games:/usr/games"
|
||||
|
||||
# This symbolic link enables running Xorg inside a container with `-sharevts`
|
||||
@@ -28,10 +29,7 @@ if ! command -v nvidia-xconfig &>/dev/null; then
|
||||
# If version is different, new installer will overwrite the existing components
|
||||
if [ ! -f "/tmp/NVIDIA-Linux-${DRIVER_ARCH}-${DRIVER_VERSION}.run" ]; then
|
||||
# Check multiple sources in order to probe both consumer and datacenter driver versions
|
||||
curl -fsSL -O "https://international.download.nvidia.com/XFree86/Linux-${DRIVER_ARCH}/${DRIVER_VERSION}/NVIDIA-Linux-${DRIVER_ARCH}-${DRIVER_VERSION}.run" || curl -fsSL -O "https://international.download.nvidia.com/tesla/${DRIVER_VERSION}/NVIDIA-Linux-${DRIVER_ARCH}-${DRIVER_VERSION}.run" || {
|
||||
echo "Failed NVIDIA GPU driver download. Exiting."
|
||||
exit 1
|
||||
}
|
||||
curl -fsSL -O "https://international.download.nvidia.com/XFree86/Linux-${DRIVER_ARCH}/${DRIVER_VERSION}/NVIDIA-Linux-${DRIVER_ARCH}-${DRIVER_VERSION}.run" || curl -fsSL -O "https://international.download.nvidia.com/tesla/${DRIVER_VERSION}/NVIDIA-Linux-${DRIVER_ARCH}-${DRIVER_VERSION}.run" || { echo "Failed NVIDIA GPU driver download. Exiting."; exit 1; }
|
||||
fi
|
||||
# Extract installer before installing
|
||||
sudo sh "NVIDIA-Linux-${DRIVER_ARCH}-${DRIVER_VERSION}.run" -x
|
||||
@@ -61,7 +59,7 @@ if [ -f "/etc/X11/xorg.conf" ]; then
|
||||
sudo rm -f "/etc/X11/xorg.conf"
|
||||
fi
|
||||
|
||||
# Get first GPU device if all devices are available or $(NVIDIA_VISIBLE_DEVICES) is not set
|
||||
# Get first GPU device if all devices are available or `NVIDIA_VISIBLE_DEVICES` is not set
|
||||
if [ "$NVIDIA_VISIBLE_DEVICES" == "all" ] || [ -z "$NVIDIA_VISIBLE_DEVICES" ]; then
|
||||
export GPU_SELECT="$(sudo nvidia-smi --query-gpu=uuid --format=csv | sed -n 2p)"
|
||||
# Get first GPU device out of the visible devices in other situations
|
||||
@@ -87,7 +85,7 @@ fi
|
||||
|
||||
# Bus ID from nvidia-smi is in hexadecimal format and should be converted to decimal format (including the domain) which Xorg understands, required because nvidia-xconfig doesn't work as intended in a container
|
||||
HEX_ID="$(sudo nvidia-smi --query-gpu=pci.bus_id --id="$GPU_SELECT" --format=csv | sed -n 2p)"
|
||||
IFS=":." ARR_ID=("$HEX_ID")
|
||||
IFS=":." ARR_ID=($HEX_ID)
|
||||
unset IFS
|
||||
BUS_ID="PCI:$((16#${ARR_ID[1]}))@$((16#${ARR_ID[0]})):$((16#${ARR_ID[2]})):$((16#${ARR_ID[3]}))"
|
||||
# A custom modeline should be generated because there is no monitor to fetch this information normally
|
||||
|
||||
Reference in New Issue
Block a user