bootstrap.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. set -e
  3. trap "echo TRAPed signal" HUP INT QUIT KILL TERM
  4. sudo chown -R user:user ~
  5. echo "user:${VNCPASS}" | sudo chpasswd
  6. # NVIDIA driver version inside the container from Dockerfile must be equal to the host
  7. HEX_ID=$(sudo nvidia-smi --query-gpu=pci.bus_id --id=$(echo $NVIDIA_VISIBLE_DEVICES | cut -d ',' -f1) --format=csv | sed -n 2p)
  8. IFS=":." ARR_ID=($HEX_ID)
  9. unset IFS
  10. BUS_ID=PCI:$((16#${ARR_ID[1]})):$((16#${ARR_ID[2]})):$((16#${ARR_ID[3]}))
  11. # Leave out --use-display-device=None if GPU is headless such as Tesla and download links of such GPU drivers in Dockerfile should also be changed
  12. sudo nvidia-xconfig --virtual=${SIZEW}x${SIZEH} --allow-empty-initial-configuration --enable-all-gpus --no-use-edid-dpi --busid=$BUS_ID --use-display-device=None
  13. if [ "x${SHARED}" == "xTRUE" ]
  14. then
  15. export SHARESTRING="-shared"
  16. fi
  17. shopt -s extglob
  18. for TTY in /dev/tty+([0-9])
  19. do
  20. if [ -w $TTY ]
  21. then
  22. /usr/bin/X tty$(echo $TTY | grep -Eo '[0-9]+$') :0 &
  23. break
  24. fi
  25. done
  26. sleep 1
  27. x11vnc -display :0 -passwd $VNCPASS -forever -xkb -rfbport 5900 $SHARESTRING &
  28. sleep 1
  29. /opt/noVNC/utils/launch.sh --vnc localhost:5900 --listen 5901 &
  30. sleep 1
  31. export DISPLAY=:0
  32. mate-session &
  33. sleep 1
  34. pulseaudio --start
  35. echo "Session Running. Press [Return] to exit."
  36. read