Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions distrobox-enter
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ headless=0
# There's no need for them to pass the --root flag option in such cases.
[ "$(id -ru)" -eq 0 ] && rootful=1 || rootful=0
skip_workdir=0
no_envvars=0
additional_envvars=""
Comment thread
89luca89 marked this conversation as resolved.
Outdated
verbose=0
clean_path=0
version="1.8.1.2.1"
Expand Down Expand Up @@ -188,6 +190,9 @@ Options:
--clean-path: reset PATH inside container to FHS standard
--no-tty/-T: do not instantiate a tty
--no-workdir/-nw: always start the container from container's home directory
--no-envvars: don't copy host environment variables (default is to copy whenever reasonable)
--additional-envvars: comma-separated list of additional host environment variables to copy
(overrides --no-envvars)
Comment thread
89luca89 marked this conversation as resolved.
Outdated
--additional-flags/-a: additional flags to pass to the container manager command
--help/-h: show this message
--root/-r: launch podman/docker/lilipod with root privileges. Note that if you need root this is the preferred
Expand Down Expand Up @@ -231,6 +236,17 @@ while :; do
shift
skip_workdir=1
;;
--no-envvars)
shift
no_envvars=1
;;
--additional-envvars)
if [ -n "$2" ]; then
additional_envvars="$2"
shift
shift
fi
;;
Comment thread
89luca89 marked this conversation as resolved.
Outdated
-n | --name)
if [ -n "$2" ]; then
container_name="$2"
Expand Down Expand Up @@ -429,14 +445,21 @@ generate_enter_command()

# Loop through all the environment vars
# and export them to the container.
set +o xtrace
# disable logging for this snippet, or it will be too talkative.
for i in $(printenv | grep '=' | grep -Ev ' |"|`|\$' |
grep -Ev '^(CONTAINER_ID|FPATH|HOST|HOSTNAME|HOME|PATH|PROFILEREAD|SHELL|XDG_SEAT|XDG_VTNR|XDG_.*_DIRS|^_)'); do
# We filter the environment so that we do not have strange variables,
# multiline or containing spaces.
# We also NEED to ignore the HOME variable, as this is set at create time
# and needs to stay that way to use custom home dirs.
if [ "${no_envvars}" -eq 0 ]; then
Comment thread
89luca89 marked this conversation as resolved.
Outdated
set +o xtrace
# disable logging for this snippet, or it will be too talkative.
for i in $(printenv | grep '=' | grep -Ev ' |"|`|\$' |
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After #1811 this needs to be reworked

grep -Ev '^(CONTAINER_ID|FPATH|HOST|HOSTNAME|HOME|PATH|PROFILEREAD|SHELL|XDG_SEAT|XDG_VTNR|XDG_.*_DIRS|^_)'); do
# We filter the environment so that we do not have strange variables,
# multiline or containing spaces.
# We also NEED to ignore the HOME variable, as this is set at create time
# and needs to stay that way to use custom home dirs.
result_command="${result_command}
--env=${i}"
done
fi
# Export all environment variables passed via --additional-envvars
for i in $(echo "$additional_envvars" | sed 's/,/ /g'); do
result_command="${result_command}
--env=${i}"
done
Expand Down
4 changes: 4 additions & 0 deletions docs/usage/distrobox-enter.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ If using it inside a script, an application, or a service, you can specify the

--name/-n: name for the distrobox default: my-distrobox
--/-e: end arguments execute the rest as command to execute at login default: default ${USER}'s shell
--clean-path: reset PATH inside container to FHS standard
--no-tty/-T: do not instantiate a tty
--no-workdir/-nw: always start the container from container's home directory
--no-envvars: don't copy host environment variables (default is to copy whenever reasonable)
Comment thread
89luca89 marked this conversation as resolved.
Outdated
--additional-envvars: comma-separated list of additional host environment variables to copy
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--additional-envvars: comma-separated list of additional host environment variables to copy
--add-env: comma-separated list of additional host environment variables to copy

(overrides --no-envvars)
Comment thread
89luca89 marked this conversation as resolved.
Outdated
--additional-flags/-a: additional flags to pass to the container manager command
--help/-h: show this message
--root/-r: launch podman/docker/lilipod with root privileges. Note that if you need root this is the preferred
Expand Down