diff options
author | Unknwon <u@gogs.io> | 2015-11-14 13:21:31 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-11-14 13:21:31 -0500 |
commit | 7c80eba77f727c2b80b4091c850dc38d47532b8d (patch) | |
tree | bb6f3811bc3547e18266eed7410b1f2ba8d7d5f2 /modules/ssh | |
parent | 9c12ed3b6edb4d087db79fbc8482c9211021602d (diff) | |
download | gitea-7c80eba77f727c2b80b4091c850dc38d47532b8d.tar.gz gitea-7c80eba77f727c2b80b4091c850dc38d47532b8d.zip |
minor UI fix and fix ssh race
Diffstat (limited to 'modules/ssh')
-rw-r--r-- | modules/ssh/ssh.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 5e3761ca19..706f5e7503 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -7,6 +7,7 @@ package ssh import ( + "fmt" "io" "io/ioutil" "net" @@ -82,14 +83,16 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) { return } - go io.Copy(ch, stdout) - go io.Copy(ch.Stderr(), stderr) - go io.Copy(input, ch) - if err = cmd.Start(); err != nil { log.Error(3, "Start: %v", err) return - } else if err = cmd.Wait(); err != nil { + } + + go io.Copy(input, ch) + io.Copy(ch, stdout) + io.Copy(ch.Stderr(), stderr) + + if err = cmd.Wait(); err != nil { log.Error(3, "Wait: %v", err) return } @@ -142,7 +145,16 @@ func Listen(port int) { }, } - privateBytes, err := ioutil.ReadFile(filepath.Join(models.SSHPath, "id_rsa")) + keyPath := filepath.Join(setting.AppDataPath, "ssh/gogs.rsa") + if !com.IsExist(keyPath) { + os.MkdirAll(filepath.Dir(keyPath), os.ModePerm) + _, stderr, err := com.ExecCmd("ssh-keygen", "-f", keyPath, "-t", "rsa", "-N", "") + if err != nil { + panic(fmt.Sprintf("Fail to generate private key: %v - %s", err, stderr)) + } + } + + privateBytes, err := ioutil.ReadFile(keyPath) if err != nil { panic("Fail to load private key") } |