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
This commit is contained in:
Sylvie Crowe 2024-08-20 12:42:43 -07:00 committed by GitHub
parent 2f020099ec
commit 5cbf2673f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -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 {

View File

@ -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)