forked from tangled.org/core
this repo has no description

guard: read the motd from a file

Signed-off-by: dusk <y.bera003.06@protonmail.com>

Change-Id: kvuxwxxzvvqtvypqzlotlwkqmuttqwun

authored by ptr.pet and committed by Tangled c1b8fd83 17890890

Changed files
+19 -3
guard
+19 -3
guard/guard.go
··· 2 3 import ( 4 "context" 5 "fmt" 6 "log/slog" 7 "net/http" 8 "net/url" ··· 43 Usage: "internal API endpoint", 44 Value: "http://localhost:5444", 45 }, 46 }, 47 } 48 } ··· 54 gitDir := cmd.String("git-dir") 55 logPath := cmd.String("log-path") 56 endpoint := cmd.String("internal-api") 57 58 logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) 59 if err != nil { ··· 149 "fullPath", fullPath, 150 "client", clientIP) 151 152 - if gitCommand == "git-upload-pack" { 153 - fmt.Fprintf(os.Stderr, "\x02%s\n", "Welcome to this knot!") 154 } else { 155 - fmt.Fprintf(os.Stderr, "%s\n", "Welcome to this knot!") 156 } 157 158 gitCmd := exec.Command(gitCommand, fullPath) 159 gitCmd.Stdout = os.Stdout
··· 2 3 import ( 4 "context" 5 + "errors" 6 "fmt" 7 + "io" 8 "log/slog" 9 "net/http" 10 "net/url" ··· 45 Usage: "internal API endpoint", 46 Value: "http://localhost:5444", 47 }, 48 + &cli.StringFlag{ 49 + Name: "motd-file", 50 + Usage: "path to message of the day file", 51 + Value: "/home/git/motd", 52 + }, 53 }, 54 } 55 } ··· 61 gitDir := cmd.String("git-dir") 62 logPath := cmd.String("log-path") 63 endpoint := cmd.String("internal-api") 64 + motdFile := cmd.String("motd-file") 65 66 logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) 67 if err != nil { ··· 157 "fullPath", fullPath, 158 "client", clientIP) 159 160 + var motdReader io.Reader 161 + if reader, err := os.Open(motdFile); err != nil { 162 + if !errors.Is(err, os.ErrNotExist) { 163 + l.Error("failed to read motd file", "error", err) 164 + } 165 + motdReader = strings.NewReader("Welcome to this knot!\n") 166 } else { 167 + motdReader = reader 168 + } 169 + if gitCommand == "git-upload-pack" { 170 + io.WriteString(os.Stderr, "\x02") 171 } 172 + io.Copy(os.Stderr, motdReader) 173 174 gitCmd := exec.Command(gitCommand, fullPath) 175 gitCmd.Stdout = os.Stdout