From f864d67baf1b1c0a54b17d4a6a7f3f79c1e84e6b Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 3 May 2019 19:33:37 +0200 Subject: [PATCH] Create /run/.toolboxenv in 'toolbox enter' for identification This is better than setting an environment variable like TOOLBOX_CONTAINER with 'podman create' because, unlike environment variables, it can't be unset later by commands like su(1) or sudo(8). One nice side-effect of doing it inside 'toolbox enter' is that it will automatically work with older toolbox containers. A subsequent commit will switch to using the /etc/profile.d/toolbox.sh start-up script to set the PS1 instead of doing it as part of the 'podman exec' invocation. Having the identification mechanism work with older toolbox containers is important to avoid breaking the PS1 for backwards compatibility. This reverts commit c7b7fa18679b91c8d1d1ddcb4121988eb9f0ede7 https://github.com/debarshiray/toolbox/pull/148 --- profile.d/toolbox.sh | 2 +- toolbox | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/profile.d/toolbox.sh b/profile.d/toolbox.sh index 97b95df..f0c7aab 100644 --- a/profile.d/toolbox.sh +++ b/profile.d/toolbox.sh @@ -25,7 +25,7 @@ fi if [ -f /run/.containerenv ] \ && ! [ -f "$toolbox_welcome_stub" ] \ - && [ "$TOOLBOX_CONTAINER" != "" ]; then + && [ -f /run/.toolboxenv ]; then echo "" echo "Welcome to the Toolbox; a container where you can install and run" echo "all your tools." diff --git a/toolbox b/toolbox index 512ccfc..5ed020c 100755 --- a/toolbox +++ b/toolbox @@ -941,7 +941,6 @@ create() $prefix_sudo podman create \ $dns_none \ $toolbox_path_set \ - --env TOOLBOX_CONTAINER="$toolbox_container" \ --group-add wheel \ --hostname toolbox \ --name $toolbox_container \ @@ -1083,6 +1082,11 @@ enter() exit 1 fi + if ! $prefix_sudo podman exec --user root:root "$toolbox_container" touch /run/.toolboxenv 2>&3; then + echo "$base_toolbox_command: failed to create /run/.toolboxenv in container $toolbox_container" >&2 + exit 1 + fi + set_environment=$(create_environment_options) echo "$base_toolbox_command: looking for $SHELL in container $toolbox_container" >&3