From 5cbf2673f41e84dfda87c0946d7699275ef9f445 Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:42:43 -0700 Subject: [PATCH] windows ssh fixes (#250) a couple small bug fixes - wsh not being executable in windows (this doesn't add it to the path yet) - windows using the wrong slash for the path to wsh on the remote --- pkg/remote/connutil.go | 17 ++++++++++++++++- pkg/util/shellutil/shellutil.go | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/remote/connutil.go b/pkg/remote/connutil.go index 263e3128..28d9174d 100644 --- a/pkg/remote/connutil.go +++ b/pkg/remote/connutil.go @@ -72,7 +72,7 @@ func GetWshVersion(client *ssh.Client) (string, error) { } func GetWshPath(client *ssh.Client) string { - defaultPath := filepath.Join("~", ".waveterm", "bin", "wsh") + defaultPath := "~/.waveterm/bin/wsh" session, err := client.NewSession() if err != nil { @@ -96,6 +96,18 @@ func GetWshPath(client *ssh.Client) string { return strings.TrimSpace(string(out)) } + // check cmd on windows since it requires an absolute path with backslashes + session, err = client.NewSession() + if err != nil { + log.Printf("unable to detect client's wsh path. using default. error: %v", err) + return defaultPath + } + + out, cmdErr := session.Output("(dir 2>&1 *``|echo %userprofile%\\.waveterm%\\.waveterm\\bin\\wsh.exe);&<# rem #>echo none") //todo + if cmdErr == nil && strings.TrimSpace(string(out)) != "none" { + return strings.TrimSpace(string(out)) + } + // no custom install, use default path return defaultPath } @@ -279,6 +291,9 @@ func CpHostToRemote(client *ssh.Client, sourcePath string, destPath string) erro func InstallClientRcFiles(client *ssh.Client) error { path := GetWshPath(client) + log.Printf("path to wsh searched is: %s", path) + log.Printf("in bytes is: %v", []byte(path)) + log.Printf("in bytes expected would be: %v", []byte("~/.waveterm/bin/wsh")) session, err := client.NewSession() if err != nil { diff --git a/pkg/util/shellutil/shellutil.go b/pkg/util/shellutil/shellutil.go index 858b8852..bf5a48f1 100644 --- a/pkg/util/shellutil/shellutil.go +++ b/pkg/util/shellutil/shellutil.go @@ -268,6 +268,9 @@ func initCustomShellStartupFilesInternal() error { return nil } wshDstPath := filepath.Join(binDir, "wsh") + if runtime.GOOS == "windows" { + wshDstPath = wshDstPath + ".exe" + } err = utilfn.AtomicRenameCopy(wshDstPath, wshFullPath, 0755) if err != nil { return fmt.Errorf("error copying wsh binary to bin: %v", err)