From 175ad8e3be7b324cf56154b718c07546de9b75c9 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Thu, 29 Jun 2023 14:02:50 +0200 Subject: [PATCH] backup-fs: Attempt to fix input some more --- opt/backup-fs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/opt/backup-fs b/opt/backup-fs index 9db16b2..1632239 100644 --- a/opt/backup-fs +++ b/opt/backup-fs @@ -1,10 +1,17 @@ #!/usr/bin/env bash +# used to work around cases where stdin is unavailable or not a terminal +if bash -c ': > /dev/tty' > /dev/null 2>&1; then + TTY_OR_CONSOLE="/dev/tty" +else + TTY_OR_CONSOLE="/dev/console" +fi + + function yesno { unset DISCARD_ME while [ -z "$DISCARD_ME" ]; do - # get input from /dev/tty to work around missing stdin - read -p "[y/n] " -n1 DISCARD_ME < /dev/tty + read -p "[y/n] " -n1 DISCARD_ME < $TTY_OR_CONSOLE case "$DISCARD_ME" in y) return 0 @@ -25,14 +32,14 @@ function yesno { cat /proc/mounts read -p " -press any key" -n1 DISCARD_ME < /dev/tty +press any key" -n1 DISCARD_ME < $TTY_OR_CONSOLE # And no services running? ps aux | grep -vF "[kworker" read -p " -press any key" -n1 DISCARD_ME < /dev/tty +press any key" -n1 DISCARD_ME < $TTY_OR_CONSOLE #TODO: remove above debugging sanity checks