From e69abd105670207f520f17d73cf7d51f540a8dc2 Mon Sep 17 00:00:00 2001 From: Sylvia Crowe Date: Sun, 12 Jan 2025 15:59:26 -0800 Subject: [PATCH 1/2] feat: add rcfileinstall rpc command --- cmd/wsh/cmd/wshcmd-rcfiles.go | 10 ++-------- frontend/app/store/wshclientapi.ts | 5 +++++ pkg/wshrpc/wshclient/wshclient.go | 6 ++++++ pkg/wshrpc/wshremote/wshremote.go | 4 ++++ pkg/wshrpc/wshrpctypes.go | 2 ++ pkg/wshutil/wshutil.go | 8 ++++++++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/cmd/wsh/cmd/wshcmd-rcfiles.go b/cmd/wsh/cmd/wshcmd-rcfiles.go index 0889c01f78..2db2fb76bf 100644 --- a/cmd/wsh/cmd/wshcmd-rcfiles.go +++ b/cmd/wsh/cmd/wshcmd-rcfiles.go @@ -4,11 +4,8 @@ package cmd import ( - "path/filepath" - "github.com/spf13/cobra" - "github.com/wavetermdev/waveterm/pkg/util/shellutil" - "github.com/wavetermdev/waveterm/pkg/wavebase" + "github.com/wavetermdev/waveterm/pkg/wshutil" ) func init() { @@ -20,10 +17,7 @@ var rcfilesCmd = &cobra.Command{ Hidden: true, Short: "Generate the rc files needed for various shells", Run: func(cmd *cobra.Command, args []string) { - home := wavebase.GetHomeDir() - waveDir := filepath.Join(home, wavebase.RemoteWaveHomeDirName) - winBinDir := filepath.Join(waveDir, wavebase.RemoteWshBinDirName) - err := shellutil.InitRcFiles(waveDir, winBinDir) + err := wshutil.InstallRcFiles() if err != nil { WriteStderr(err.Error()) return diff --git a/frontend/app/store/wshclientapi.ts b/frontend/app/store/wshclientapi.ts index e1d88d60fc..d12b21dfbf 100644 --- a/frontend/app/store/wshclientapi.ts +++ b/frontend/app/store/wshclientapi.ts @@ -247,6 +247,11 @@ class RpcApiType { return client.wshRpcCall("remotegetinfo", null, opts); } + // command "remoteinstallrcfiles" [call] + RemoteInstallRcFilesCommand(client: WshClient, opts?: RpcOpts): Promise { + return client.wshRpcCall("remoteinstallrcfiles", null, opts); + } + // command "remotemkdir" [call] RemoteMkdirCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { return client.wshRpcCall("remotemkdir", data, opts); diff --git a/pkg/wshrpc/wshclient/wshclient.go b/pkg/wshrpc/wshclient/wshclient.go index b21eb3d9a0..02148642ca 100644 --- a/pkg/wshrpc/wshclient/wshclient.go +++ b/pkg/wshrpc/wshclient/wshclient.go @@ -301,6 +301,12 @@ func RemoteGetInfoCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) (wshrpc.Remot return resp, err } +// command "remoteinstallrcfiles", wshserver.RemoteInstallRcFilesCommand +func RemoteInstallRcFilesCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) error { + _, err := sendRpcRequestCallHelper[any](w, "remoteinstallrcfiles", nil, opts) + return err +} + // command "remotemkdir", wshserver.RemoteMkdirCommand func RemoteMkdirCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpts) error { _, err := sendRpcRequestCallHelper[any](w, "remotemkdir", data, opts) diff --git a/pkg/wshrpc/wshremote/wshremote.go b/pkg/wshrpc/wshremote/wshremote.go index 09e5c1944d..26d6f66776 100644 --- a/pkg/wshrpc/wshremote/wshremote.go +++ b/pkg/wshrpc/wshremote/wshremote.go @@ -392,3 +392,7 @@ func (*ServerImpl) RemoteFileDeleteCommand(ctx context.Context, path string) err func (*ServerImpl) RemoteGetInfoCommand(ctx context.Context) (wshrpc.RemoteInfo, error) { return wshutil.GetInfo(), nil } + +func (*ServerImpl) RemoteInstallRcFilesCommand(ctx context.Context) error { + return wshutil.InstallRcFiles() +} diff --git a/pkg/wshrpc/wshrpctypes.go b/pkg/wshrpc/wshrpctypes.go index ce71c92abb..b2f7d02dc3 100644 --- a/pkg/wshrpc/wshrpctypes.go +++ b/pkg/wshrpc/wshrpctypes.go @@ -74,6 +74,7 @@ const ( Command_SetVar = "setvar" Command_RemoteMkdir = "remotemkdir" Command_RemoteGetInfo = "remotegetinfo" + Command_RemoteInstallRcfiles = "remoteinstallrcfiles" Command_ConnStatus = "connstatus" Command_WslStatus = "wslstatus" @@ -181,6 +182,7 @@ type WshRpcInterface interface { RemoteMkdirCommand(ctx context.Context, path string) error RemoteStreamCpuDataCommand(ctx context.Context) chan RespOrErrorUnion[TimeSeriesData] RemoteGetInfoCommand(ctx context.Context) (RemoteInfo, error) + RemoteInstallRcFilesCommand(ctx context.Context) error // emain WebSelectorCommand(ctx context.Context, data CommandWebSelectorData) ([]string, error) diff --git a/pkg/wshutil/wshutil.go b/pkg/wshutil/wshutil.go index 44eedf9f87..77342fcd6d 100644 --- a/pkg/wshutil/wshutil.go +++ b/pkg/wshutil/wshutil.go @@ -12,6 +12,7 @@ import ( "net" "os" "os/signal" + "path/filepath" "runtime" "strings" "sync" @@ -561,3 +562,10 @@ func GetInfo() wshrpc.RemoteInfo { } } + +func InstallRcFiles() error { + home := wavebase.GetHomeDir() + waveDir := filepath.Join(home, wavebase.RemoteWaveHomeDirName) + winBinDir := filepath.Join(waveDir, wavebase.RemoteWshBinDirName) + return shellutil.InitRcFiles(waveDir, winBinDir) +} From d13413916799befd7cf7d53b3dd5f0b7111092f8 Mon Sep 17 00:00:00 2001 From: Sylvia Crowe Date: Sun, 12 Jan 2025 16:18:56 -0800 Subject: [PATCH 2/2] feat: use rpc for setting up remote rc files This replaces the call that used a separate session with an rpc command. --- pkg/remote/connutil.go | 13 ------------- pkg/shellexec/shellexec.go | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/pkg/remote/connutil.go b/pkg/remote/connutil.go index e5b7ff3688..323a7d1ab7 100644 --- a/pkg/remote/connutil.go +++ b/pkg/remote/connutil.go @@ -209,19 +209,6 @@ func CpWshToRemote(ctx context.Context, client *ssh.Client, clientOs string, cli return nil } -func InstallClientRcFiles(client *ssh.Client) error { - path := GetWshPath(client) - log.Printf("path to wsh searched is: %s", path) - session, err := client.NewSession() - if err != nil { - // this is a true error that should stop further progress - return err - } - - _, err = session.Output(path + " rcfiles") - return err -} - func IsPowershell(shellPath string) bool { // get the base path, and then check contains shellBase := filepath.Base(shellPath) diff --git a/pkg/shellexec/shellexec.go b/pkg/shellexec/shellexec.go index ced6443ee8..e5ffbce845 100644 --- a/pkg/shellexec/shellexec.go +++ b/pkg/shellexec/shellexec.go @@ -305,7 +305,7 @@ func StartRemoteShellProc(termSize waveobj.TermSize, cmdStr string, cmdOpts Comm var cmdCombined string log.Printf("using shell: %s", shellPath) - err = remote.InstallClientRcFiles(client) + err = wshclient.RemoteInstallRcFilesCommand(rpcClient, &wshrpc.RpcOpts{Route: connRoute, Timeout: 2000}) if err != nil { log.Printf("error installing rc files: %v", err) return nil, err