diff --git a/main.go b/main.go index 52df847..2f1b360 100644 --- a/main.go +++ b/main.go @@ -197,6 +197,12 @@ func main() { Usage: "debug mode", EnvVars: []string{"PLUGIN_DEBUG", "DEBUG", "INPUT_DEBUG"}, }, + &cli.StringFlag{ + Name: "shell", + Usage: "shell on host", + EnvVars: []string{"PLUGIN_HOST_SHELL"}, + Value: "bash", + }, } // Override a template @@ -242,6 +248,7 @@ func run(c *cli.Context) error { if s := c.String("script.string"); s != "" { scripts = append(scripts, s) } + plugin := Plugin{ Config: Config{ Key: c.String("ssh-key"), @@ -261,6 +268,7 @@ func run(c *cli.Context) error { Sync: c.Bool("sync"), Ciphers: c.StringSlice("ciphers"), UseInsecureCipher: c.Bool("useInsecureCipher"), + Shell: c.String("shell"), Proxy: easyssh.DefaultConfig{ Key: c.String("proxy.ssh-key"), KeyPath: c.String("proxy.key-path"), diff --git a/plugin.go b/plugin.go index 6eb7ed6..3cd5c47 100644 --- a/plugin.go +++ b/plugin.go @@ -41,6 +41,7 @@ type ( Sync bool Ciphers []string UseInsecureCipher bool + Shell string } // Plugin structure @@ -99,11 +100,16 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) { p.log(host, strings.Join(p.Config.Script, "\n")) p.log(host, "======END======") + shell := p.Config.Shell env := []string{} for _, key := range p.Config.Envs { key = strings.ToUpper(key) if val, found := os.LookupEnv(key); found { - env = append(env, "export "+key+"="+escapeArg(val)) + if shell == "bash" { + env = append(env, "export "+key+"="+escapeArg(val)) + } else if shell == "powershell" { + env = append(env, "$env:"+key+" = "+escapeArg(val)) + } } }