Bump version to 1.0.18
This commit is contained in:
@@ -261,11 +261,17 @@ func (e *Engine) Run(ctx context.Context, jobID int64, pairID int64) error {
|
||||
|
||||
var result *RsyncResult
|
||||
if isRemoteToRemote(srcMachine, dstMachine) {
|
||||
destPrivKey, err := e.resolveSSHKey(dstMachine)
|
||||
if err != nil {
|
||||
slog.Warn("failed to resolve destination SSH key, using server key", "error", err)
|
||||
destPrivKey = filepath.Join(e.cfg.SSHDir(), "id_ed25519")
|
||||
}
|
||||
result, err = runner.RunRemote(jobCtx, cfg, RemoteMachine{
|
||||
Host: srcMachine.Host,
|
||||
Port: srcMachine.Port,
|
||||
SSHUser: srcMachine.SSHUser,
|
||||
PrivKey: privKey,
|
||||
Host: srcMachine.Host,
|
||||
Port: srcMachine.Port,
|
||||
SSHUser: srcMachine.SSHUser,
|
||||
PrivKey: privKey,
|
||||
DestPrivKey: destPrivKey,
|
||||
}, onLine)
|
||||
} else {
|
||||
result, err = runner.Run(jobCtx, cfg, onLine)
|
||||
|
||||
@@ -2,6 +2,7 @@ package syncengine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
@@ -180,26 +181,43 @@ func (r *RsyncRunner) buildRemoteArgs(pair *SyncPairConfig) []string {
|
||||
}
|
||||
|
||||
type RemoteMachine struct {
|
||||
Host string
|
||||
Port int
|
||||
SSHUser string
|
||||
PrivKey string
|
||||
Host string
|
||||
Port int
|
||||
SSHUser string
|
||||
PrivKey string
|
||||
DestPrivKey string
|
||||
}
|
||||
|
||||
func (r *RsyncRunner) RunRemote(ctx context.Context, pair *SyncPairConfig, remote RemoteMachine, onLine func(stream string, line string)) (*RsyncResult, error) {
|
||||
args := r.buildRemoteArgs(pair)
|
||||
args := r.buildArgs(pair)
|
||||
|
||||
var remoteCmd string
|
||||
if remote.DestPrivKey != "" {
|
||||
encodedKey := base64.StdEncoding.EncodeToString([]byte(remote.DestPrivKey))
|
||||
innerSSH := fmt.Sprintf(`ssh -i /tmp/syncserver-dest-key -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/dev/null`)
|
||||
rsyncPart := fmt.Sprintf("rsync %s -e %q %s %s",
|
||||
strings.Join(args, " "), innerSSH, pair.Source, pair.Dest)
|
||||
remoteCmd = fmt.Sprintf(
|
||||
`echo '%s' | base64 -d > /tmp/syncserver-dest-key && chmod 600 /tmp/syncserver-dest-key && %s; STATUS=$?; rm -f /tmp/syncserver-dest-key; exit $STATUS`,
|
||||
encodedKey, rsyncPart)
|
||||
} else {
|
||||
remoteCmd = "rsync " + strings.Join(args, " ")
|
||||
}
|
||||
|
||||
sshArgs := []string{
|
||||
"ssh",
|
||||
"-i", remote.PrivKey,
|
||||
"-o", "StrictHostKeyChecking=accept-new",
|
||||
"-o", "UserKnownHostsFile=" + strings.TrimRight(r.sshDir, "/") + "/known_hosts",
|
||||
"-tt",
|
||||
"-p", fmt.Sprintf("%d", remote.Port),
|
||||
fmt.Sprintf("%s@%s", remote.SSHUser, remote.Host),
|
||||
"rsync",
|
||||
}
|
||||
sshArgs = append(sshArgs, args...)
|
||||
if remote.DestPrivKey != "" {
|
||||
sshArgs = append(sshArgs, "bash", "-c", remoteCmd)
|
||||
} else {
|
||||
sshArgs = append(sshArgs, "rsync")
|
||||
sshArgs = append(sshArgs, args...)
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(ctx, "ssh", sshArgs...)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user