]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - rpc/dial.go
Update copyright years
[safcm/safcm.git] / rpc / dial.go
index c0c6cd4088b2859d758aa0d06cf64405a2b70a16..e4d7f3842c90b67b6d4c69ad599c980573f45271 100644 (file)
@@ -1,6 +1,6 @@
 // Simple RPC-like protocol: establish new connection and upload helper
 
-// Copyright (C) 2021  Simon Ruderich
+// Copyright (C) 2021-2022  Simon Ruderich
 //
 // This program is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -24,18 +24,20 @@ import (
        "encoding/hex"
        "fmt"
        "io"
+       "io/fs"
        "os/exec"
        "strconv"
        "strings"
 
        "ruderich.org/simon/safcm"
-       "ruderich.org/simon/safcm/remote"
 )
 
 type SSHConfig struct {
        Host      string
        User      string // optional
        SshConfig string // optional
+
+       RemoteHelpers fs.FS
 }
 
 func (c *Conn) DialSSH(cfg SSHConfig) error {
@@ -43,6 +45,11 @@ func (c *Conn) DialSSH(cfg SSHConfig) error {
                return fmt.Errorf("cannot reuse Conn")
        }
 
+       if cfg.RemoteHelpers == nil {
+               return fmt.Errorf("SSHConfig.RemoteHelpers not set")
+       }
+       c.remoteHelpers = cfg.RemoteHelpers
+
        remote := cfg.Host
        if cfg.User != "" {
                remote = cfg.User + "@" + cfg.Host
@@ -83,7 +90,7 @@ func (c *Conn) DialSSH(cfg SSHConfig) error {
 
        err = c.dialSSH(stdin, stdout)
        if err != nil {
-               c.Kill()
+               c.Kill() //nolint:errcheck
                return err
        }
        c.conn = safcm.NewGobConn(stdout, stdin)
@@ -208,9 +215,9 @@ f
                return err
        }
 
-       // Get embedded helper binary
-       helper, err := remote.Helpers.ReadFile(
-               fmt.Sprintf("helpers/%s-%s", goos, goarch))
+       // Get remote helper binary
+       helper, err := fs.ReadFile(c.remoteHelpers,
+               fmt.Sprintf("%s-%s", goos, goarch))
        if err != nil {
                return fmt.Errorf("remote not built for GOOS/GOARCH %s/%s",
                        goos, goarch)