diff --git a/internal/flypg/state/store.go b/internal/flypg/state/store.go index 8a368f89..77759d6a 100644 --- a/internal/flypg/state/store.go +++ b/internal/flypg/state/store.go @@ -85,7 +85,7 @@ func clientConfig() (*api.Config, error) { token, set := u.User.Password() if !set { - return nil, fmt.Errorf("token not set") + return nil, fmt.Errorf("consul token not set") } u.User = nil diff --git a/internal/utils/shell.go b/internal/utils/shell.go index cd550ff9..ca79c1e9 100644 --- a/internal/utils/shell.go +++ b/internal/utils/shell.go @@ -1,7 +1,10 @@ package utils import ( + "bytes" "fmt" + "io" + "log" "os" "os/exec" "os/user" @@ -15,11 +18,24 @@ func RunCommand(cmdStr, usr string) ([]byte, error) { return nil, err } + log.Printf("> Running command as %s: %s\n", usr, cmdStr) + cmd := exec.Command("sh", "-c", cmdStr) cmd.SysProcAttr = &syscall.SysProcAttr{} cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)} - return cmd.Output() + var stdoutBuf, stderrBuf bytes.Buffer + cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf) + cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf) + + err = cmd.Run() + if err != nil { + if ee, ok := err.(*exec.ExitError); ok { + ee.Stderr = stderrBuf.Bytes() + } + } + + return stdoutBuf.Bytes(), err } func SetFileOwnership(pathToFile, owner string) error {