// Regular commands afterwards so they can react on triggers if
// necessary
for _, x := range s.req.Commands {
- err := s.syncCommand(x, "")
+ err := s.syncCommand(x.Cmd, "")
if err != nil {
return err
}
"group2",
"host.example.org",
},
- Commands: []string{
- "echo; env | grep SAFCM_",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo; env | grep SAFCM_",
+ },
},
},
nil,
"group2",
"host.example.org",
},
- Commands: []string{
- "echo; env | grep SAFCM_",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo; env | grep SAFCM_",
+ },
},
},
nil,
"group2",
"host.example.org",
},
- Commands: []string{
- "echo hi; false",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo hi; false",
+ },
},
},
nil,
"group2",
"host.example.org",
},
- Commands: []string{
- "echo hi; false",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo hi; false",
+ },
},
},
nil,
"group2",
"host.example.org",
},
- Commands: []string{
- "echo first",
- "echo second",
- "false",
- "echo third",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo first",
+ }, {
+ Cmd: "echo second",
+ }, {
+ Cmd: "false",
+ }, {
+ Cmd: "echo third",
+ },
},
},
nil,
},
},
},
- Commands: []string{
- "echo; env | grep SAFCM_",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo; env | grep SAFCM_",
+ },
},
},
[]string{
},
},
},
- Commands: []string{
- "echo; env | grep SAFCM_",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo; env | grep SAFCM_",
+ },
},
},
[]string{
"path/filepath"
"gopkg.in/yaml.v2"
+
+ "ruderich.org/simon/safcm"
)
-func LoadCommands(group string) ([]string, error) {
+func LoadCommands(group string) ([]*safcm.Command, error) {
path := filepath.Join(group, "commands.yaml")
- var res []string
+ var cmds []string
x, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
}
return nil, err
}
- err = yaml.UnmarshalStrict(x, &res)
+ err = yaml.UnmarshalStrict(x, &cmds)
if err != nil {
return nil, fmt.Errorf("%s: failed to load: %v", path, err)
}
+
+ var res []*safcm.Command
+ for _, x := range cmds {
+ res = append(res, &safcm.Command{
+ Cmd: x,
+ })
+ }
return res, nil
}
allFiles := make(map[string]*safcm.File)
allPackagesMap := make(map[string]bool) // map to deduplicate
allServicesMap := make(map[string]bool) // map to deduplicate
- var allCommands []string
+ var allCommands []*safcm.Command
for _, group := range groups {
// Skip non-existent group directories
Services: []string{
"unbound",
},
- Commands: []string{
- "echo command one",
- "echo -n command two",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo command one",
+ },
+ {
+ Cmd: "echo -n command two",
+ },
},
},
[]string{
Services: []string{
"unbound",
},
- Commands: []string{
- "echo command one",
- "echo -n command two",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo command one",
+ },
+ {
+ Cmd: "echo -n command two",
+ },
},
},
nil,
Files map[string]*File
Packages []string
Services []string
- Commands []string
+ Commands []*Command
}
type MsgSyncResp struct {
FileChanges []FileChange
TriggerCommands []string
}
+type Command struct {
+ Cmd string
+}
+
type FileChange struct {
Path string
Created bool