diff --git a/distrobox-create b/distrobox-create index 5a132a1e..2d98d413 100755 --- a/distrobox-create +++ b/distrobox-create @@ -62,6 +62,18 @@ distrobox_sudo_program="sudo" dryrun=0 init=0 non_interactive=0 +# Use cd + dirname + pwd so that we do not have relative paths in mount points +# We're not using "realpath" here so that symlinks are not resolved this way +# "realpath" would break situations like Nix or similar symlink based package +# management. +distrobox_entrypoint_path="$(cd "$(dirname "${0}")" && pwd)/distrobox-init" +distrobox_export_path="$(cd "$(dirname "${0}")" && pwd)/distrobox-export" +distrobox_hostexec_path="$(cd "$(dirname "${0}")" && pwd)/distrobox-host-exec" +# In case init or export are not in the same path as create, let's search +# in PATH for them. +[ ! -e "${distrobox_entrypoint_path}" ] && distrobox_entrypoint_path="$(command -v distrobox-init)" +[ ! -e "${distrobox_export_path}" ] && distrobox_export_path="$(command -v distrobox-export)" +[ ! -e "${distrobox_hostexec_path}" ] && distrobox_hostexec_path="$(command -v distrobox-hostexec)" rootful=0 verbose=0 version="1.4.1" @@ -426,6 +438,9 @@ generate_command() { --volume /dev:/dev:rslave --volume /sys:/sys:rslave --volume /tmp:/tmp:rslave + --volume \"${distrobox_entrypoint_path}\":/usr/bin/entrypoint:ro + --volume \"${distrobox_export_path}\":/usr/bin/distrobox-export:ro + --volume \"${distrobox_hostexec_path}\":/usr/bin/distrobox-host-exec:ro --volume \"${container_user_home}\":\"${container_user_home}\":rslave" # This fix is needed as on Selinux systems, the host's selinux sysfs directory @@ -561,6 +576,13 @@ generate_command() { printf "%s" "${result_command}" } +# Check that we have a complete distrobox installation or +# entrypoint and export will not work. +if [ -z "${distrobox_entrypoint_path}" ] || [ -z "${distrobox_export_path}" ]; then + printf >&2 "Error: no distrobox-init found in %s\n" "${PATH}" + exit 127 +fi + # dry run mode, just generate the command and print it. No creation. if [ "${dryrun}" -ne 0 ]; then if [ -n "${container_clone}" ]; then diff --git a/distrobox-enter b/distrobox-enter index 3a724e91..49d283f1 100755 --- a/distrobox-enter +++ b/distrobox-enter @@ -38,15 +38,6 @@ if [ "$(id -u)" -eq 0 ]; then exit 1 fi -# Finx components we need to copy inside the container. -distrobox_entrypoint_path="$(dirname "$(realpath "${0}")")/distrobox-init" -distrobox_export_path="$(dirname "$(realpath "${0}")")/distrobox-export" -distrobox_hostexec_path="$(dirname "$(realpath "${0}")")/distrobox-host-exec" -# In case init or export are not in the same path as create, let's search -# in PATH for them. -[ ! -e "${distrobox_entrypoint_path}" ] && distrobox_entrypoint_path="$(command -v distrobox-init)" -[ ! -e "${distrobox_export_path}" ] && distrobox_export_path="$(command -v distrobox-export)" -[ ! -e "${distrobox_hostexec_path}" ] && distrobox_hostexec_path="$(command -v distrobox-hostexec)" # Defaults container_command="" container_image="" @@ -444,15 +435,6 @@ if [ "${container_status}" != "running" ]; then printf >&2 "run this command to follow along:\n\n" printf >&2 " %s logs -f %s\n\n" "${container_manager}" "${container_name}" - # IMPORTANT STEP: - # - # Before starting, ensure we copy the entrypoint, the export and the host-exec utilities. - # This approach should solve the location-dependency, on systems like NixOS, or - # If one wants to change the installation path of distrobox (eg: from /usr/bin to ~/.local/bin). - ${container_manager} cp "${distrobox_entrypoint_path}" "${container_name}":/usr/bin/entrypoint - ${container_manager} cp "${distrobox_export_path}" "${container_name}":/usr/bin/distrobox-export - ${container_manager} cp "${distrobox_hostexec_path}" "${container_name}":/usr/bin/distrobox-host-exec - log_timestamp="$(date +%FT%T.%N%:z)" ${container_manager} start "${container_name}" > /dev/null # Check if the container is going in error status earlier than the