"encoding/hex"
"fmt"
"io"
+ "io/fs"
"os/exec"
"strconv"
"strings"
"ruderich.org/simon/safcm"
- "ruderich.org/simon/safcm/remote"
)
-func (c *Conn) DialSSH(user, host, sshConfig string) error {
+type SSHConfig struct {
+ Host string
+ User string // optional
+ SshConfig string // optional
+
+ RemoteHelpers fs.FS
+}
+
+func (c *Conn) DialSSH(cfg SSHConfig) error {
if c.events == nil {
return fmt.Errorf("cannot reuse Conn")
}
- remote := host
- if user != "" {
- remote = user + "@" + host
+ 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
}
c.debugf("DialSSH: connecting to %q", remote)
}
c.sshRemote = remote
- if sshConfig != "" {
- c.sshOpts = append(c.sshOpts, "-F", sshConfig)
+ if cfg.SshConfig != "" {
+ c.sshOpts = []string{"-F", cfg.SshConfig}
}
c.cmd = exec.Command("ssh",
append(append([]string{}, c.sshOpts...),
tmp="$(mktemp "$x.XXXXXX")"
# Report filename for upload
echo "$tmp"
-
# Wait for upload to complete
read unused
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)