Skip to content

Commit bc573b6

Browse files
committed
Add documentation
1 parent a4c1235 commit bc573b6

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

cmd/doctor.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cmd
66

77
import (
88
"bufio"
9+
"errors"
910
"fmt"
1011
"os"
1112
"os/exec"
@@ -31,16 +32,18 @@ type check struct {
3132
f func(ctx *cli.Context) ([]string, error)
3233
}
3334

35+
// checklist represents list for all checks
3436
var checklist = []check{
3537
{
36-
title: "Check if openssh authorized_keys file id correct",
38+
title: "Check if OpenSSH authorized_keys file id correct",
3739
f: runDoctorLocationMoved,
3840
},
41+
// more checks please append here
3942
}
4043

4144
func runDoctor(ctx *cli.Context) error {
4245
err := initDB()
43-
fmt.Println("Using app.ini at ", setting.CustomConf)
46+
fmt.Println("Using app.ini at", setting.CustomConf)
4447
if err != nil {
4548
fmt.Println(err)
4649
fmt.Println("Check if you are using the right config file. You can use a --config directive to specify one.")
@@ -49,7 +52,6 @@ func runDoctor(ctx *cli.Context) error {
4952

5053
for i, check := range checklist {
5154
fmt.Println("[", i+1, "]", check.title)
52-
fmt.Println()
5355
if messages, err := check.f(ctx); err != nil {
5456
fmt.Println("Error:", err)
5557
} else if len(messages) > 0 {
@@ -73,7 +75,7 @@ func exePath() (string, error) {
7375
}
7476

7577
func runDoctorLocationMoved(ctx *cli.Context) ([]string, error) {
76-
if setting.SSH.StartBuiltinServer {
78+
if setting.SSH.StartBuiltinServer || !setting.SSH.CreateAuthorizedKeysFile {
7779
return nil, nil
7880
}
7981

@@ -87,18 +89,22 @@ func runDoctorLocationMoved(ctx *cli.Context) ([]string, error) {
8789
var firstline string
8890
scanner := bufio.NewScanner(f)
8991
for scanner.Scan() {
90-
firstline = scanner.Text()
91-
if !strings.HasPrefix(firstline, "#") {
92-
break
92+
firstline = strings.TrimSpace(scanner.Text())
93+
if len(firstline) == 0 || firstline[0] == '#' {
94+
continue
9395
}
96+
break
9497
}
9598

9699
// command="/Volumes/data/Projects/gitea/gitea/gitea --config
97100
if len(firstline) > 0 {
98101
exp := regexp.MustCompile(`^[ \t]*(?:command=")([^ ]+) --config='([^']+)' serv key-([^"]+)",(?:[^ ]+) ssh-rsa ([^ ]+) ([^ ]+)[ \t]*$`)
99102

100103
// command="/home/user/gitea --config='/home/user/etc/app.ini' serv key-999",option-1,option-2,option-n ssh-rsa public-key-value key-name
101-
res := exp.FindAllStringSubmatch(firstline, -1)
104+
res := exp.FindStringSubmatch(firstline)
105+
if res == nil {
106+
return nil, errors.New("Unknow authorized_keys format")
107+
}
102108

103109
giteaPath := res[1] // => /home/user/gitea
104110
iniPath := res[2] // => /home/user/etc/app.ini
@@ -112,11 +118,11 @@ func runDoctorLocationMoved(ctx *cli.Context) ([]string, error) {
112118
return nil, err
113119
}
114120

115-
if len(giteaPath) > 0 && giteaPath[0] != p {
116-
return []string{fmt.Sprintf("Gitea exe path wants %s but %s on %s", p, giteaPath[0], fPath)}, nil
121+
if len(giteaPath) > 0 && giteaPath != p {
122+
return []string{fmt.Sprintf("Gitea exe path wants %s but %s on %s", p, giteaPath, fPath)}, nil
117123
}
118-
if len(iniPath) > 0 && iniPath[0] != setting.CustomConf {
119-
return []string{fmt.Sprintf("Gitea config path wants %s but %s on %s", setting.CustomConf, iniPath[0], fPath)}, nil
124+
if len(iniPath) > 0 && iniPath != setting.CustomConf {
125+
return []string{fmt.Sprintf("Gitea config path wants %s but %s on %s", setting.CustomConf, iniPath, fPath)}, nil
120126
}
121127
}
122128

docs/content/doc/usage/command-line.en-us.md

+25
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,28 @@ This command is idempotent.
289289

290290
#### convert
291291
Converts an existing MySQL database from utf8 to utf8mb4.
292+
293+
#### doctor
294+
Diagnose the problems of current gitea instance according the given configuration.
295+
Currently there are a check list below:
296+
297+
- Check if OpenSSH authorized_keys file id correct
298+
When your gitea instance support OpenSSH, your gitea instance binary path will be written to `authorized_keys`
299+
when there is any public key added or changed on your gitea instance.
300+
Sometimes if you moved or renamed your gitea binary when upgrade and you haven't run `Update the '.ssh/authorized_keys' file with Gitea SSH keys. (Not needed for the built-in SSH server.)` on your Admin Panel. Then all pull/push via SSH will not be work.
301+
This check will help you to check if it works well.
302+
303+
For contributors, if you want to add more checks, you can wrie ad new function like `func(ctx *cli.Context) ([]string, error)` and
304+
append it to `doctor.go`.
305+
306+
```go
307+
var checklist = []check{
308+
{
309+
title: "Check if OpenSSH authorized_keys file id correct",
310+
f: runDoctorLocationMoved,
311+
},
312+
// more checks please append here
313+
}
314+
```
315+
316+
This function will receive a command line context and return a list of details about the problems or error.

0 commit comments

Comments
 (0)