Skip to content

Commit

Permalink
create: revert 52a34fb, docker cp does not work well with btrfs syste…
Browse files Browse the repository at this point in the history
…ms, Fix #399

Signed-off-by: Luca Di Maio <[email protected]>
  • Loading branch information
89luca89 committed Sep 16, 2022
1 parent 75f4984 commit 1ad3204
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
22 changes: 22 additions & 0 deletions distrobox-create
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions distrobox-enter
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1ad3204

Please sign in to comment.