(ctx context.Context, logCtx context.Context, termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType, conn *conncontroller.SSHConn, optBlockId string)
| 470 | } |
| 471 | |
| 472 | func StartRemoteShellJob(ctx context.Context, logCtx context.Context, termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType, conn *conncontroller.SSHConn, optBlockId string) (string, error) { |
| 473 | connRoute := wshutil.MakeConnectionRouteId(conn.GetName()) |
| 474 | rpcClient := wshclient.GetBareRpcClient() |
| 475 | remoteInfo, err := wshclient.RemoteGetInfoCommand(rpcClient, &wshrpc.RpcOpts{Route: connRoute, Timeout: 2000}) |
| 476 | if err != nil { |
| 477 | return "", fmt.Errorf("unable to obtain client info: %w", err) |
| 478 | } |
| 479 | if remoteInfo.HomeDir == "" { |
| 480 | return "", fmt.Errorf("unable to obtain home directory from remote machine") |
| 481 | } |
| 482 | log.Printf("client info collected: %+#v", remoteInfo) |
| 483 | var shellPath string |
| 484 | if cmdOpts.ShellPath != "" { |
| 485 | conn.Infof(logCtx, "using shell path from command opts: %s\n", cmdOpts.ShellPath) |
| 486 | shellPath = cmdOpts.ShellPath |
| 487 | } |
| 488 | configShellPath := conn.GetConfigShellPath() |
| 489 | if shellPath == "" && configShellPath != "" { |
| 490 | conn.Infof(logCtx, "using shell path from config (conn:shellpath): %s\n", configShellPath) |
| 491 | shellPath = configShellPath |
| 492 | } |
| 493 | if shellPath == "" && remoteInfo.Shell != "" { |
| 494 | conn.Infof(logCtx, "using shell path detected on remote machine: %s\n", remoteInfo.Shell) |
| 495 | shellPath = remoteInfo.Shell |
| 496 | } |
| 497 | if shellPath == "" { |
| 498 | conn.Infof(logCtx, "no shell path detected, using default (/bin/bash)\n") |
| 499 | shellPath = "/bin/bash" |
| 500 | } |
| 501 | var shellOpts []string |
| 502 | log.Printf("detected shell %q for conn %q\n", shellPath, conn.GetName()) |
| 503 | shellOpts = append(shellOpts, cmdOpts.ShellOpts...) |
| 504 | shellType := shellutil.GetShellTypeFromShellPath(shellPath) |
| 505 | conn.Infof(logCtx, "detected shell type: %s\n", shellType) |
| 506 | conn.Debugf(logCtx, "cmdStr: %q\n", cmdStr) |
| 507 | |
| 508 | if cmdStr == "" { |
| 509 | if shellType == shellutil.ShellType_bash { |
| 510 | bashPath := fmt.Sprintf("%s/.waveterm/%s/.bashrc", remoteInfo.HomeDir, shellutil.BashIntegrationDir) |
| 511 | shellOpts = append(shellOpts, "--rcfile", bashPath) |
| 512 | } else if shellType == shellutil.ShellType_fish { |
| 513 | if cmdOpts.Login { |
| 514 | shellOpts = append(shellOpts, "-l") |
| 515 | } |
| 516 | waveFishPath := fmt.Sprintf("%s/.waveterm/%s/wave.fish", remoteInfo.HomeDir, shellutil.FishIntegrationDir) |
| 517 | carg := fmt.Sprintf(`source %s`, waveFishPath) |
| 518 | shellOpts = append(shellOpts, "-C", carg) |
| 519 | } else if shellType == shellutil.ShellType_pwsh { |
| 520 | pwshPath := fmt.Sprintf("%s/.waveterm/%s/wavepwsh.ps1", remoteInfo.HomeDir, shellutil.PwshIntegrationDir) |
| 521 | shellOpts = append(shellOpts, "-ExecutionPolicy", "Bypass", "-NoExit", "-File", pwshPath) |
| 522 | } else { |
| 523 | if cmdOpts.Login { |
| 524 | shellOpts = append(shellOpts, "-l") |
| 525 | } |
| 526 | if cmdOpts.Interactive { |
| 527 | shellOpts = append(shellOpts, "-i") |
| 528 | } |
| 529 | } |
no test coverage detected