entrypoint.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. #
  3. # Copyright (c) Contributors to the Open 3D Engine Project.
  4. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. #
  6. # SPDX-License-Identifier: Apache-2.0 OR MIT
  7. #
  8. # Validate that the UID and GID environment variables are set
  9. : "${UID:=0}"
  10. : "${GID:=0}"
  11. if [ "$UID" == 0 ]
  12. then
  13. echo 'The env for the current User ID is required. You need to provide the following arguments: --env UID=\$(id -u)'
  14. exit 1
  15. fi
  16. if [ "$GID" == 0 ]
  17. then
  18. echo 'The env for the current Group ID is required. You need to provide the following arguments: --env GID=\$(id -g)'
  19. exit 1
  20. fi
  21. # Update the O3DE user's UID and GID to match the environment so that it has the same user information/permissions for the mapped volumes used
  22. # for persistence of this Docker container
  23. set -eu
  24. usermod -u "$UID" "$O3DE_USER" 2>/dev/null && {
  25. groupmod -g "$GID" "$O3DE_USER" 2>/dev/null ||
  26. usermod -a -G "$GID" "$O3DE_USER"
  27. }
  28. if [ $? -ne 0 ]
  29. then
  30. echo "Error matching Docker user $O3DE to User ID $$UID and Group ID $GID"
  31. exit 1
  32. fi
  33. # Make sure the O3DE specific manifest (.o3de) and home (O3DE) folders are mapped correctly for persistence
  34. if [ ! -d "/home/$O3DE_USER/.o3de" ]
  35. then
  36. echo 'Mapping of the user id was not provided on docker run. You need to provide the following arguments: -v "$HOME/.o3de:/home/o3de/.o3de" -v "$HOME/O3DE:/home/o3de/O3DE"'
  37. exit 1
  38. elif [ ! -d "/home/$O3DE_USER/O3DE" ]
  39. then
  40. echo 'Mapping of the user id was not provided on docker run. You need to provide the following arguments: -v "$HOME/.o3de:/home/o3de/.o3de" -v "$HOME/O3DE:/home/o3de/O3DE"'
  41. exit 1
  42. else
  43. # Make sure ownership is correct for the mapped O3DE folders
  44. sudo chown $O3DE_USER:$O3DE_USER -R /home/$O3DE_USER/.o3de
  45. sudo chown $O3DE_USER:$O3DE_USER -R /home/$O3DE_USER/O3DE
  46. # Prepare and set the XDG_RUNTIME_DIR value for Qt in order to launch mime applications from Project Manager
  47. sudo mkdir -p /run/user/$UID
  48. sudo chown $O3DE_USER:$O3DE_USER /run/user/$UID
  49. sudo chmod 7700 /run/user/$UID
  50. echo -e "\nexport XDG_RUNTIME_DIR=/run/user/$UID\n" >> /home/o3de/.bashrc
  51. fi
  52. # Bootstrap python first
  53. su -c "/opt/O3DE/$(ls /opt/O3DE/)/python/get_python.sh" $O3DE_USER
  54. if [ $? -ne 0 ]
  55. then
  56. echo "Error Initializing O3DE Python."
  57. exit 1
  58. fi
  59. # If this is a ROS based image, then add ros setup in the $O3DE user's startup
  60. if [ "$INPUT_IMAGE" == "ros" ]
  61. then
  62. echo -e "\nsource /opt/ros/${ROS_DISTRO}/setup.bash\n" >> /home/o3de/.bashrc
  63. fi
  64. # Start the session as $O3DE_USER
  65. set -- su $O3DE_USER -g $O3DE_USER "${@}"
  66. exec "$@"