From 1c7866bc0a59835f0c5e65bf6721584a489879d7 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Mar 2026 13:36:28 +0000 Subject: [PATCH 1/2] 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 --- setup-openwhispr.sh | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/setup-openwhispr.sh b/setup-openwhispr.sh index 3dd2929..af3e367 100755 --- a/setup-openwhispr.sh +++ b/setup-openwhispr.sh @@ -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 || { From cc847cff67d01e4037884a56bc72d1e5ef13b84f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Mar 2026 13:37:29 +0000 Subject: [PATCH 2/2] Wrap script in main() to prevent line-by-line execution bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When run via `bash <(curl ...)`, bash reads the script incrementally from a process substitution fd. If a `read < /dev/tty` call disrupts the fd state, bash can lose its place and the remaining script lines get fed to the interactive shell prompt as individual commands. Wrapping everything in main() forces bash to parse the entire script into memory before executing any of it — the standard fix for curl-piped scripts. Also changed README one-liner to download-then-execute pattern (curl -o /tmp/... && bash /tmp/...) as a belt-and-suspenders approach. https://claude.ai/code/session_01XKYC1basxdwtHy71tky7xm --- README.md | 2 +- setup-openwhispr.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6e4075..a940e6d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## Quick install ```bash -bash <(curl -fsSL https://raw.githubusercontent.com/outis1one/openwhispr-easy-setup/main/setup-openwhispr.sh) +curl -fsSL https://raw.githubusercontent.com/outis1one/openwhispr-easy-setup/main/setup-openwhispr.sh -o /tmp/setup-openwhispr.sh && bash /tmp/setup-openwhispr.sh ``` Or clone and run: diff --git a/setup-openwhispr.sh b/setup-openwhispr.sh index af3e367..d65c627 100755 --- a/setup-openwhispr.sh +++ b/setup-openwhispr.sh @@ -3,6 +3,14 @@ # https://github.com/outis1one/openwhispr-easy-setup # License: MIT +# ── Wrap everything in main() so bash reads the entire script before executing. +# This prevents the "line-by-line interpreted as commands" bug when run via: +# bash <(curl -fsSL ...) or curl ... | bash +# Without this wrapper, bash may lose track of the script source after a read +# from /dev/tty and start feeding remaining script lines to the shell prompt. + +main() { + # Do NOT use set -e — we handle errors explicitly readonly SCRIPT_VERSION="1.0.0" @@ -653,3 +661,8 @@ cat <