scripts/bin/bazel: be smart about allocating TTYs

Allocating a TTY when output is being redirected results in improper
mapping of stdout/stderr and everything gets mangled into stdout. This
breaks scripting our wrapped Bazel. This changes the wrapper to only
allocate a TTY if the output is one as well.

Change-Id: I5683020b5d89f3a7c7760db0fce3e9e8c628d326
Reviewed-on: https://review.monogon.dev/c/monogon/+/643
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/scripts/bin/bazel b/scripts/bin/bazel
index aba155b..091242a 100755
--- a/scripts/bin/bazel
+++ b/scripts/bin/bazel
@@ -6,4 +6,10 @@
     exit 1
 fi
 
-exec podman exec -it monogon-dev bazel --output_user_root ${HOME}/.cache/bazel-monogon "$@"
+if [ -t 1 ]; then
+  EXTRA_ARGS=-t
+else
+  EXTRA_ARGS=
+fi
+
+exec podman exec -i $EXTRA_ARGS monogon-dev bazel --output_user_root ${HOME}/.cache/bazel-monogon "$@"