예제 #1
0
// WriteCommands returns shell commands to write the agent
// configuration.  It returns an error if the configuration does not
// have all the right elements.
func (c *Conf) WriteCommands() ([]string, error) {
	if err := c.Check(); err != nil {
		return nil, err
	}
	data, err := goyaml.Marshal(c)
	if err != nil {
		return nil, err
	}
	var cmds []string
	addCmd := func(f string, a ...interface{}) {
		cmds = append(cmds, fmt.Sprintf(f, a...))
	}
	f := trivial.ShQuote(c.confFile())
	addCmd("mkdir -p %s", trivial.ShQuote(c.Dir()))
	addCmd("echo %s > %s", trivial.ShQuote(string(data)), f)
	addCmd("chmod %o %s", 0600, f)
	return cmds, nil
}
예제 #2
0
func shquote(p string) string {
	return trivial.ShQuote(p)
}