bootstrap.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. set -e
  3. trap "echo TRAPed signal" HUP INT QUIT KILL TERM
  4. echo 'user:${VNCPASS}' | sudo chpasswd
  5. # NVIDIA driver inside the container must be same version as host.
  6. HEX_ID=$(sudo nvidia-smi --query-gpu=pci.bus_id --id=${NVIDIA_VISIBLE_DEVICES} --format=csv | tail -n1)
  7. IFS=":." ARR_ID=($HEX_ID); unset IFS
  8. BUS_ID=PCI:$((16#${ARR_ID[1]})):$((16#${ARR_ID[2]})):$((16#${ARR_ID[3]}))
  9. # 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 different
  10. sudo nvidia-xconfig -a --virtual=${SIZEW}x${SIZEH} --allow-empty-initial-configuration --enable-all-gpus --busid=$BUS_ID --use-display-device=None
  11. shopt -s extglob
  12. for TTY in /dev/tty+([0-9])
  13. do
  14. if [ -w $TTY ] ; then
  15. /usr/bin/X tty$(echo $TTY | grep -Eo '[0-9]+$') :0 &
  16. break
  17. fi
  18. done
  19. sleep 1
  20. x11vnc -display :0 -passwd $VNCPASS -forever -rfbport 5900 &
  21. sleep 2
  22. pulseaudio --start
  23. sleep 2
  24. /opt/noVNC/utils/launch.sh --vnc localhost:5900 --listen 5901 &
  25. sleep 2
  26. export DISPLAY=:0
  27. mate-session &
  28. echo "Session Running. Press [Return] to exit."
  29. read