mirror of
				https://github.com/appleboy/drone-ssh.git
				synced 2025-10-29 00:51:15 +08:00 
			
		
		
		
	feat: added shell option
This commit is contained in:
		
							parent
							
								
									fc62fb377c
								
							
						
					
					
						commit
						f218df05e9
					
				
							
								
								
									
										8
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								main.go
									
									
									
									
									
								
							| @ -197,6 +197,12 @@ func main() { | |||||||
| 			Usage:   "debug mode", | 			Usage:   "debug mode", | ||||||
| 			EnvVars: []string{"PLUGIN_DEBUG", "DEBUG", "INPUT_DEBUG"}, | 			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
 | 	// Override a template
 | ||||||
| @ -242,6 +248,7 @@ func run(c *cli.Context) error { | |||||||
| 	if s := c.String("script.string"); s != "" { | 	if s := c.String("script.string"); s != "" { | ||||||
| 		scripts = append(scripts, s) | 		scripts = append(scripts, s) | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	plugin := Plugin{ | 	plugin := Plugin{ | ||||||
| 		Config: Config{ | 		Config: Config{ | ||||||
| 			Key:               c.String("ssh-key"), | 			Key:               c.String("ssh-key"), | ||||||
| @ -261,6 +268,7 @@ func run(c *cli.Context) error { | |||||||
| 			Sync:              c.Bool("sync"), | 			Sync:              c.Bool("sync"), | ||||||
| 			Ciphers:           c.StringSlice("ciphers"), | 			Ciphers:           c.StringSlice("ciphers"), | ||||||
| 			UseInsecureCipher: c.Bool("useInsecureCipher"), | 			UseInsecureCipher: c.Bool("useInsecureCipher"), | ||||||
|  | 			Shell:             c.String("shell"), | ||||||
| 			Proxy: easyssh.DefaultConfig{ | 			Proxy: easyssh.DefaultConfig{ | ||||||
| 				Key:               c.String("proxy.ssh-key"), | 				Key:               c.String("proxy.ssh-key"), | ||||||
| 				KeyPath:           c.String("proxy.key-path"), | 				KeyPath:           c.String("proxy.key-path"), | ||||||
|  | |||||||
| @ -41,6 +41,7 @@ type ( | |||||||
| 		Sync              bool | 		Sync              bool | ||||||
| 		Ciphers           []string | 		Ciphers           []string | ||||||
| 		UseInsecureCipher bool | 		UseInsecureCipher bool | ||||||
|  | 		Shell             string | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Plugin structure
 | 	// 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, strings.Join(p.Config.Script, "\n")) | ||||||
| 	p.log(host, "======END======") | 	p.log(host, "======END======") | ||||||
| 
 | 
 | ||||||
|  | 	shell := p.Config.Shell | ||||||
| 	env := []string{} | 	env := []string{} | ||||||
| 	for _, key := range p.Config.Envs { | 	for _, key := range p.Config.Envs { | ||||||
| 		key = strings.ToUpper(key) | 		key = strings.ToUpper(key) | ||||||
| 		if val, found := os.LookupEnv(key); found { | 		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)) | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 iam1337
						iam1337