fix(bootstrap): detect a missing terminal by opening /dev/tty
prompt_install_mode guarded its prompt with `[ ! -r /dev/tty ]`, which never fires on Linux: /dev/tty is mode 0666 whether or not the process has a controlling terminal, and only opening it fails. Without a terminal the menu was printed, the read failed with "No such device or address", and the default was taken by accident rather than by the documented path. The guard now opens /dev/tty in a subshell and takes the "no terminal for a prompt" path when that fails.
This commit is contained in:
2 files changed
+6
-4
No files matched your search
+3
-2
@@ -2240,8 +2240,9 @@ prompt_install_mode() {
|
|||||||
|
|
||||||
# No override: ask on the controlling terminal. Under `curl | sudo bash` stdin
|
# No override: ask on the controlling terminal. Under `curl | sudo bash` stdin
|
||||||
# is the script, so we must read /dev/tty, not stdin. No tty (CI/cloud-init) →
|
# is the script, so we must read /dev/tty, not stdin. No tty (CI/cloud-init) →
|
||||||
# take the default.
|
# take the default. Open it to find out: /dev/tty is mode 0666 on every Linux host, so
|
||||||
if [ ! -r /dev/tty ]; then
|
# `-r` passes even when there is no controlling terminal and only the open fails.
|
||||||
|
if ! (: </dev/tty) 2>/dev/null; then
|
||||||
INSTALL_MODE="$def"
|
INSTALL_MODE="$def"
|
||||||
log "no terminal for a prompt; defaulting to a ${def} install (set FELIS_INSTALL_MODE=full or nano to override)"
|
log "no terminal for a prompt; defaulting to a ${def} install (set FELIS_INSTALL_MODE=full or nano to override)"
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -363,8 +363,9 @@ else
|
|||||||
"$(run_mode "$sdir/felis-nano.service" "$sdir/absent.done")"
|
"$(run_mode "$sdir/felis-nano.service" "$sdir/absent.done")"
|
||||||
expect "a host with the full install re-runs as full" "MODE: full" \
|
expect "a host with the full install re-runs as full" "MODE: full" \
|
||||||
"$(run_mode "$sdir/felis-nano.service" "$sdir/bootstrap.done")"
|
"$(run_mode "$sdir/felis-nano.service" "$sdir/bootstrap.done")"
|
||||||
expect "a fresh host defaults to full" "MODE: full" \
|
out="$(run_mode "$sdir/absent.service" "$sdir/absent.done")"
|
||||||
"$(run_mode "$sdir/absent.service" "$sdir/absent.done")"
|
expect "a fresh host defaults to full" "MODE: full" "$out"
|
||||||
|
expect "no controlling terminal takes the no-prompt path" "LOG: no terminal for a prompt" "$out"
|
||||||
# felis setup goes on to need the control plane, so under it nano is refused, and the
|
# felis setup goes on to need the control plane, so under it nano is refused, and the
|
||||||
# nano-only default above must not apply either.
|
# nano-only default above must not apply either.
|
||||||
expect "felis setup refuses FELIS_INSTALL_MODE=nano" "DIE: felis setup installs the full control plane" \
|
expect "felis setup refuses FELIS_INSTALL_MODE=nano" "DIE: felis setup installs the full control plane" \
|
||||||
|
|||||||
Reference in new issue
Block a user