Skip to content

Commit

Permalink
conn updates (more consistency) (#1657)
Browse files Browse the repository at this point in the history
  • Loading branch information
sawka authored Dec 31, 2024
1 parent 91a5444 commit b59e9e9
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 37 deletions.
8 changes: 7 additions & 1 deletion cmd/wsh/cmd/wshcmd-connserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"net"
"os"
"path/filepath"
"sync/atomic"
"time"

Expand Down Expand Up @@ -38,8 +39,13 @@ func init() {
rootCmd.AddCommand(serverCmd)
}

func getRemoteDomainSocketName() string {
homeDir := wavebase.GetHomeDir()
return filepath.Join(homeDir, wavebase.RemoteWaveHomeDirName, wavebase.RemoteDomainSocketBaseName)
}

func MakeRemoteUnixListener() (net.Listener, error) {
serverAddr := wavebase.GetRemoteDomainSocketName()
serverAddr := getRemoteDomainSocketName()
os.Remove(serverAddr) // ignore error
rtn, err := net.Listen("unix", serverAddr)
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions cmd/wsh/cmd/wshcmd-rcfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/wavetermdev/waveterm/pkg/wavebase"
)

var WshBinDir = ".waveterm/bin"

func init() {
rootCmd.AddCommand(rcfilesCmd)
}
Expand All @@ -23,8 +21,8 @@ var rcfilesCmd = &cobra.Command{
Short: "Generate the rc files needed for various shells",
Run: func(cmd *cobra.Command, args []string) {
home := wavebase.GetHomeDir()
waveDir := filepath.Join(home, ".waveterm")
winBinDir := filepath.Join(waveDir, "bin")
waveDir := filepath.Join(home, wavebase.RemoteWaveHomeDirName)
winBinDir := filepath.Join(waveDir, wavebase.RemoteWshBinDirName)
err := shellutil.InitRcFiles(waveDir, winBinDir)
if err != nil {
WriteStderr(err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/remote/conncontroller/conncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (conn *SSHConn) CheckAndInstallWsh(ctx context.Context, clientDisplayName s
}
// attempt to install extension
wshLocalPath := shellutil.GetWshBinaryPath(wavebase.WaveVersion, clientOs, clientArch)
err = remote.CpHostToRemote(client, wshLocalPath, "~/.waveterm/bin/wsh")
err = remote.CpHostToRemote(client, wshLocalPath, wavebase.RemoteFullWshBinPath)
if err != nil {
return err
}
Expand Down
15 changes: 2 additions & 13 deletions pkg/remote/connutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/wavetermdev/waveterm/pkg/panichandler"
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
"github.com/wavetermdev/waveterm/pkg/wavebase"
"golang.org/x/crypto/ssh"
)

Expand Down Expand Up @@ -69,8 +70,7 @@ func GetWshVersion(client *ssh.Client) (string, error) {
}

func GetWshPath(client *ssh.Client) string {
defaultPath := "~/.waveterm/bin/wsh"

defaultPath := wavebase.RemoteFullWshBinPath
session, err := client.NewSession()
if err != nil {
log.Printf("unable to detect client's wsh path. using default. error: %v", err)
Expand Down Expand Up @@ -300,21 +300,10 @@ func GetHomeDir(client *ssh.Client) string {
if err != nil {
return "~"
}

out, err := session.Output(`echo "$HOME"`)
if err == nil {
return strings.TrimSpace(string(out))
}

session, err = client.NewSession()
if err != nil {
return "~"
}
out, err = session.Output(`echo %userprofile%`)
if err == nil {
return strings.TrimSpace(string(out))
}

return "~"
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/shellexec/shellexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func StartWslShellProc(ctx context.Context, termSize waveobj.TermSize, cmdStr st
} else if wsl.IsPowershell(shellPath) {
// powershell is weird about quoted path executables and requires an ampersand first
shellPath = "& " + shellPath
subShellOpts = append(subShellOpts, "-ExecutionPolicy", "Bypass", "-NoExit", "-File", homeDir+fmt.Sprintf("/.waveterm/%s/wavepwsh.ps1", shellutil.PwshIntegrationDir))
subShellOpts = append(subShellOpts, "-ExecutionPolicy", "Bypass", "-NoExit", "-File", fmt.Sprintf("%s/.waveterm/%s/wavepwsh.ps1", homeDir, shellutil.PwshIntegrationDir))
} else {
if cmdOpts.Login {
subShellOpts = append(subShellOpts, "-l")
Expand Down Expand Up @@ -315,7 +315,7 @@ func StartRemoteShellProc(termSize waveobj.TermSize, cmdStr string, cmdOpts Comm
} else if remote.IsPowershell(shellPath) {
// powershell is weird about quoted path executables and requires an ampersand first
shellPath = "& " + shellPath
shellOpts = append(shellOpts, "-ExecutionPolicy", "Bypass", "-NoExit", "-File", homeDir+fmt.Sprintf("/.waveterm/%s/wavepwsh.ps1", shellutil.PwshIntegrationDir))
shellOpts = append(shellOpts, "-ExecutionPolicy", "Bypass", "-NoExit", "-File", fmt.Sprintf("%s/.waveterm/%s/wavepwsh.ps1", homeDir, shellutil.PwshIntegrationDir))
} else {
if cmdOpts.Login {
shellOpts = append(shellOpts, "-l")
Expand Down
10 changes: 4 additions & 6 deletions pkg/wavebase/wavebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ const RemoteDomainSocketBaseName = "wave-remote.sock"
const WaveDBDir = "db"
const JwtSecret = "waveterm" // TODO generate and store this
const ConfigDir = "config"

var RemoteWaveHome = ExpandHomeDirSafe("~/.waveterm")
const RemoteWaveHomeDirName = ".waveterm"
const RemoteWshBinDirName = "bin"
const RemoteFullWshBinPath = "~/.waveterm/bin/wsh"
const RemoteFullDomainSocketPath = "~/.waveterm/wave-remote.sock"

const AppPathBinDir = "bin"

Expand Down Expand Up @@ -137,10 +139,6 @@ func GetDomainSocketName() string {
return filepath.Join(GetWaveDataDir(), DomainSocketBaseName)
}

func GetRemoteDomainSocketName() string {
return filepath.Join(RemoteWaveHome, RemoteDomainSocketBaseName)
}

func EnsureWaveDataDir() error {
return CacheEnsureDir(GetWaveDataDir(), "wavehome", 0700, "wave home directory")
}
Expand Down
10 changes: 2 additions & 8 deletions pkg/wsl/wsl-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/wavetermdev/waveterm/pkg/panichandler"
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
"github.com/wavetermdev/waveterm/pkg/wavebase"
)

func DetectShell(ctx context.Context, client *Distro) (string, error) {
Expand Down Expand Up @@ -49,7 +50,7 @@ func GetWshVersion(ctx context.Context, client *Distro) (string, error) {
}

func GetWshPath(ctx context.Context, client *Distro) string {
defaultPath := "~/.waveterm/bin/wsh"
defaultPath := wavebase.RemoteFullWshBinPath

cmd := client.WslCommand(ctx, "which wsh")
out, whichErr := cmd.Output()
Expand All @@ -63,13 +64,6 @@ func GetWshPath(ctx context.Context, client *Distro) string {
return strings.TrimSpace(string(out))
}

// check cmd on windows since it requires an absolute path with backslashes
cmd = client.WslCommand(ctx, "(dir 2>&1 *``|echo %userprofile%\\.waveterm%\\.waveterm\\bin\\wsh.exe);&<# rem #>echo none")
out, cmdErr := cmd.Output()
if cmdErr == nil && strings.TrimSpace(string(out)) != "none" {
return strings.TrimSpace(string(out))
}

// no custom install, use default path
return defaultPath
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/wsl/wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (conn *WslConn) OpenDomainSocketListener() error {
return fmt.Errorf("cannot open domain socket for %q when status is %q", conn.GetName(), conn.GetStatus())
}
conn.WithLock(func() {
conn.SockName = "~/.waveterm/wave-remote.sock"
conn.SockName = wavebase.RemoteFullDomainSocketPath
})
return nil
}
Expand Down Expand Up @@ -326,7 +326,7 @@ func (conn *WslConn) CheckAndInstallWsh(ctx context.Context, clientDisplayName s
}
// attempt to install extension
wshLocalPath := shellutil.GetWshBinaryPath(wavebase.WaveVersion, clientOs, clientArch)
err = CpHostToRemote(ctx, client, wshLocalPath, "~/.waveterm/bin/wsh")
err = CpHostToRemote(ctx, client, wshLocalPath, wavebase.RemoteFullWshBinPath)
if err != nil {
return err
}
Expand Down

0 comments on commit b59e9e9

Please sign in to comment.