From 46a42ae245ce7dad53c183f17d5862c2e09b2cab Mon Sep 17 00:00:00 2001 From: fcd <1352288+femnad@users.noreply.github.com> Date: Wed, 13 Dec 2023 03:41:30 +0000 Subject: [PATCH] fix: run shell cmd with sudo if user is not root --- base/task.go | 11 +++++++++-- main.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/base/task.go b/base/task.go index 99d626f..df6f7eb 100644 --- a/base/task.go +++ b/base/task.go @@ -41,12 +41,19 @@ func runCmd(step Step, cfg Config) error { func runShellCmd(step Step, cfg Config) error { pwd := ExpandSettings(cfg.Settings, step.Pwd) cmd := ExpandSettings(cfg.Settings, step.Cmd) - _, err := run.Cmd(cfg.Settings, marecmd.Input{ + + isRoot, err := common.IsUserRoot() + if err != nil { + return err + } + + sudo := !isRoot && step.Sudo + _, err = run.Cmd(cfg.Settings, marecmd.Input{ Command: cmd, Pwd: pwd, Shell: true, ShellCmd: step.Shell, - Sudo: step.Sudo, + Sudo: sudo, }) return err } diff --git a/main.go b/main.go index cf85e6f..5142b91 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( ) const ( - version = "0.21.1" + version = "0.21.2" ) type args struct {