diff --git a/lib/http/websockets.go b/lib/http/websockets.go index 54178e5b..c759b193 100644 --- a/lib/http/websockets.go +++ b/lib/http/websockets.go @@ -9,6 +9,7 @@ import ( "os/exec" "path/filepath" "regexp" + "runtime" "strings" "time" @@ -26,6 +27,22 @@ var ( cmdNotAllowed = []byte("Command not allowed.") ) +var commandShell []string + +func init() { + if runtime.GOOS != "windows" { + path, err := exec.LookPath("bash") + + if err != nil { + path, err = exec.LookPath("sh") + } + + if err != nil { + commandShell = []string{path, "-c"} + } + } +} + // command handles the requests for VCS related commands: git, svn and mercurial func command(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // Upgrades the connection to a websocket and checks for fb.Errors. @@ -87,6 +104,10 @@ func command(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) path = filepath.Clean(path) buff := new(bytes.Buffer) + if len(commandShell) == 0 { + command = append(commandShell, command...) + } + // Sets up the command executation. cmd := exec.Command(command[0], command[1:]...) cmd.Dir = path