conn updates (more consistency) (#1657)

This commit is contained in:
Mike Sawka 2024-12-30 17:11:50 -08:00 committed by GitHub
parent 91a54442b7
commit b59e9e95bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 22 additions and 37 deletions

View File

@ -10,6 +10,7 @@ import (
"log"
"net"
"os"
"path/filepath"
"sync/atomic"
"time"
@ -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 {

View File

@ -11,8 +11,6 @@ import (
"github.com/wavetermdev/waveterm/pkg/wavebase"
)
var WshBinDir = ".waveterm/bin"
func init() {
rootCmd.AddCommand(rcfilesCmd)
}
@ -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())

View File

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

View File

@ -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"
)
@ -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)
@ -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 "~"
}

View File

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

View File

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

View File

@ -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) {
@ -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()
@ -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
}

View File

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