50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using InnovEnergy.Lib.SysTools.Process;
|
|
using InnovEnergy.Lib.SysTools.Remote;
|
|
|
|
namespace InnovEnergy.Lib.SysTools.Edges;
|
|
|
|
public static class RemoteCommandToProcess
|
|
{
|
|
public static ProcessResult ExecuteBlocking(this RemoteCommand command, Dictionary<String, String> variables = null, Boolean logToConsole = false)
|
|
{
|
|
return command
|
|
.ToLocalCommand()
|
|
.ExecuteBlocking(variables, logToConsole);
|
|
}
|
|
|
|
public static AsyncProcess ToAsyncProcess(this RemoteCommand command, Dictionary<String, String> variables = null)
|
|
{
|
|
return command
|
|
.ToLocalCommand()
|
|
.ToAsyncProcess(variables);
|
|
}
|
|
|
|
public static SyncProcess ToSyncProcess(this RemoteCommand command, Dictionary<String, String> variables = null)
|
|
{
|
|
return command
|
|
.ToLocalCommand()
|
|
.ToSyncProcess(variables);
|
|
}
|
|
|
|
private static SysCommand ToLocalCommand(this RemoteCommand command)
|
|
{
|
|
var ssh = "ssh"
|
|
.Opt("o", "ConnectTimeout=5") // TODO
|
|
.Opt("o", "PasswordAuthentication=no")
|
|
.Opt("o", "StrictHostKeyChecking=no")
|
|
.Opt("o", "UserKnownHostsFile=/dev/null")
|
|
.Opt("o", "LogLevel=ERROR");
|
|
|
|
var host = command.Host;
|
|
|
|
if (host.KeyFile.HasValue)
|
|
ssh = ssh.Opt("i", host.KeyFile.Value);
|
|
|
|
if (host.Port != 22)
|
|
ssh = ssh.Opt("p", host.Port);
|
|
|
|
return ssh
|
|
.Arg($"{host.User}@{host.Address}")
|
|
.Arg(command.Path + command.Args);
|
|
}
|
|
} |