pkg/utils: Preserve environment variables for Bash's history facility

Any system-wide customization to Bash's history facilities done through
a custom /etc/profile.d configuration snippet on the host operating
system gets lost inside the Toolbx container.

This is because Toolbx doesn't know what name to expect for the custom
/etc/profile.d snippet on the host, and, hence, can't give access to it
through a bind mount or symbolic link inside the container.  The user
can definitely set up their own symbolic link inside the container to a
snippet inside /run/host/etc/profile.d.  However, it's tedious to do
that for all containers, and the user may not even know that they are
missing the customization until they notice something wrong with the
history, which is shared across all containers and the host, and at that
point they might have already lost commands that they can't easily
reconstruct.

Therefore, it's worth trying to improve the situation by default.

This tries to preserve the environment variables used to customize
Bash's history facilities [1] across the host operating system and
Toolbx container.  It assumes that the Bash start-up scripts inside the
container won't overwrite any of the propagated variables, which might
not always be the case [2].

[1] https://www.gnu.org/software/bash/manual/html_node/Bash-History-Facilities.html
    https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html

[2] https://pagure.io/setup/pull-request/48

https://github.com/containers/toolbox/issues/1359
This commit is contained in:
Debarshi Ray 2023-09-29 15:01:24 +02:00
parent 540b13cd0b
commit 5cdd30efd3

View file

@ -84,6 +84,12 @@ var (
"DBUS_SYSTEM_BUS_ADDRESS",
"DESKTOP_SESSION",
"DISPLAY",
"HISTCONTROL",
"HISTFILE",
"HISTFILESIZE",
"HISTIGNORE",
"HISTSIZE",
"HISTTIMEFORMAT",
"LANG",
"SHELL",
"SSH_AUTH_SOCK",