From a83058a1c7780109b655f485ec97fd819b0df30e Mon Sep 17 00:00:00 2001 From: Eusener Castilho Date: Sun, 22 Nov 2026 06:59:42 -0300 Subject: [PATCH] fix(catalog): cede o terminal ao instalador do lerd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O install.sh do lerd faz perguntas via /dev/tty (modo de DNS, pacotes, lerd install). Rodando num process group próprio, sem terminal, a leitura levava SIGTTIN e a instalação ficava parada para sempre. Novo campo `interactive` nos métodos do catálogo: o backend script marca o comando com Stdin e a TUI cede o terminal, como já faz com chsh e sudo -v. --- catalog/items/lerd.yaml | 1 + internal/backend/backend_test.go | 13 +++++++++++++ internal/backend/script.go | 4 ++-- internal/catalog/types.go | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/catalog/items/lerd.yaml b/catalog/items/lerd.yaml index 67dfeb6..02bd452 100644 --- a/catalog/items/lerd.yaml +++ b/catalog/items/lerd.yaml @@ -15,3 +15,4 @@ detect: install: - backend: script url: https://lerd.sh/install.sh + interactive: true # pergunta o modo de DNS e confirmações via /dev/tty diff --git a/internal/backend/backend_test.go b/internal/backend/backend_test.go index 959e9ea..d97df72 100644 --- a/internal/backend/backend_test.go +++ b/internal/backend/backend_test.go @@ -207,6 +207,19 @@ func TestMiseLatestParses(t *testing.T) { } } +// Instaladores que perguntam via /dev/tty (lerd) precisam do terminal: sem Stdin ficam parados em SIGTTIN. +func TestScriptInteractive(t *testing.T) { + b := get(t, "script") + if b.Install(catalog.Method{URL: "https://x.dev/i.sh"}, "", ubuntu)[0].Stdin { + t.Fatal("script must not take the terminal by default") + } + for _, m := range []catalog.Method{{URL: "https://lerd.sh/install.sh", Interactive: true}, {Inline: "x", Interactive: true}} { + if !b.Install(m, "", ubuntu)[0].Stdin || !b.Update(m, ubuntu)[0].Stdin { + t.Fatalf("interactive script must take the terminal: %+v", m) + } + } +} + func TestScriptInline(t *testing.T) { eq(t, "inline", get(t, "script").Install(catalog.Method{Inline: "herdr plugin action invoke x"}, "", ubuntu), "herdr plugin action invoke x") } diff --git a/internal/backend/script.go b/internal/backend/script.go index 9dbec88..470f695 100644 --- a/internal/backend/script.go +++ b/internal/backend/script.go @@ -18,7 +18,7 @@ func (script) Name() string { return "script" } func (script) Install(m catalog.Method, _ string, _ platform.Platform) []runner.Cmd { if m.Inline != "" { - return []runner.Cmd{{Shell: m.Inline}} + return []runner.Cmd{{Shell: m.Inline, Stdin: m.Interactive}} } var b strings.Builder b.WriteString(`T=$(mktemp) && curl -fsSL ` + q(m.URL) + ` -o "$T"`) @@ -31,7 +31,7 @@ func (script) Install(m catalog.Method, _ string, _ platform.Platform) []runner. b.WriteString(" " + q(a)) } b.WriteString(`; rc=$?; rm -f "$T"; exit $rc`) - return []runner.Cmd{{Shell: b.String(), Display: "curl " + m.URL + " | bash"}} + return []runner.Cmd{{Shell: b.String(), Display: "curl " + m.URL + " | bash", Stdin: m.Interactive}} } func (s script) Update(m catalog.Method, p platform.Platform) []runner.Cmd { diff --git a/internal/catalog/types.go b/internal/catalog/types.go index 5f2822f..ff2bea0 100644 --- a/internal/catalog/types.go +++ b/internal/catalog/types.go @@ -83,6 +83,8 @@ type Method struct { Repo string `yaml:"repo"` Ref string `yaml:"ref"` Dest string `yaml:"dest"` + // Interactive cede o terminal ao comando (instaladores que perguntam via /dev/tty, como o do lerd). + Interactive bool `yaml:"interactive"` } type When struct {