+/cmd/safcm/remote/
/cmd/safcm/testdata/ssh/project/no-changes.example.org/
/cmd/safcm/testdata/ssh/ssh/authorized_keys
/cmd/safcm/testdata/ssh/ssh/id_ed25519
/cmd/safcm/testdata/ssh/ssh/known_hosts
/cmd/safcm/testdata/ssh/sshd/ssh_host_key
/cmd/safcm/testdata/ssh/sshd/ssh_host_key.pub
-/remote/helpers/
/safcm
/tags
shellcheck cmd/safcm/testdata/ssh/prepare.sh
clean:
- rm -rf remote/helpers/
+ rm -rf cmd/safcm/remote/
rm -f safcm
rm -f cmd/safcm/testdata/ssh/ssh/authorized_keys
rm -f cmd/safcm/testdata/ssh/ssh/id_ed25519
}
-dest=../../remote/helpers
+dest=../safcm/remote
mkdir -p "$dest"
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-package remote
+package main
import (
"embed"
)
-// Helpers contains remote helper binaries for different operating systems and
-// architectures.
-//go:embed helpers/*
-var Helpers embed.FS
+// RemoteHelpers contains remote helper binaries for different operating
+// systems and architectures.
+//go:embed remote/*
+var RemoteHelpers embed.FS
import (
"flag"
"fmt"
+ "io/fs"
"log"
"os"
"os/signal"
wg.Done()
}()
+ helpers, err := fs.Sub(RemoteHelpers, "remote")
+ if err != nil {
+ conn.Kill()
+ return err
+ }
+
// Connect to remote host
user := s.host.SshUser
if user == "" {
user = s.config.SshUser
}
- err := conn.DialSSH(rpc.SSHConfig{
- Host: s.host.Name,
- User: user,
- SshConfig: s.config.SshConfig,
+ err = conn.DialSSH(rpc.SSHConfig{
+ Host: s.host.Name,
+ User: user,
+ SshConfig: s.config.SshConfig,
+ RemoteHelpers: helpers,
})
if err != nil {
conn.Kill()
import (
"bufio"
"fmt"
+ "io/fs"
"os/exec"
"strings"
"sync"
sshRemote string
sshOpts []string
+ remoteHelpers fs.FS
+
cmd *exec.Cmd
conn *safcm.GobConn
}
"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 {
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
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)