Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distrobox-export: improvements, login shell, escaping #869

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 5 additions & 25 deletions distrobox-export
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ extra_flags=""
# DBX_HOST_HOME is set in case container is created
# with custom --home directory
host_home="${DISTROBOX_HOST_HOME:-"${HOME}"}"
sudo=""
dest_path="${host_home}/.local/bin"
is_login=0
is_sudo=0
rootful=""
start_shell=""
verbose=0
version="1.5.0.2"

Expand Down Expand Up @@ -77,7 +75,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 @@ -117,12 +114,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 @@ -222,21 +215,8 @@ if [ -z "${container_name}" ]; then
container_name=$(uname -n | cut -d'.' -f1)
fi

#
if [ "${is_login}" -ne 0 ]; then
if [ "${is_sudo}" -ne 0 ]; then
start_shell="$(command -v sudo) -i"
else
start_shell="$(command -v sudo) -u ${USER} -i"
fi
elif [ "${is_sudo}" -ne 0 ]; then
start_shell="$(command -v sudo)"
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})"
elif [ "${exported_app_label}" = "none" ]; then
Expand All @@ -257,8 +237,8 @@ generate_script() {
# distrobox_binary
# name: ${container_name}
if [ -z "\${CONTAINER_ID}" ]; then
exec "${DISTROBOX_ENTER_PATH:-"distrobox-enter"}" ${rootful} -n ${container_name} -- \
${start_shell} ${exported_bin} ${extra_flags} "\$@"
exec ${DISTROBOX_ENTER_PATH:-"distrobox-enter"} ${rootful} -n ${container_name} -- \
${sudo} sh -lc '${exported_bin} "\$@"' distrobox-export ${extra_flags} "\$@"
elif [ -n "\${CONTAINER_ID}" ] && [ "\${CONTAINER_ID}" != "${container_name}" ]; then
exec distrobox-host-exec ${dest_path}/$(basename "${exported_bin}") ${extra_flags} "\$@"
else
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 @@ -26,7 +26,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 @@ -84,11 +83,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