Skip to content

Commit 281fdb2

Browse files
authored
Probe /dev/tty by opening it, not by testing permission bits (#5)
[ -r /dev/tty ] passes in environments where the device exists but cannot be opened (macOS reports 'Device not configured' only on open). The installer then tried to prompt anyway: three open errors and a retry loop instead of the clean 'no terminal — set QBRAID_API_KEY and re-run' message. Verified both directions: under a real pty (script(1)) the probe yields /dev/tty; with the unopenable device it yields empty and the installer dies with the instruction.
1 parent 559fbd7 commit 281fdb2

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎install.sh‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ die() { printf '\n%serror:%s %s\n' "$red" "$rst" "$*" >&2; exit 1; }
7575
# When this script is piped from curl, stdin is the script itself — prompts
7676
# must read the keyboard directly. If there is no terminal at all (CI), the
7777
# install has to be driven entirely by environment variables.
78+
# `[ -r /dev/tty ]` passes even where the device cannot actually be opened
79+
# (some CI harnesses report "Device not configured" only on open), so probe by
80+
# really opening it in both directions.
7881
TTY=""
79-
if [ -r /dev/tty ] && [ -w /dev/tty ]; then TTY=/dev/tty; fi
82+
if (exec 3</dev/tty) 2>/dev/null && (exec 3>/dev/tty) 2>/dev/null; then TTY=/dev/tty; fi
8083

8184
prompt() { # prompt <question> -> echoes the answer
8285
local q="$1" reply=""

0 commit comments

Comments
 (0)