entrypoint.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. mv /home/opendevin/.cache/ms-playwright/ /root/.cache/
  22. "$@"
  23. else
  24. echo "Setting up enduser with id $SANDBOX_USER_ID"
  25. if id "enduser" &>/dev/null; then
  26. echo "User enduser already exists. Skipping creation."
  27. else
  28. if ! useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser; then
  29. echo "Failed to create user enduser with id $SANDBOX_USER_ID. Moving opendevin user."
  30. incremented_id=$(($SANDBOX_USER_ID + 1))
  31. usermod -u $incremented_id opendevin
  32. if ! useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser; then
  33. echo "Failed to create user enduser with id $SANDBOX_USER_ID for a second time. Exiting."
  34. exit 1
  35. fi
  36. fi
  37. fi
  38. usermod -aG app enduser
  39. # get the user group of /var/run/docker.sock and set opendevin to that group
  40. DOCKER_SOCKET_GID=$(stat -c '%g' /var/run/docker.sock)
  41. echo "Docker socket group id: $DOCKER_SOCKET_GID"
  42. if getent group $DOCKER_SOCKET_GID; then
  43. echo "Group with id $DOCKER_SOCKET_GID already exists"
  44. else
  45. echo "Creating group with id $DOCKER_SOCKET_GID"
  46. groupadd -g $DOCKER_SOCKET_GID docker
  47. fi
  48. mkdir -p /home/enduser/.cache/ms-playwright/
  49. mv /home/opendevin/.cache/ms-playwright/ /home/enduser/.cache/
  50. usermod -aG $DOCKER_SOCKET_GID enduser
  51. echo "Running as enduser"
  52. su enduser /bin/bash -c "$*"
  53. fi