parent
49d36e287d
commit
db4ffc0fa9
18
shell.go
18
shell.go
|
@ -272,3 +272,21 @@ func Exec(cmdline string) {
|
||||||
log.Println("shell.Exec() err =", err)
|
log.Println("shell.Exec() err =", err)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return true if the filename exists
|
||||||
|
func Exists(filename string) bool {
|
||||||
|
_, err := os.Stat(filename)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// return true if the filename exists
|
||||||
|
func Dir(dirname string) bool {
|
||||||
|
info, err := os.Stat(dirname)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return info.IsDir()
|
||||||
|
}
|
||||||
|
|
13
ssh.go
13
ssh.go
|
@ -9,6 +9,7 @@ import "io/ioutil"
|
||||||
import "path/filepath"
|
import "path/filepath"
|
||||||
import "strings"
|
import "strings"
|
||||||
import "time"
|
import "time"
|
||||||
|
import "runtime"
|
||||||
|
|
||||||
import "golang.org/x/crypto/ssh"
|
import "golang.org/x/crypto/ssh"
|
||||||
import "github.com/tmc/scp"
|
import "github.com/tmc/scp"
|
||||||
|
@ -24,7 +25,17 @@ func SSH(hostname string, port int, username string, pass string) *ssh.Session {
|
||||||
|
|
||||||
user, _ := user.Current()
|
user, _ := user.Current()
|
||||||
|
|
||||||
publicKey, err := PublicKeyFile(user.HomeDir + "/.ssh/id_ed25519")
|
keyfile := user.HomeDir + "/.ssh/id_ed25519"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
if Exists("/cygwin") {
|
||||||
|
log.Println("On Windows, but running within cygwin")
|
||||||
|
keyfile = "/home/wit/.ssh/id_ed25519"
|
||||||
|
} else {
|
||||||
|
keyfile = user.HomeDir + "\\id_ed25519"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publicKey, err := PublicKeyFile(keyfile)
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
log.Println("PublicKeyFile() error =", err)
|
log.Println("PublicKeyFile() error =", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue