@@ -10,6 +10,7 @@ import (
10
10
"os"
11
11
"os/exec"
12
12
"path/filepath"
13
+ "regexp"
13
14
"strings"
14
15
15
16
"code.gitea.io/gitea/modules/setting"
@@ -32,14 +33,18 @@ type check struct {
32
33
33
34
var checklist = []check {
34
35
{
35
- title : "Check if openssh authorized_keys file correct" ,
36
+ title : "Check if openssh authorized_keys file id correct" ,
36
37
f : runDoctorLocationMoved ,
37
38
},
38
39
}
39
40
40
41
func runDoctor (ctx * cli.Context ) error {
41
- if err := initDB (); err != nil {
42
- return err
42
+ err := initDB ()
43
+ fmt .Println ("Using app.ini at " , setting .CustomConf )
44
+ if err != nil {
45
+ fmt .Println (err )
46
+ fmt .Println ("Check if you are using the right config file. You can use a --config directive to specify one." )
47
+ return nil
43
48
}
44
49
45
50
for i , check := range checklist {
@@ -90,28 +95,28 @@ func runDoctorLocationMoved(ctx *cli.Context) ([]string, error) {
90
95
91
96
// command="/Volumes/data/Projects/gitea/gitea/gitea --config
92
97
if len (firstline ) > 0 {
93
- var start , end int
94
- for i , c := range firstline {
95
- if c == ' ' {
96
- end = i
97
- break
98
- } else if c == '"' {
99
- start = i + 1
100
- }
98
+ exp := regexp .MustCompile (`^[ \t]*(?:command=")([^ ]+) --config='([^']+)' serv key-([^"]+)",(?:[^ ]+) ssh-rsa ([^ ]+) ([^ ]+)[ \t]*$` )
99
+
100
+ // 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 )
102
+
103
+ giteaPath := res [1 ] // => /home/user/gitea
104
+ iniPath := res [2 ] // => /home/user/etc/app.ini
105
+
106
+ p , err := exePath ()
107
+ if err != nil {
108
+ return nil , err
109
+ }
110
+ p , err = filepath .Abs (p )
111
+ if err != nil {
112
+ return nil , err
101
113
}
102
- if start > 0 && end > 0 {
103
- p , err := exePath ()
104
- if err != nil {
105
- return nil , err
106
- }
107
- p , err = filepath .Abs (p )
108
- if err != nil {
109
- return nil , err
110
- }
111
114
112
- if firstline [start :end ] != p {
113
- return []string {fmt .Sprintf ("Wants %s but %s on %s" , p , firstline [start :end ], fPath )}, nil
114
- }
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
117
+ }
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
115
120
}
116
121
}
117
122
0 commit comments