From acdbb116fb2cb53c811abf302c8816b50c65c641 Mon Sep 17 00:00:00 2001 From: "Stefano C. Coronado" Date: Sat, 28 Dec 2019 19:38:58 -0500 Subject: [PATCH] cleaned up podman/docker detection --- dockergui | 37 ++++++++++++++----------------------- pkg-install | 14 ++++++++++---- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/dockergui b/dockergui index 46b8e05..46fd26d 100755 --- a/dockergui +++ b/dockergui @@ -43,32 +43,23 @@ windowmanagerpid=$! #detect podman or docker if command -v docker; then - - docker run --net=host \ - --rm \ - -e DISPLAY=:$DNum \ - -v /tmp/.X11-unix/X$DNum:/tmp/.X11-unix/X$DNum:rw \ - --user $(id -u):$(id -g) \ - --group-add audio \ - --cap-drop=ALL \ - --shm-size 2g \ - "$@" - + engine_of_choice="docker" + elif command -v podman; then - - - podman run --net=host \ - --rm \ - -e DISPLAY=:$DNum \ - -v /tmp/.X11-unix/X$DNum:/tmp/.X11-unix/X$DNum:rw \ - --user $(id -u):$(id -g) \ - --group-add audio \ - --cap-drop=ALL \ - --shm-size 2g \ - "$@" - + engine_of_choice="podman" fi +# then run the detected container engine + +$engine_of_choice run --net=host \ + --rm \ + -e DISPLAY=:$DNum \ + -v /tmp/.X11-unix/X$DNum:/tmp/.X11-unix/X$DNum:rw \ + --user $(id -u):$(id -g) \ + --group-add audio \ + --cap-drop=ALL \ + --shm-size 2g \ + "$@" kill $windowmanagerpid kill $xephyrpid diff --git a/pkg-install b/pkg-install index 0ddc03a..2338b30 100755 --- a/pkg-install +++ b/pkg-install @@ -45,9 +45,15 @@ RUN yay -S --noconfirm {package_name} ENTRYPOINT [\"/usr/bin/env\", \"{command}\"]" """ -try: - subprocess.run(["docker", "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8') +# check if either docker or podman are installed -except FileNotFoundError: # primitive way to detect that docker is not installed - subprocess.run(["podman", "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8') +docker_check = subprocess.call(["which", "docker"]) + +if docker_check != 0: + print("Docker not installed, building with Podman") + engine = "podman" +else: + engine = "docker" + +subprocess.run([engine, "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8')