From 835d1903208be9a45a5ac8dff2f99f57566d2d3e Mon Sep 17 00:00:00 2001 From: "Stefano C. Coronado" Date: Sat, 28 Dec 2019 13:36:57 -0500 Subject: [PATCH 1/7] add distro detection to avoid unnecessary crashes --- dockergui | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dockergui b/dockergui index 82c33eb..c145c3c 100755 --- a/dockergui +++ b/dockergui @@ -26,9 +26,16 @@ xephyrpid=$! if command -v ratpoison; then sleep 1 ratpoison -d :$DNum & -else # Use the default x window manager installed +else # Use the default x window manager installed based on the host DISPLAY=:$DNum - x-window-manager & + distro_id=$(lsb_release -i | awk '{print($3)}') + + if [ "${distro_id}" == "Ubuntu" ] || [ "${distro_id}" == "Debian" ]; then + x-window-manager & + else + Xorg & #generic case (Fedora, Arch, etc) + fi + fi windowmanagerpid=$! From 65725888c752e100223c6bbaff3caf50dea6fd90 Mon Sep 17 00:00:00 2001 From: "Stefano C. Coronado" Date: Sat, 28 Dec 2019 14:10:43 -0500 Subject: [PATCH 2/7] added primitive podman detection --- dockergui | 42 ++++++++++++++++++++++++++++++++---------- pkg-install | 7 ++++++- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/dockergui b/dockergui index c145c3c..46b8e05 100755 --- a/dockergui +++ b/dockergui @@ -26,7 +26,7 @@ xephyrpid=$! if command -v ratpoison; then sleep 1 ratpoison -d :$DNum & -else # Use the default x window manager installed based on the host +else # Use the default x window manager installed based on lsb_release id DISPLAY=:$DNum distro_id=$(lsb_release -i | awk '{print($3)}') @@ -37,17 +37,39 @@ else # Use the default x window manager installed based on the host fi fi + windowmanagerpid=$! -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 \ - "$@" +#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 \ + "$@" + +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 \ + "$@" + +fi + + kill $windowmanagerpid kill $xephyrpid diff --git a/pkg-install b/pkg-install index 9149b31..0ddc03a 100755 --- a/pkg-install +++ b/pkg-install @@ -45,4 +45,9 @@ RUN yay -S --noconfirm {package_name} ENTRYPOINT [\"/usr/bin/env\", \"{command}\"]" """ -subprocess.run(["docker", "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8') +try: + subprocess.run(["docker", "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8') + +except FileNotFoundError: # primitive way to detect that docker is not installed + subprocess.run(["podman", "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8') + From acdbb116fb2cb53c811abf302c8816b50c65c641 Mon Sep 17 00:00:00 2001 From: "Stefano C. Coronado" Date: Sat, 28 Dec 2019 19:38:58 -0500 Subject: [PATCH 3/7] 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') From ca4a7be675dc155e43847591594dbf1ac5d115f4 Mon Sep 17 00:00:00 2001 From: "Stefano C. Coronado" Date: Sat, 28 Dec 2019 22:14:14 -0500 Subject: [PATCH 4/7] removed generic Xorg call --- dockergui | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dockergui b/dockergui index 46fd26d..9d81960 100755 --- a/dockergui +++ b/dockergui @@ -33,7 +33,12 @@ else # Use the default x window manager installed based on lsb_release id if [ "${distro_id}" == "Ubuntu" ] || [ "${distro_id}" == "Debian" ]; then x-window-manager & else - Xorg & #generic case (Fedora, Arch, etc) + if [ "${XDG_SESSION_DESKTOP}" == "KDE" ]; then + startplasma-x11 & + elif [ "${XDG_SESSION_DESKTOP}" == "GNOME" ]; then + mutter & + fi + fi fi From bed6777595067a23958cc3a7dd10adcf65b337b0 Mon Sep 17 00:00:00 2001 From: "Stefano C. Coronado" Date: Sun, 29 Dec 2019 11:50:36 -0500 Subject: [PATCH 5/7] added clean exit default cases --- dockergui | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dockergui b/dockergui index 9d81960..aa20dcc 100755 --- a/dockergui +++ b/dockergui @@ -27,6 +27,7 @@ if command -v ratpoison; then sleep 1 ratpoison -d :$DNum & else # Use the default x window manager installed based on lsb_release id + DISPLAY=:$DNum distro_id=$(lsb_release -i | awk '{print($3)}') @@ -37,6 +38,10 @@ else # Use the default x window manager installed based on lsb_release id startplasma-x11 & elif [ "${XDG_SESSION_DESKTOP}" == "GNOME" ]; then mutter & + else + printf "%s\n" "Could not find a suitable Window Manager" + exit 1 + fi fi @@ -52,6 +57,9 @@ if command -v docker; then elif command -v podman; then engine_of_choice="podman" +else + printf "%s\n" "Docker/Podman are not installed!" + exit 1 fi # then run the detected container engine From 971e5749f467ea8f0981a0a84c55707700c4ebaa Mon Sep 17 00:00:00 2001 From: "Stefano C. Coronado" Date: Sun, 29 Dec 2019 12:10:08 -0500 Subject: [PATCH 6/7] clean no podman/docker exit case --- pkg-install | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg-install b/pkg-install index 2338b30..f1cd745 100755 --- a/pkg-install +++ b/pkg-install @@ -3,6 +3,7 @@ from argparse import ArgumentParser from getpass import getuser from os import getuid, getgid, getlogin +from shutil import which import subprocess parser = ArgumentParser(description="Install AUR packages into a Docker container") @@ -47,13 +48,19 @@ ENTRYPOINT [\"/usr/bin/env\", \"{command}\"]" # check if either docker or podman are installed -docker_check = subprocess.call(["which", "docker"]) +docker_check = which("docker") -if docker_check != 0: +podman_check = which("podman") + +if docker_check is None: print("Docker not installed, building with Podman") engine = "podman" -else: +elif podman_check is None: engine = "docker" +else: + print("Podman/Docker are not installed! Exiting...") + exit(1) + subprocess.run([engine, "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8') From df637acee41c1c69f54a60536a773f9c24f3daed Mon Sep 17 00:00:00 2001 From: "Stefano C. Coronado" Date: Sun, 29 Dec 2019 13:00:19 -0500 Subject: [PATCH 7/7] caught blind case if engine fails to build when both not installed --- pkg-install | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg-install b/pkg-install index f1cd745..bcfbfb2 100755 --- a/pkg-install +++ b/pkg-install @@ -48,19 +48,18 @@ ENTRYPOINT [\"/usr/bin/env\", \"{command}\"]" # check if either docker or podman are installed -docker_check = which("docker") +try: + if which("docker") is None: + print("Docker not installed, building with Podman") + engine = "podman" + elif which("podman") is None: + engine = "docker" + else: + print("Podman/Docker are not installed! Exiting...") + exit(1) -podman_check = which("podman") -if docker_check is None: - print("Docker not installed, building with Podman") - engine = "podman" -elif podman_check is None: - engine = "docker" -else: - print("Podman/Docker are not installed! Exiting...") + subprocess.run([engine, "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8') +except FileNotFoundError: + print("An Error has occured while attempting to build the image.") exit(1) - - -subprocess.run([engine, "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8') -