From 4b0841f6d1be8d128fc6a8a34079b4e55ab74e47 Mon Sep 17 00:00:00 2001 From: Sig Lange Date: Wed, 30 Nov 2022 08:05:47 -0800 Subject: [PATCH 1/2] add shell --- script.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/script.go b/script.go index 0ea0c4f..eaf1410 100644 --- a/script.go +++ b/script.go @@ -10,13 +10,15 @@ import ( ) var ( - DefaultScriptType = "post" + DefaultScriptType = "post" + DefaultScriptShell = "/bin/bash" ) type Script struct { Id string Command string Disabled bool + Shell string // post or pre; default is 'post' Type string @@ -34,6 +36,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,7 +48,7 @@ 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:]...) From 43dcdeb3f26f0fb44af473a3aea2578df5b826d3 Mon Sep 17 00:00:00 2001 From: Sig Lange Date: Wed, 30 Nov 2022 08:09:54 -0800 Subject: [PATCH 2/2] add options --- README.md | 6 ++++++ script.go | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) 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 eaf1410..58ac1c9 100644 --- a/script.go +++ b/script.go @@ -18,7 +18,12 @@ type Script struct { Id string Command string Disabled bool - Shell string + + // do not print commands stdout and stderr to logs + Quiet bool + + // default shell + Shell string // post or pre; default is 'post' Type string @@ -53,8 +58,11 @@ func (me *Script) Run() (*ScriptResult, error) { } 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()