From 1c7ce2a018a081dd90dfefee6d1ca7e0c9fd66d9 Mon Sep 17 00:00:00 2001
From: Graham Christensen <graham@grahamc.com>
Date: Thu, 13 Jul 2017 17:22:54 -0400
Subject: [PATCH] Assume yes if we have no TTY

Starve the TTY of input to ensure this works, but provide yes to the
current installer to handle the current broken case.
---
 scripts/install-darwin-multi-user.sh | 11 +++++++++++
 tests/install-darwin.sh              |  5 +++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/scripts/install-darwin-multi-user.sh b/scripts/install-darwin-multi-user.sh
index 01a0e4ffb..368d9957e 100644
--- a/scripts/install-darwin-multi-user.sh
+++ b/scripts/install-darwin-multi-user.sh
@@ -43,6 +43,12 @@ readonly EXTRACTED_NIX_PATH="$(dirname "$0")"
 
 readonly ROOT_HOME="/var/root"
 
+if [ -t 0 ]; then
+    readonly IS_HEADLESS='no'
+else
+    readonly IS_HEADLESS='yes'
+fi
+
 contactme() {
     echo "We'd love to help if you need it."
     echo ""
@@ -173,6 +179,11 @@ failure() {
 ui_confirm() {
     _textout "$GREEN$GREEN_UL" "$1"
 
+    if [ "$IS_HEADLESS" = "yes" ]; then
+        echo "No TTY, assuming you would say yes :)"
+        return 0
+    fi
+
     local prompt="[y/n] "
     echo -n "$prompt"
     while read -r y; do
diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh
index d2a7ab456..b7f874672 100755
--- a/tests/install-darwin.sh
+++ b/tests/install-darwin.sh
@@ -53,7 +53,8 @@ trap finish EXIT
 
 # First setup Nix
 cleanup
-curl https://nixos.org/nix/install | bash
+curl -o install https://nixos.org/nix/install
+yes | bash ./install
 verify
 
 
@@ -82,7 +83,7 @@ verify
 
     cleanup
 
-    yes | ./install
+    echo -n "" | ./install
     verify
 
     cleanup
-- 
GitLab