Skip to content

Commit f27f82a

Browse files
committed
installer + Dockerfile: keep set -u out of user's .bashrc
The previous fix wrapped the installer's 'source /opt/ros/noetic/setup.bash' call with 'set +u; ...; set -u' via a Dockerfile sed. But the same sed also caught the literal 'source /opt/ros/noetic/setup.bash' string inside the installer's `echo "source ..." >> ~/.bashrc` line. The wrapped string then got echoed into the user's .bashrc, leaving every interactive shell with `set -u` active. Any ROS bash helper that references positional args without defaults (roscd $1, rosls $1, ...) errored out with 'bash: $1: unbound variable'. Fix in the installer itself: wrap the actual source calls inline with explicit `set +u` / `set -u` lines (two places — install_ros_noetic and build_workspace). The literal `echo ... >> .bashrc` lines stay plain, so the bashrc gets a clean source command that doesn't toggle nounset. Dockerfile: drop the two sed lines that wrapped the bashrc echoes; they're no longer needed. Verified: .bashrc now ends with source /opt/ros/noetic/setup.bash source /home/uniros/uniros_ws/devel/setup.bash Interactive shells have nounset off, roscd / rosls / etc. work.
1 parent 94b25fa commit f27f82a

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

docker/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ WORKDIR /home/${USERNAME}
112112
# user's HOME so bind mounts on a host with matching UID work cleanly.
113113
COPY --chown=${USERNAME}:${USERNAME} install_uniros_stack.sh /tmp/install_uniros_stack.sh
114114
RUN chmod +x /tmp/install_uniros_stack.sh \
115-
&& sed -i 's@source /opt/ros/noetic/setup.bash@set +u; source /opt/ros/noetic/setup.bash; set -u@' /tmp/install_uniros_stack.sh \
116-
&& sed -i 's@source "$WORKSPACE_PATH/devel/setup.bash" || true@set +u; source "$WORKSPACE_PATH/devel/setup.bash" || true; set -u@' /tmp/install_uniros_stack.sh \
117115
&& UNIROS_INSTALL_IN_DOCKER=1 \
118116
/tmp/install_uniros_stack.sh -y -p /home/${USERNAME}/uniros_ws \
119117
&& sudo rm -f /tmp/install_uniros_stack.sh \

install_uniros_stack.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,13 @@ install_ros_noetic() {
194194
if ! grep -q "source /opt/ros/noetic/setup.bash" "$HOME/.bashrc"; then
195195
echo "source /opt/ros/noetic/setup.bash" >> "$HOME/.bashrc"
196196
fi
197+
# ROS setup.bash references variables that may be unset (and ROS
198+
# bash helpers like roscd reference $1 in function bodies); both
199+
# blow up under `set -u`. Disable nounset just for the source call.
197200
# shellcheck disable=SC1091
201+
set +u
198202
source /opt/ros/noetic/setup.bash
203+
set -u
199204
apt_install python3-rosdep python3-rosinstall python3-rosinstall-generator \
200205
python3-wstool python3-catkin-tools build-essential \
201206
|| fail "Failed to install ROS build tools"
@@ -416,8 +421,13 @@ build_workspace() {
416421
EOF
417422
ok "Created ~/.bash_profile (delegates to ~/.bashrc)."
418423
fi
424+
# Same `set -u` deal as install_ros_noetic — disable nounset for
425+
# the source so workspace setup.bash and ROS bash helpers don't
426+
# explode on unset references.
419427
# shellcheck disable=SC1090
428+
set +u
420429
source "$WORKSPACE_PATH/devel/setup.bash" || true
430+
set -u
421431
ok "Workspace built."
422432
}
423433

0 commit comments

Comments
 (0)