Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions catalog/items/lerd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions internal/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/backend/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`)
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions internal/catalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading