Skip to content

Commit

Permalink
distrobox-export: improvements, login shell, escaping
Browse files Browse the repository at this point in the history
* Do not use sudo if it is not necessary.
* Improve escaping mechanism, always run with sh
* Always use login shell
  • Loading branch information
Clyde Laforge committed Jul 18, 2023
1 parent 40fdc93 commit 446945b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
24 changes: 4 additions & 20 deletions distrobox-export
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ extra_flags=""
# DBX_HOST_HOME is set in case container is created
# with custom --home directory
host_home="${DISTROBOX_HOST_HOME:-"${HOME}"}"
is_login=0
is_sudo=0
sudo=""
rootful=""
start_shell=""
verbose=0
version="1.5.0.2"

Expand Down Expand Up @@ -76,7 +74,6 @@ Options:
Defaults to (on \$container_name)
--export-path/-ep: path where to export the binary
--extra-flags/-ef: extra flags to add to the command
--login/-l run the exported item in a login shell
--sudo/-S: specify if the exported item should be run as sudo
--help/-h: show this message
--verbose/-v: show more verbosity
Expand Down Expand Up @@ -116,12 +113,8 @@ while :; do
shift
fi
;;
-l | --login)
is_login=1
shift
;;
-S | --sudo)
is_sudo=1
sudo="sudo"
shift
;;
-el | --export-label)
Expand Down Expand Up @@ -221,17 +214,8 @@ if [ -z "${container_name}" ]; then
container_name=$(uname -n | cut -d'.' -f1)
fi

#
if [ "${is_login}" -ne 0 ] && [ "${is_sudo}" -ne 0 ]; then
start_shell="sudo -i"
elif [ "${is_login}" -ne 0 ]; then
start_shell="sudo -u ${USER} -i"
else
start_shell=""
fi

# Prefix to add to an existing command to work through the container
container_command_prefix="${DISTROBOX_ENTER_PATH:-"distrobox-enter"} ${rootful} -n ${container_name} -- ${start_shell} "
container_command_prefix="${DISTROBOX_ENTER_PATH:-"distrobox-enter"} ${rootful} -n ${container_name} -- ${sudo} "
if [ -z "${exported_app_label}" ]; then
exported_app_label=" (on ${container_name})"
fi
Expand All @@ -248,7 +232,7 @@ generate_script() {
# name: ${container_name}
if [ -z "\${CONTAINER_ID}" ]; then
exec ${DISTROBOX_ENTER_PATH:-"distrobox-enter"} ${rootful} -n ${container_name} -- \
${start_shell} ${exported_bin} ${extra_flags} "\$@"
${sudo} sh -lc '${exported_bin} "\$@"' distrobox-export ${extra_flags} "\$@"
else
exec ${exported_bin} "\$@"
fi
Expand Down
6 changes: 0 additions & 6 deletions docs/usage/distrobox-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ automatically be launched from the container it is exported from.
Defaults to (on \$container_name)
--export-path/-ep: path where to export the binary
--extra-flags/-ef: extra flags to add to the command
--login/-l run the exported item in a login shell
--sudo/-S: specify if the exported item should be run as sudo
--help/-h: show this message
--verbose/-v: show more verbosity
Expand Down Expand Up @@ -83,11 +82,6 @@ The option "--delete" will un-export an app or binary

The option "--sudo" will launch the exported item as root inside the distrobox.

**Run inside a login shell**

The option "--login" will launch the exported item inside a login shell, allowing access to
variables sourced at login in the container (e.g: /etc/profile).

**Exporting apps from rootful containers**

It is worth noting that, when exporting any item - which includes graphical apps - from rootful
Expand Down

0 comments on commit 446945b

Please sign in to comment.