From 802710222caf9a21d4c17f8a6fbdad5af5cf9dbc Mon Sep 17 00:00:00 2001
From: Andres Montano <andres.montano@tecnalia.com>
Date: Thu, 26 Oct 2023 09:03:48 +0200
Subject: [PATCH] Add plugins installation option

---
 dockerfiles/devenv.Dockerfile | 85 ++++++++++++++++++++++-------------
 dotfiles/docker.sh            | 76 +++++++++++++++++++++++++++++--
 dotfiles/ros.sh               |  2 +-
 3 files changed, 127 insertions(+), 36 deletions(-)

diff --git a/dockerfiles/devenv.Dockerfile b/dockerfiles/devenv.Dockerfile
index ce0bfa2..3ae4b0f 100644
--- a/dockerfiles/devenv.Dockerfile
+++ b/dockerfiles/devenv.Dockerfile
@@ -37,6 +37,7 @@ RUN apt-get update && \
     # ccmake
     cmake-curses-gui \
     direnv \
+    gawk \
     gdb \
     git \
     git-lfs \
@@ -54,26 +55,6 @@ RUN if [ "$EXT_SHELL" = "zsh" ]; \
         apt-get -y install zsh; \
     fi
 
-# Install extra libs from .deb files
-WORKDIR /tmp/srcs/
-COPY /extra_libs/* ./
-
-# Enviroment tools based on ubuntu version
-RUN if [ -f "common_libs.txt" ]; \
-    then \
-        grep -v '^#' common_libs.txt | xargs dpkg -i ;\
-    fi
-
-# Extra libs, e.g. vtk-7.1_20221201-1_amd64.deb
-RUN if [ -f "${ROS_DISTRO}_libs.txt" ]; \
-    then \
-        grep -v '^#' ${ROS_DISTRO}_libs.txt | xargs dpkg -i ;\
-    fi
-
-RUN rm -rf *
-
-RUN apt-get --reinstall install -y libnotify-bin notify-osd
-
 # Configure system to look for debian packages in the Artifactory repository
 COPY auth.conf /etc/apt/auth.conf.d/tecnalia.conf
 
@@ -106,17 +87,20 @@ RUN if [ "${ROS_DISTRO}" = "melodic"  ]; \
         python-osrf-pycommon\
         python-vcstool; \
     else\
-        apt-get update && \
-        apt-get -y install \
-        ipython3 \
-        python-is-python3 \
-        python3-click \
-        python3-numpy \
-        python3-osrf-pycommon \
-        python3-vcstool \
-        python3-pip \
-        # clang
-        clangd liblldb-dev libllvm-ocaml-dev python3-clang; \
+        if [ "${ROS_DISTRO}" = "noetic"  ]; \
+        then \
+            apt-get update && \
+            apt-get -y install \
+            ipython3 \
+            python-is-python3 \
+            python3-click \
+            python3-numpy \
+            python3-osrf-pycommon \
+            python3-vcstool \
+            python3-pip \
+            # clang
+            clangd liblldb-dev libllvm-ocaml-dev python3-clang; \
+        fi \
     fi
 
 # Install ROS 1 tools
@@ -149,8 +133,45 @@ RUN if [ -f "${ROS_DISTRO}_requirements.txt" ]; \
 
 RUN rm -rf *
 
+# Install extra libs from .deb files
+WORKDIR /tmp/srcs/
+COPY /extra_libs/* ./
+
+# Enviroment tools based on ubuntu version
+RUN if [ -f "common_libs.txt" ]; \
+    then \
+        grep -v '^#' common_libs.txt | xargs dpkg -i ;\
+    fi
+
+# Extra libs, e.g. vtk-7.1_20221201-1_amd64.deb
+RUN if [ -f "${ROS_DISTRO}_libs.txt" ]; \
+    then \
+        grep -v '^#' ${ROS_DISTRO}_libs.txt | xargs dpkg -i ;\
+    fi
+
+# Read the plugin list and copy the plugins to their destinations
+RUN if [ -f "${ROS_DISTRO}_plugins.txt" ]; \
+    then \
+        while IFS= read -r line; \
+        do \
+            echo "Processing line: $line"; \
+            if [[ "$line" == \#* ]]; \
+            then \
+                echo "Skipping ${line}"; \
+            else \
+                plugin_name=$(echo "$line" | awk '{print $1}'); \
+                destination=$(echo "$line" | awk '{print $2}'); \
+                echo "Coping ${plugin_name} into ${destination}"; \
+                mkdir -p "$destination" && cp -r "$plugin_name" "$destination/"; \
+            fi; \
+        done < ${ROS_DISTRO}_plugins.txt ; \
+    fi
+
+RUN rm -rf *
+RUN apt-get --reinstall install -y libnotify-bin notify-osd
+
 # Update this date to re-run the image final update
-LABEL image.date=23-10-2023
+LABEL image.date=25-10-2023
 
 # Update final image
 RUN apt-get update \
diff --git a/dotfiles/docker.sh b/dotfiles/docker.sh
index a374608..4ad2802 100644
--- a/dotfiles/docker.sh
+++ b/dotfiles/docker.sh
@@ -9,11 +9,22 @@ alias drmi="docker rmi"
 alias dsp="docker system prune --all"
 alias dimp="docker image prune"
 
+# Determine shell extension
+if [ -z $SHELL ]; then
+    echo "SHELL not set"
+    export SHELL=/usr/bin/zsh
+    ext=$(basename ${SHELL});
+else
+    ext=$(basename ${SHELL});
+fi
+
 # Build docker image
 # usage: dockbuild {noetic, melodic}
 function dockbuild(){
     if [ $# -lt 1 ]; then
         echo "Usage: dockbuild <ROS_DISTRO> [build_args]"
+        echo "ROS_DISTRO:"
+        echo "      melodic, noetic, humble, etc."
         echo "build_args:"
         echo "      EXT_SHELL - zsh (default) or bash"
         return 1
@@ -39,7 +50,23 @@ function dockbuild(){
 # ToDo Add extra parameters by arg
 # To share docker --volume /var/run/docker.sock:/var/run/docker.sock:ro
 # To share video (usb-cam) --volume /dev/video0:/dev/video0
+# To share pcan --volume /dev/pcanusb32:/dev/pcanusb32
 function dockrun() {
+    if [ $# -lt 1 ]; then
+        echo "Usage: dockrun <ROS_DISTRO> [posicional options]"
+        echo "ROS_DISTRO:"
+        echo "      melodic, noetic, humble, etc."
+        echo "Options:"
+        echo "      Passing 1 option   --> path_to_workspace. E.g., dockrun humble mairon_ws"
+        echo "      Passing 2 options  --> path_to_workspace + extra_config. E.g., dockrun humble mairon_ws video"
+        echo "          extra_config: pcan, video, pcan_video"
+        echo "Examples:"
+        echo "dockrun humble mairon_ws"
+        echo "dockrun noetic neurondones_ws pcan_video"
+        echo "dockrun melodic odinrobot_ws video"
+        return 1
+    fi
+
     # Check if the image exist
     if [[ "$(docker images -q devenv:$1 2> /dev/null)" == "" ]]; then
         # build the image
@@ -48,12 +75,55 @@ function dockrun() {
 
     # Check if the container exist
     if [[ $(docker ps -aq -f name=$1) ]]; then
-        # Attach to conayiner
-        docker exec -it $1 bash -c "cd ~/ros/$1/$2 && $ext"
+        # Attach to container
+        if [ $# -lt 2 ]; then
+            docker exec -it $1 bash -c "cd ~/ros/$1 && $ext"
+        else
+            docker exec -it $1 bash -c "cd ~/ros/$1/$2 && $ext"
+        fi
     else
         # Launch container
         cd ~/ros/$1/$2;
-        rocker --home --ssh --git --user --privileged --nvidia --x11 --network host --name $1 devenv:$1 $3
+
+        if [ $# -lt 4 ]; then
+            rocker --home --ssh --git --user --privileged --nvidia --x11 --network host --name $1 devenv:$1
+        else
+            if [ $3 = "pcan" ]; then
+                rocker --home --ssh --git --user --privileged --nvidia --x11 --volume /dev/pcanusb32:/dev/pcanusb32 --network host --name $1 devenv:$1
+            else
+            fi
+        fi
+    fi
+}
+
+function dockexec() {
+    if [ $# -lt 1 ]; then
+        echo "Usage: dockexec <ROS_DISTRO> [workspace] [command]"
+        echo "ROS_DISTRO:"
+        echo "      melodic, noetic, humble, etc."
+        echo "Example:"
+        echo "dockexec noetic neurondones_ws roscore"
+        return 1
+    fi
+
+    # Check if the image exist
+    if [[ "$(docker images -q devenv:$1 2> /dev/null)" == "" ]]; then
+        # build the image
+        echo "Docker image for ${1} does not exist"
+        return 1
+    fi
+
+    # Check if the container exist
+    if [[ $(docker ps -aq -f name=$1) ]]; then
+        # Attach to container
+        if [ $# -lt 2 ]; then
+            docker exec -it $1 bash -c "cd ~/ros/$1 && $ext"
+        else
+            docker exec -it $1 bash -c "cd ~/ros/$1/$2 && $ext"
+        fi
+    else
+        # Launch container
+        echo "Container for ${1} does not exist"
     fi
 }
 
diff --git a/dotfiles/ros.sh b/dotfiles/ros.sh
index 1d14d6a..b179774 100644
--- a/dotfiles/ros.sh
+++ b/dotfiles/ros.sh
@@ -88,7 +88,7 @@ function cbclean(){
     then
         roshome && rm -rf build devel install && catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release
     else
-        rm -rf build devel install && cb
+        rm -rf build log install && cb "$@"
     fi
 }
 
-- 
GitLab