Skip to content

Commit

Permalink
Revert "fix: always execute cmd in subshell"
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 authored Feb 27, 2023
1 parent 16c49a9 commit ec22291
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions cli/packages/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,11 @@ func init() {

// Will execute a single command and pass in the given secrets into the process
func executeSingleCommandWithEnvs(args []string, secretsCount int, env []string) error {
shell := subShellCmd()
command := args[0]
argsForCommand := args[1:]
color.Green("Injecting %v Infisical secrets into your application process", secretsCount)

args = append(args[:1], args[0:]...) // shift args to the right
args[0] = shell[1]

cmd := exec.Command(shell[0], args...)

cmd := exec.Command(command, argsForCommand...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand All @@ -203,7 +200,15 @@ func executeSingleCommandWithEnvs(args []string, secretsCount int, env []string)
}

func executeMultipleCommandWithEnvs(fullCommand string, secretsCount int, env []string) error {
shell := subShellCmd()
shell := [2]string{"sh", "-c"}
if runtime.GOOS == "windows" {
shell = [2]string{"cmd", "/C"}
} else {
currentShell := os.Getenv("SHELL")
if currentShell != "" {
shell[0] = currentShell
}
}

cmd := exec.Command(shell[0], shell[1], fullCommand)
cmd.Stdin = os.Stdin
Expand All @@ -217,23 +222,6 @@ func executeMultipleCommandWithEnvs(fullCommand string, secretsCount int, env []
return execCmd(cmd)
}

func subShellCmd() [2]string {
// default to sh -c
shell := [...]string{"sh", "-c"}

currentShell := os.Getenv("SHELL")
if currentShell != "" {
shell[0] = currentShell
} else if runtime.GOOS == "windows" {
// if the SHELL env var is not set and we're on Windows, use cmd.exe
// The SHELL var should always be checked first, in case the user executes
// infisical from something like Git Bash.
return [...]string{"cmd", "/C"}
}

return shell
}

// Credit: inspired by AWS Valut
func execCmd(cmd *exec.Cmd) error {
sigChannel := make(chan os.Signal, 1)
Expand Down

0 comments on commit ec22291

Please sign in to comment.