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 GITHUB_API="https://api.github.com/repos/OpenWhispr/openwhispr/releases/latest"
|
||||||
readonly TMP_DIR="/tmp/openwhispr-install"
|
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 ─────────────────────────────────────────────────────
|
# ── Colours & formatting ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
@@ -48,8 +41,8 @@ divider() { printf "${DIM}━━━━━━━━━━━━━━━━━━
|
|||||||
prompt_default() {
|
prompt_default() {
|
||||||
# Usage: prompt_default "prompt text" "default" VARNAME
|
# Usage: prompt_default "prompt text" "default" VARNAME
|
||||||
local prompt="$1" default="$2" varname="$3" reply
|
local prompt="$1" default="$2" varname="$3" reply
|
||||||
printf "%s [default: %s]: " "$prompt" "$default"
|
printf "%s [default: %s]: " "$prompt" "$default" > /dev/tty
|
||||||
read -r reply
|
read -r reply < /dev/tty
|
||||||
reply="${reply:-$default}"
|
reply="${reply:-$default}"
|
||||||
printf -v "$varname" '%s' "$reply"
|
printf -v "$varname" '%s' "$reply"
|
||||||
}
|
}
|
||||||
@@ -57,9 +50,9 @@ prompt_default() {
|
|||||||
prompt_hidden() {
|
prompt_hidden() {
|
||||||
# Usage: prompt_hidden "prompt text" VARNAME
|
# Usage: prompt_hidden "prompt text" VARNAME
|
||||||
local prompt="$1" varname="$2" reply
|
local prompt="$1" varname="$2" reply
|
||||||
printf "%s: " "$prompt"
|
printf "%s: " "$prompt" > /dev/tty
|
||||||
read -rs reply
|
read -rs reply < /dev/tty
|
||||||
printf "\n"
|
printf "\n" > /dev/tty
|
||||||
printf -v "$varname" '%s' "$reply"
|
printf -v "$varname" '%s' "$reply"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,8 +116,8 @@ This script will:
|
|||||||
6. Launch OpenWhispr for first-run setup
|
6. Launch OpenWhispr for first-run setup
|
||||||
INTRO
|
INTRO
|
||||||
divider
|
divider
|
||||||
printf "\nPress Enter to continue or Ctrl-C to cancel... "
|
printf "\nPress Enter to continue or Ctrl-C to cancel... " > /dev/tty
|
||||||
read -r
|
read -r < /dev/tty
|
||||||
|
|
||||||
# ══════════════════════════════════════════════════════════════════════════════
|
# ══════════════════════════════════════════════════════════════════════════════
|
||||||
# [2/8] Detect distro + arch
|
# [2/8] Detect distro + arch
|
||||||
@@ -183,8 +176,8 @@ fi
|
|||||||
|
|
||||||
if ! command_exists jq; then
|
if ! command_exists jq; then
|
||||||
warn "jq is required but not installed."
|
warn "jq is required but not installed."
|
||||||
printf "Install jq now? [Y/n]: "
|
printf "Install jq now? [Y/n]: " > /dev/tty
|
||||||
read -r jq_reply
|
read -r jq_reply < /dev/tty
|
||||||
jq_reply="${jq_reply:-Y}"
|
jq_reply="${jq_reply:-Y}"
|
||||||
if [[ "${jq_reply,,}" == "y" ]]; then
|
if [[ "${jq_reply,,}" == "y" ]]; then
|
||||||
case "$DISTRO_FAMILY" in
|
case "$DISTRO_FAMILY" in
|
||||||
@@ -526,8 +519,8 @@ case "$CLEANUP_CHOICE" in
|
|||||||
ollama pull llama3.1
|
ollama pull llama3.1
|
||||||
|
|
||||||
OLLAMA_INFO
|
OLLAMA_INFO
|
||||||
printf "Install Ollama now? [Y/n]: "
|
printf "Install Ollama now? [Y/n]: " > /dev/tty
|
||||||
read -r ollama_reply
|
read -r ollama_reply < /dev/tty
|
||||||
ollama_reply="${ollama_reply:-Y}"
|
ollama_reply="${ollama_reply:-Y}"
|
||||||
if [[ "${ollama_reply,,}" == "y" ]]; then
|
if [[ "${ollama_reply,,}" == "y" ]]; then
|
||||||
curl -fsSL https://ollama.ai/install.sh | sh || {
|
curl -fsSL https://ollama.ai/install.sh | sh || {
|
||||||
|
|||||||
Reference in New Issue
Block a user