From 7300360f09232d4f2e39e7fd81631b1a6cabd477 Mon Sep 17 00:00:00 2001 From: Lennart Reiher Date: Mon, 23 Dec 2024 14:46:10 +0000 Subject: [PATCH 1/2] make chown in entrypoint safe from existing uid/gid --- docker/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 8a47279..3c36dd8 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -27,7 +27,7 @@ if [[ $DOCKER_UID && $DOCKER_GID ]]; then ln -s $WORKSPACE /home/$DOCKER_USER/ws chown -h $DOCKER_UID:$DOCKER_GID $WORKSPACE /home/$DOCKER_USER/ws /home/$DOCKER_USER/.sudo_as_admin_successful if [[ -d $WORKSPACE/src ]]; then - chown -R $DOCKER_USER:$DOCKER_USER $WORKSPACE/src + chown -R $DOCKER_UID:$DOCKER_GID $WORKSPACE/src fi fi [[ $(pwd) == "$WORKSPACE" ]] && cd /home/$DOCKER_USER/ws From 71c12572368cfc309359aebbc9c4cf8d87d94898 Mon Sep 17 00:00:00 2001 From: Lennart Reiher Date: Mon, 23 Dec 2024 14:46:31 +0000 Subject: [PATCH 2/2] add warnings if uid/gid is already existing --- docker/entrypoint.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 3c36dd8..be7921c 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -12,6 +12,8 @@ source /opt/ros/$ROS_DISTRO/setup.bash if [[ $DOCKER_UID && $DOCKER_GID ]]; then if ! getent group $DOCKER_GID > /dev/null 2>&1; then groupadd -g $DOCKER_GID $DOCKER_USER + else + echo -e "\e[33mWARNING | Cannot create group '$DOCKER_USER' with GID $DOCKER_GID, another group '$(getent group $DOCKER_GID | cut -d: -f1)' with same GID is already existing\e[0m" fi if ! getent passwd $DOCKER_UID > /dev/null 2>&1; then useradd -s /bin/bash \ @@ -29,6 +31,8 @@ if [[ $DOCKER_UID && $DOCKER_GID ]]; then if [[ -d $WORKSPACE/src ]]; then chown -R $DOCKER_UID:$DOCKER_GID $WORKSPACE/src fi + else + echo -e "\e[33mWARNING | Cannot create user '$DOCKER_USER' with UID $DOCKER_UID, another user '$(getent passwd $DOCKER_UID | cut -d: -f1)' with same UID is already existing\e[0m" fi [[ $(pwd) == "$WORKSPACE" ]] && cd /home/$DOCKER_USER/ws exec gosu $DOCKER_USER "$@"