FROM osrf/ros:humble-desktop

ARG USERNAME=turtlebot
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
    #
    # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
    && apt-get update \
    && apt-get install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME

# ********************************************************
# * Anything else you want to do like clean up goes here *
# ********************************************************

ENV SHELL=/bin/bash

# Install turtlebot4 dependecies
RUN sudo apt update -y && sudo apt install -y ros-humble-turtlebot4-desktop

# Configure discovery over discovery servers of turtlebots in lab
COPY turtlebot4_discovery /etc/turtlebot4_discovery
RUN echo "source /etc/turtlebot4_discovery/setup.bash" >> /etc/bash.bashrc

# Copy EntryPoint-Skript and make it executable
COPY entrypoint.sh /EntryPoint.sh
RUN chmod +x /EntryPoint.sh

# [Optional] Set the default user. Omit if you want to keep the default as root.
USER $USERNAME

ENTRYPOINT ["/EntryPoint.sh"]
CMD [ "bash" ]
