From 7382af0e365a324c0050501f65e4078ba21c2d7a Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Mon, 5 Jul 2021 23:15:27 +0300
Subject: [PATCH] Migrate workbench to use Podman Toolbox.

- wb shell function to launch tmux inside a toolbox container locally.
- wbr shell function to do the same but on ns4.
- Remove the workbench SSH config, not used now.
- Set the DOCKER_HOST environment variable to the Podman socket in case
  the Docker socket isn't available but the Podman socket is.
- A few aliases (for now flatpak-spawn and podman) that are set if
  running in a toolbox container.
---
 .bashrc                | 22 +++++++++++++++++++++-
 .ssh/config.d/20_shore |  5 -----
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/.bashrc b/.bashrc
index 5a0602f..b341e16 100644
--- a/.bashrc
+++ b/.bashrc
@@ -293,7 +293,11 @@ toux () {
 }
 
 wb () {
-    ssh -t workbench.shore.co.il 'if tmux ls >/dev/null 2>&1; then tmux a; else tmux; fi;'
+    toolbox run --container workbench -- /bin/sh -ic 'if tmux ls >/dev/null 2>&1; then tmux a; else tmux; fi;'
+}
+
+wbr () {
+    ssh -t ns4.shore.co.il toolbox run --container workbench -- /bin/sh -ic "'if tmux ls >/dev/null 2>&1; then tmux a; else tmux; fi;'"
 }
 
 __prompt () {
@@ -380,5 +384,21 @@ then
     ! command -v direnv > /dev/null || eval "$(direnv hook bash)"
 fi
 
+if [ ! -S /var/run/docker.sock ] &&
+    [ -z "${DOCKER_HOST:-}" ] &&
+    [ -S "$XDG_RUNTIME_DIR/podman/podman.sock" ] &&
+    [ -w "$XDG_RUNTIME_DIR/podman/podman.sock" ]
+then
+    export DOCKER_HOST="unix://$XDG_RUNTIME_DIR/podman/podman.sock"
+fi
+
+if [ "$HOSTNAME" = 'toolbox' ]
+then
+    alias flatpak-spawn='/usr/libexec/flatpak-xdg-utils/flatpak-spawn --host'
+    [ ! -S "$XDG_RUNTIME_DIR/podman/podman.sock" ] ||
+        [ ! -w "$XDG_RUNTIME_DIR/podman/podman.sock" ] ||
+        alias podman='podman --remote'
+fi
+
 # shellcheck disable=SC2119
 prune_ssh_sockets
diff --git a/.ssh/config.d/20_shore b/.ssh/config.d/20_shore
index 23c6148..7947d1c 100644
--- a/.ssh/config.d/20_shore
+++ b/.ssh/config.d/20_shore
@@ -18,11 +18,6 @@ IdentityFile ~/.ssh/gitlab_ed25519
 HostName host01.shore.co.il
 Port 2222
 
-Host workbench.shore.co.il
-HostName ns4.shore.co.il
-LocalForward 8080 localhost:8080
-Port 2222
-
 Host *.shore.co.il 192.168.3.*
 IdentityFile ~/.ssh/shore_ecdsa
 IdentityFile ~/.ssh/shore_ed25519
-- 
GitLab