Skip to content

Commit 2546fe9

Browse files
committed
Fix ufw exec file presence check
1 parent e26e3e4 commit 2546fe9

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

cmd/tufw/main.go

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ func main() {
1616
log.Fatal("This program must be run as root! (sudo)")
1717
}
1818

19+
cmd = exec.Command("ufw", "status")
20+
_, err = cmd.Output()
21+
if err != nil {
22+
log.Fatal("Cannot find ufw. Is it installed?")
23+
}
24+
1925
tui := service.CreateApplication()
2026
tui.Init()
2127
data, err := tui.LoadTableData()

internal/core/service/tufw.go

+14-18
Original file line numberDiff line numberDiff line change
@@ -460,24 +460,20 @@ func (t *Tui) Build(data []string) {
460460
root := t.CreateLayout()
461461

462462
if len(data) <= 1 {
463-
if len(data) == 1 && strings.Contains(data[0], "inactive") {
464-
t.pages.HidePage("base")
465-
t.CreateModal("ufw is disabled.\nDo you want to enable it?",
466-
func() {
467-
utils.Shellout("ufw --force enable")
468-
},
469-
func() {
470-
t.app.Stop()
471-
},
472-
func() {
473-
t.pages.HidePage("modal")
474-
t.pages.ShowPage("base")
475-
t.app.SetFocus(t.menu)
476-
},
477-
)
478-
} else {
479-
panic("ufw is not installed.\nBe sure to install it before launching tufw")
480-
}
463+
t.pages.HidePage("base")
464+
t.CreateModal("ufw is disabled.\nDo you want to enable it?",
465+
func() {
466+
utils.Shellout("ufw --force enable")
467+
},
468+
func() {
469+
t.app.Stop()
470+
},
471+
func() {
472+
t.pages.HidePage("modal")
473+
t.pages.ShowPage("base")
474+
t.app.SetFocus(t.menu)
475+
},
476+
)
481477
}
482478

483479
t.CreateTable(data)

0 commit comments

Comments
 (0)