bootstrap.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 ]
  15. then
  16. /usr/bin/X tty$(echo $TTY | grep -Eo '[0-9]+$') :0 &
  17. break
  18. fi
  19. done
  20. sleep 1
  21. x11vnc -display :0 -passwd $VNCPASS -forever -rfbport 5900 &
  22. sleep 2
  23. pulseaudio --start
  24. sleep 2
  25. /opt/noVNC/utils/launch.sh --vnc localhost:5900 --listen 5901 &
  26. sleep 2
  27. export DISPLAY=:0
  28. mate-session &
  29. echo "Session Running. Press [Return] to exit."
  30. read