From c8db8b5ca837d0b4662828af63156da7ebbbca82 Mon Sep 17 00:00:00 2001 From: Jakub Delicat Date: Wed, 24 Jul 2024 11:36:47 +0200 Subject: [PATCH] fixed healthcheck_node.sh --- run_healthcheck_node.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/run_healthcheck_node.sh b/run_healthcheck_node.sh index 5ed31ae..84504b4 100644 --- a/run_healthcheck_node.sh +++ b/run_healthcheck_node.sh @@ -1,2 +1,15 @@ -source "/ros2_ws_healthcheck/install/setup.bash" -gosu $USER bash -c "ros2 run healthcheck_pkg healthcheck_node &" +if [ ! -z "$USER" ] && [ "$USER" != "root" ] && [ "$USER" != "$(whoami)" ]; then + # Check if the user already exists; if not, create the user + if ! id "$USER" &>/dev/null; then + useradd -ms /bin/bash "$USER" + echo "[ \"\$(whoami)\" != \"$USER\" ] && su - \"$USER\"" >> /etc/bash.bashrc + fi + + source "/ros2_ws_healthcheck/install/setup.bash" + + exec gosu $USER /bin/bash -c "ros2 run healthcheck_pkg healthcheck_node &" + +else + source "/ros2_ws_healthcheck/install/setup.bash" + ros2 run healthcheck_pkg healthcheck_node & +fi