2024-01-11 12:26:31 +00:00
|
|
|
package exec
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
osexec "os/exec"
|
2024-02-01 14:10:04 +00:00
|
|
|
"strings"
|
2024-01-11 12:26:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type bashShell struct {
|
|
|
|
executable string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s bashShell) prepare(command string) (*execContext, error) {
|
|
|
|
filename, err := createTempScript(command, ".sh")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &execContext{
|
|
|
|
executable: s.executable,
|
|
|
|
args: []string{"-e", filename},
|
|
|
|
scriptFile: filename,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newBashShell() (shell, error) {
|
|
|
|
out, err := osexec.LookPath("bash")
|
|
|
|
if err != nil && !errors.Is(err, osexec.ErrNotFound) {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// `bash` is not found, return early.
|
|
|
|
if out == "" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2024-02-01 14:10:04 +00:00
|
|
|
// Skipping WSL bash if found one
|
|
|
|
if strings.Contains(out, `\Windows\System32\bash.exe`) || strings.Contains(out, `\Microsoft\WindowsApps\bash.exe`) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2024-01-11 12:26:31 +00:00
|
|
|
return &bashShell{executable: out}, nil
|
|
|
|
}
|
2024-02-01 14:10:04 +00:00
|
|
|
|
|
|
|
func (s bashShell) getType() ExecutableType {
|
|
|
|
return BashExecutable
|
|
|
|
}
|