utils.go 812 B

123456789101112131415161718192021222324252627
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package conf
  5. import (
  6. "strings"
  7. "github.com/pkg/errors"
  8. "gogs.io/gogs/internal/process"
  9. )
  10. // openSSHVersion returns string representation of OpenSSH version via command "ssh -V".
  11. func openSSHVersion() (string, error) {
  12. // NOTE: Somehow the version is printed to stderr.
  13. _, stderr, err := process.Exec("conf.openSSHVersion", "ssh", "-V")
  14. if err != nil {
  15. return "", errors.Wrap(err, stderr)
  16. }
  17. // Trim unused information, see https://github.com/gogs/gogs/issues/4507#issuecomment-305150441.
  18. v := strings.TrimRight(strings.Fields(stderr)[0], ",1234567890")
  19. v = strings.TrimSuffix(strings.TrimPrefix(v, "OpenSSH_"), "p")
  20. return v, nil
  21. }