diff --git a/README.md b/README.md index 0b6c1fe..f7fbc15 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,12 @@ Example command: | chmod 0400 ~/.ssh/config chmod 0400 ~/.ssh/config.d/* + - id: example3 + shell: /bin/bash + quiet: true + command: | + set -x + date > /tmp/test.txt For the above examples, example1 is a 'pre' script which runs before symlinks and example2 is a 'post' script which runs after symlinks. diff --git a/script.go b/script.go index 0ea0c4f..58ac1c9 100644 --- a/script.go +++ b/script.go @@ -10,7 +10,8 @@ import ( ) var ( - DefaultScriptType = "post" + DefaultScriptType = "post" + DefaultScriptShell = "/bin/bash" ) type Script struct { @@ -18,6 +19,12 @@ type Script struct { Command string Disabled bool + // do not print commands stdout and stderr to logs + Quiet bool + + // default shell + Shell string + // post or pre; default is 'post' Type string } @@ -34,6 +41,9 @@ func (me *Script) SetDefaults() { me.Type = DefaultScriptType } me.Type = strings.ToLower(me.Type) + if me.Shell == "" { + me.Shell = DefaultScriptShell + } } func (me *Script) Run() (*ScriptResult, error) { @@ -43,13 +53,16 @@ func (me *Script) Run() (*ScriptResult, error) { stdin := bytes.NewBufferString(me.Command) cmdline := []string{ - "/bin/bash", + me.Shell, "-", } c := exec.CommandContext(ctx, cmdline[0], cmdline[1:]...) c.Stdin = stdin - c.Stdout = os.Stdout - c.Stderr = os.Stdout + + if me.Quiet == false { + c.Stdout = os.Stdout + c.Stderr = os.Stdout + } c.Env = os.Environ() err := c.Run()