From f4680da3e2022060a5fb27b68e3f1bc74c4134c5 Mon Sep 17 00:00:00 2001 From: 89luca89 Date: Sun, 12 Dec 2021 22:47:45 +0100 Subject: [PATCH] create: check if container exists using inspect enter: improve regex to check if a container is started --- distrobox-create | 10 +++++----- distrobox-enter | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/distrobox-create b/distrobox-create index c14dd0bebe..c2723c47cb 100755 --- a/distrobox-create +++ b/distrobox-create @@ -112,8 +112,7 @@ generate_command() { fi result_command="${result_command} --env=\"XDG_RUNTIME_DIR=/run/user/${container_user_uid}\" - --hostname ${container_name} - --ipc host" + --hostname ${container_name}" # mount useful stuff inside the container. # we also mount host's root filesystem to /run/host, to be # able to syphon dynamic configurations from the host @@ -121,6 +120,7 @@ generate_command() { # also mount the distrobox-init utility as the container entrypoint result_command="${result_command} --name ${container_name} --env=\"SHELL=${SHELL}\" + --ipc host --network host --pid host --privileged @@ -207,8 +207,8 @@ if [ -z "$(podman images -q "${container_image}")" ]; then fi # Check if the container already exists. -if podman ps -a | grep -q "${container_name}\$"; then - printf "Distrobox named '%s' already exists." "${container_name}" +if podman inspect "${container_name}" >/dev/null 2>&1; then + printf "Distrobox named '%s' already exists.\n" "${container_name}" printf "To enter, run:\n" printf "\tdistrobox-enter --name %s\n" "${container_name}" exit 0 @@ -219,7 +219,7 @@ cmd="$(generate_command)" # Eval the generated command. If successful display an helpful message. # shellcheck disable=SC2086 if eval ${cmd}; then - printf "Distrobox '%s' successfully created." "${container_name}" + printf "Distrobox '%s' successfully created.\n" "${container_name}" printf "To enter, run:\n" printf "\tdistrobox-enter --name %s\n" "${container_name}" fi diff --git a/distrobox-enter b/distrobox-enter index ba70f06a14..5a563a91b7 100755 --- a/distrobox-enter +++ b/distrobox-enter @@ -92,7 +92,7 @@ fi # prints the podman command to enter the distrobox container generate_command() { # If the container is not already running, we need to start if first - if ! podman ps | grep -q "${container_name}\$"; then + if ! podman ps | grep -qE "(^| )${container_name}( |$)"; then # if container is not running, start it first if ! podman start "${container_name}" >/dev/null; then