Fix script breaking when run via bash <(curl ...) pipe
Replace `exec < /dev/tty` (which hijacks bash's script-reading fd and causes the rest of the script to be interpreted as shell commands) with per-call `< /dev/tty` redirection on every `read` and prompt `printf`. This preserves bash's ability to continue reading the script from the process substitution while still getting interactive input from the real terminal. https://claude.ai/code/session_01XKYC1basxdwtHy71tky7xm
This commit is contained in:
+11
-18
@@ -11,13 +11,6 @@ readonly MARKER="# Added by openwhispr-easy-setup"
|
||||
readonly GITHUB_API="https://api.github.com/repos/OpenWhispr/openwhispr/releases/latest"
|
||||
readonly TMP_DIR="/tmp/openwhispr-install"
|
||||
|
||||
# ── Ensure interactive input works when piped (bash <(curl ...)) ──────────────
|
||||
# When run via bash <(curl ...), stdin is the curl stream, not the terminal.
|
||||
# We must read user input from /dev/tty instead.
|
||||
if [[ ! -t 0 ]] && [[ -e /dev/tty ]]; then
|
||||
exec < /dev/tty
|
||||
fi
|
||||
|
||||
# ── Colours & formatting ─────────────────────────────────────────────────────
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
@@ -48,8 +41,8 @@ divider() { printf "${DIM}━━━━━━━━━━━━━━━━━━
|
||||
prompt_default() {
|
||||
# Usage: prompt_default "prompt text" "default" VARNAME
|
||||
local prompt="$1" default="$2" varname="$3" reply
|
||||
printf "%s [default: %s]: " "$prompt" "$default"
|
||||
read -r reply
|
||||
printf "%s [default: %s]: " "$prompt" "$default" > /dev/tty
|
||||
read -r reply < /dev/tty
|
||||
reply="${reply:-$default}"
|
||||
printf -v "$varname" '%s' "$reply"
|
||||
}
|
||||
@@ -57,9 +50,9 @@ prompt_default() {
|
||||
prompt_hidden() {
|
||||
# Usage: prompt_hidden "prompt text" VARNAME
|
||||
local prompt="$1" varname="$2" reply
|
||||
printf "%s: " "$prompt"
|
||||
read -rs reply
|
||||
printf "\n"
|
||||
printf "%s: " "$prompt" > /dev/tty
|
||||
read -rs reply < /dev/tty
|
||||
printf "\n" > /dev/tty
|
||||
printf -v "$varname" '%s' "$reply"
|
||||
}
|
||||
|
||||
@@ -123,8 +116,8 @@ This script will:
|
||||
6. Launch OpenWhispr for first-run setup
|
||||
INTRO
|
||||
divider
|
||||
printf "\nPress Enter to continue or Ctrl-C to cancel... "
|
||||
read -r
|
||||
printf "\nPress Enter to continue or Ctrl-C to cancel... " > /dev/tty
|
||||
read -r < /dev/tty
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
# [2/8] Detect distro + arch
|
||||
@@ -183,8 +176,8 @@ fi
|
||||
|
||||
if ! command_exists jq; then
|
||||
warn "jq is required but not installed."
|
||||
printf "Install jq now? [Y/n]: "
|
||||
read -r jq_reply
|
||||
printf "Install jq now? [Y/n]: " > /dev/tty
|
||||
read -r jq_reply < /dev/tty
|
||||
jq_reply="${jq_reply:-Y}"
|
||||
if [[ "${jq_reply,,}" == "y" ]]; then
|
||||
case "$DISTRO_FAMILY" in
|
||||
@@ -526,8 +519,8 @@ case "$CLEANUP_CHOICE" in
|
||||
ollama pull llama3.1
|
||||
|
||||
OLLAMA_INFO
|
||||
printf "Install Ollama now? [Y/n]: "
|
||||
read -r ollama_reply
|
||||
printf "Install Ollama now? [Y/n]: " > /dev/tty
|
||||
read -r ollama_reply < /dev/tty
|
||||
ollama_reply="${ollama_reply:-Y}"
|
||||
if [[ "${ollama_reply,,}" == "y" ]]; then
|
||||
curl -fsSL https://ollama.ai/install.sh | sh || {
|
||||
|
||||
Reference in New Issue
Block a user