ssh_theater: only edit conf if host doesn't resolve
diff --git a/dockerimg/ssh_theater.go b/dockerimg/ssh_theater.go
index 6afcfc9..1b060cc 100644
--- a/dockerimg/ssh_theater.go
+++ b/dockerimg/ssh_theater.go
@@ -10,6 +10,7 @@
"fmt"
"io/fs"
"os"
+ "os/exec"
"path/filepath"
"strings"
@@ -125,6 +126,15 @@
return cst, nil
}
+func checkSSHResolve(hostname string) error {
+ cmd := exec.Command("ssh", "-T", hostname)
+ out, err := cmd.CombinedOutput()
+ if strings.HasPrefix(string(out), "ssh: Could not resolve hostname") {
+ return err
+ }
+ return nil
+}
+
func CheckForIncludeWithFS(fs FileSystem, stdinReader bufio.Reader) error {
sketchSSHPathInclude := "Include " + filepath.Join(os.Getenv("HOME"), ".config", "sketch", "ssh_config")
defaultSSHPath := filepath.Join(os.Getenv("HOME"), ".ssh", "config")
@@ -563,7 +573,10 @@
return ssh.NewPublicKey(privateKey)
}
-// CheckForInclude checks if the user's SSH config includes the Sketch SSH config file
-func CheckForInclude() error {
- return CheckForIncludeWithFS(&RealFileSystem{}, *bufio.NewReader(os.Stdin))
+// CheckSSHReachability checks if the user's SSH config includes the Sketch SSH config file
+func CheckSSHReachability(cntrName string) error {
+ if err := checkSSHResolve(cntrName); err != nil {
+ return CheckForIncludeWithFS(&RealFileSystem{}, *bufio.NewReader(os.Stdin))
+ }
+ return nil
}