entrypoint.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. set -eo pipefail
  3. echo "Starting OpenDevin..."
  4. if [[ $NO_SETUP == "true" ]]; then
  5. echo "Skipping setup, running as $(whoami)"
  6. "$@"
  7. exit 0
  8. fi
  9. if [ "$(id -u)" -ne 0 ]; then
  10. echo "The OpenDevin entrypoint.sh must run as root"
  11. exit 1
  12. fi
  13. if [ -z "$SANDBOX_USER_ID" ]; then
  14. echo "SANDBOX_USER_ID is not set"
  15. exit 1
  16. fi
  17. if [[ "$SANDBOX_USER_ID" -eq 0 ]]; then
  18. echo "Running OpenDevin as root"
  19. export RUN_AS_DEVIN=false
  20. mkdir -p /root/.cache/ms-playwright/
  21. if [ -d "/home/opendevin/.cache/ms-playwright/" ]; then
  22. mv /home/opendevin/.cache/ms-playwright/ /root/.cache/
  23. fi
  24. "$@"
  25. else
  26. echo "Setting up enduser with id $SANDBOX_USER_ID"
  27. if id "enduser" &>/dev/null; then
  28. echo "User enduser already exists. Skipping creation."
  29. else
  30. if ! useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser; then
  31. echo "Failed to create user enduser with id $SANDBOX_USER_ID. Moving opendevin user."
  32. incremented_id=$(($SANDBOX_USER_ID + 1))
  33. usermod -u $incremented_id opendevin
  34. if ! useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser; then
  35. echo "Failed to create user enduser with id $SANDBOX_USER_ID for a second time. Exiting."
  36. exit 1
  37. fi
  38. fi
  39. fi
  40. usermod -aG app enduser
  41. # get the user group of /var/run/docker.sock and set opendevin to that group
  42. DOCKER_SOCKET_GID=$(stat -c '%g' /var/run/docker.sock)
  43. echo "Docker socket group id: $DOCKER_SOCKET_GID"
  44. if getent group $DOCKER_SOCKET_GID; then
  45. echo "Group with id $DOCKER_SOCKET_GID already exists"
  46. else
  47. echo "Creating group with id $DOCKER_SOCKET_GID"
  48. groupadd -g $DOCKER_SOCKET_GID docker
  49. fi
  50. mkdir -p /home/enduser/.cache/huggingface/hub/
  51. mkdir -p /home/enduser/.cache/ms-playwright/
  52. if [ -d "/home/opendevin/.cache/ms-playwright/" ]; then
  53. mv /home/opendevin/.cache/ms-playwright/ /home/enduser/.cache/
  54. fi
  55. usermod -aG $DOCKER_SOCKET_GID enduser
  56. echo "Running as enduser"
  57. su enduser /bin/bash -c "$*"
  58. fi