Skip to content

Commit

Permalink
fix: run shell cmd with sudo if user is not root
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed Dec 13, 2023
1 parent ce8966e commit 46a42ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions base/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
version = "0.21.1"
version = "0.21.2"
)

type args struct {
Expand Down

0 comments on commit 46a42ae

Please sign in to comment.