Skip to content

Commit

Permalink
Fix mount routine (#5)
Browse files Browse the repository at this point in the history
* create: check that a folder exists before adding volume in podman

* install: fix basedir chmod

* create: let distrobox-export path to be optional

* create: improve error message for missing distrobox-init

* podman: when we use verbose, also podman should be verbose

* arguments: use also full word for verbose

* README: add brief explanation of all the tools
  • Loading branch information
89luca89 authored Dec 2, 2021
1 parent c6491a7 commit 99b187f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ All the props goes to them as they had the great idea to implement this stuff.

Simply put it's a fancy `podman` wrapper to create and start containers highly integrated with the hosts.

It is divided in 4 parts:

- `distrobox-create` - creates the container
- `distrobox-enter` - to enter the container
- `distrobox-init` - it's the entrypoint of the container (not meant to be used manually)
- `distrobox-export` - it is meant to be used inside the container, useful to export apps and services from the container to the host

## Why?

The intention is to provide a mutable environment on a host where the file-system is immutable (like Suse's MicroOS, Fedora Silverblue, Endless OS or SteamOS3)
Expand Down Expand Up @@ -64,8 +71,6 @@ user 0m0,116s
sys 0m0,063s
```

It is included also a `distrobox-export` functionality to export applications and services from the container onto the host.

# Compatibility

This project does **not need** a dedicated image but can use normal images in example from docker hub.
Expand Down
39 changes: 27 additions & 12 deletions distrobox-create
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ while :; do
show_help
exit
;;
-v)
-v | --verbose)
verbose=1
shift
;;
Expand Down Expand Up @@ -88,10 +88,16 @@ fi
# Outputs:
# prints the podman command to create the distrobox container
generate_command() {

host_folders="/ /etc /media /mnt /run /tmp /usr /var"

# Set the container hostname the same as the container name.
# use the host's namespace for ipc, network, pid, ulimit
echo "podman create
--dns none
echo "podman create"
if [ "${verbose}" -ne 0 ]; then
echo "--log-level debug"
fi
echo "--dns none
--env XDG_RUNTIME_DIR=/run/user/${container_user_uid}
--hostname ${container_name}
--ipc host"
Expand All @@ -114,41 +120,50 @@ generate_command() {
--user root:root
--userns keep-id
--volume ${distrobox_entrypoint_path}:/usr/bin/entrypoint:ro"

# let's check if we can include distrobox-export or not
if [ -n "${distrobox_export_path}" ]; then
echo "--volume ${distrobox_export_path}:/usr/bin/distrobox-export:ro"
fi

echo "--volume ${container_user_home}:${container_user_home}:rslave
--volume /:/run/host:rslave
--volume /dev:/dev:rslave
--volume /etc:/run/host/etc
--volume /media:/media:rslave
--volume /mnt:/mnt:rslave
--volume /run:/run/host/run:rslave
--volume /tmp:/run/host/tmp:rslave
--volume /usr:/run/host/usr:rw,rslave
--volume /var:/run/host/var:rslave"
--volume /dev:/dev:rslave"

# Check if host folder exists before mounting it
for host_folder in ${host_folders}; do
if [ -d "${host_folder}" ]; then
echo "--volume "${host_folder}":/run/host"${host_folder}":rslave"
fi
done

if [ -d /run/media ]; then
echo "--volume /run/media:/run/media:rslave"
fi

# mount also the XDG_RUNTIME_DIR to ensure functionality of the apps
if [ -d /run/user/"${container_user_uid}" ]; then
echo "--volume /run/user/${container_user_uid}:/run/user/${container_user_uid}"
fi

# find all the user's socket and mount them inside the container
# this will allow for continuity of functionality between host and container
# for example using `podman --remote` to control the host's podman from inside
# the container
for socket in $(find /run -iname "*socket" ! -path "/run/user/*" 2>/dev/null); do
echo "--volume ${socket}:${socket}"
done

# now execute the entrypoint, refer to `distrobox-init -h` for instructions
echo "${container_image}
/usr/bin/entrypoint -v --name ${container_user_name}
--user ${container_user_uid} --group ${container_user_gid}
--home ${container_user_home}"
}

# check that we have a complete distrobox installation or
# entrypoint and export will not work.
[ -z "${distrobox_entrypoint_path}" ] && echo "Error: no distrobox-init found in $PATH" && exit 1

# First, check if the image exists in the host
if ! podman image exists "${container_image}"; then
echo "Image not found, run this command first:"
Expand Down
8 changes: 6 additions & 2 deletions distrobox-enter
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ while :; do
show_help
exit
;;
-v)
-v | --verbose)
shift
verbose=1
;;
Expand Down Expand Up @@ -103,7 +103,11 @@ generate_command() {
fi

# entering container using our user and workdir
echo "podman exec --interactive --tty --user=${USER} --workdir=${HOME}"
echo "podman exec"
if [ "${verbose}" -ne 0 ]; then
echo "--log-level debug"
fi
echo "--interactive --tty --user=${USER} --workdir=${HOME}"
echo "--env=DISTROBOX_ENTER_PATH=$(command -v distrobox-enter)"
# exporting current environment to container
for i in $(printenv | grep '=' | head -n -2); do
Expand Down
2 changes: 1 addition & 1 deletion distrobox-export
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ while :; do
show_help
exit
;;
-v)
-v | --verbose)
shift
verbose=1
;;
Expand Down
2 changes: 1 addition & 1 deletion distrobox-init
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ while :; do
show_help
exit
;;
-v)
-v | --verbose)
shift
verbose=1
;;
Expand Down
4 changes: 2 additions & 2 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ while :; do
show_help
exit
;;
-v)
-v | --verbose)
shift
verbose=1
;;
Expand Down Expand Up @@ -87,7 +87,7 @@ else
# deploy our files
for file in "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')"/distrobox-*; do
cp "${file}" "${dest_path}"
chmod 0755 "${dest_path}/${file}"
chmod 0755 "${dest_path}/$(basename ${file})"
done

# securely delete unneeded files
Expand Down

0 comments on commit 99b187f

Please sign in to comment.