X-Git-Url: https://ruderich.org/simon/gitweb/?p=safcm%2Fsafcm.git;a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Fcommands.go;h=5a3c59c1d1d4c156396992733c1ed27131fe2364;hp=84a318d79668b8e43118d9981e5d7736db3f766c;hb=6015bd22c34e8287b43b462facd5ad491296c8c2;hpb=1934f1ab83306dff45310d5b45e2a99c97e28c35 diff --git a/cmd/safcm-remote/sync/commands.go b/cmd/safcm-remote/sync/commands.go index 84a318d..5a3c59c 100644 --- a/cmd/safcm-remote/sync/commands.go +++ b/cmd/safcm-remote/sync/commands.go @@ -31,7 +31,7 @@ func (s *Sync) syncCommands() error { // Run triggered commands first for _, path := range s.triggers { for _, x := range s.req.Files[path].TriggerCommands { - err := s.syncCommand(x, path) + err := s.syncCommand(x, "", path) if err != nil { return err } @@ -40,7 +40,7 @@ func (s *Sync) syncCommands() error { // Regular commands afterwards so they can react on triggers if // necessary for _, x := range s.req.Commands { - err := s.syncCommand(x.Cmd, "") + err := s.syncCommand(x.Cmd, x.OrigGroup, "") if err != nil { return err } @@ -48,7 +48,7 @@ func (s *Sync) syncCommands() error { return nil } -func (s *Sync) syncCommand(command string, trigger string) error { +func (s *Sync) syncCommand(command, group, trigger string) error { s.resp.CommandChanges = append(s.resp.CommandChanges, safcm.CommandChange{ Command: command, @@ -59,12 +59,20 @@ func (s *Sync) syncCommand(command string, trigger string) error { } change := &s.resp.CommandChanges[len(s.resp.CommandChanges)-1] + var info string + if trigger != "" { + info = fmt.Sprintf("%q", trigger) + } else if group != "" { + info = group + } + cmd := exec.Command("/bin/sh", "-c", command) cmd.Env = safcmEnviroment(s.req.Groups) // Cannot use cmd.CombinedOutputCmd() because we need another log // level (here the command is the actual change and not a side effect) // and different error handling. - s.log.Verbosef("commands: running %s", run.QuoteForDebug(cmd)) + s.log.Verbosef("commands: running %s (%s)", + run.QuoteForDebug(cmd), info) out, err := s.cmd.Runner.CombinedOutput(cmd) if len(out) > 0 { s.log.Debug2f("commands: command output:\n%s", out)