all repos

mugit @ c826112

🐮 git server that your cow will love
5 files changed, 22 insertions(+), 6 deletions(-)
support custom ssh user name (for future switch to ssh)
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-03-05 21:09:09 +0200
Change ID: usyrorzswltynllxvoxsvlxlporxyyuv
Parent: 9d3f4dd
M README.md

@@ -89,6 +89,7 @@ # ssh: push/clone over SSH

ssh: enable: true port: 2222 # SSH port (default 2222) + user: "git" # user as which the app operates (default "git") host_key: /var/lib/mugit/host # path to SSH host key (generate with ssh-keygen) # Only these public keys can access private repos and push to others. keys:
M internal/config/config.go

@@ -36,6 +36,7 @@ }

type SSHConfig struct { Enable bool `yaml:"enable"` + User string `yaml:"user"` Port int `yaml:"port"` HostKey string `yaml:"host_key"` Keys []string `yaml:"keys"`

@@ -117,13 +118,9 @@ return ""

} func (c *Config) ensureDefaults() { - // ports + // http if c.Server.Port == 0 { c.Server.Port = 8080 - } - - if c.SSH.Port == 0 { - c.SSH.Port = 2222 } // meta

@@ -143,6 +140,15 @@ "README.html", "readme.html",

"README.txt", "readme.txt", "readme", } + } + + // ssh + if c.SSH.Port == 0 { + c.SSH.Port = 2222 + } + + if c.SSH.User == "" { + c.SSH.User = "git" } // mirroring
M internal/config/validate.go

@@ -3,8 +3,11 @@

import ( "errors" "fmt" + "regexp" "strings" ) + +var validUserNameRe = regexp.MustCompile("^[a-z_][a-z0-9_-]{0,31}$") func (c Config) validate() error { var errs []error

@@ -32,6 +35,10 @@ }

if c.SSH.Port == c.Server.Port { errs = append(errs, fmt.Errorf("ssh.port must differ from server.port (both are %d)", c.Server.Port)) + } + + if !validUserNameRe.MatchString(c.SSH.User) { + errs = append(errs, fmt.Errorf("ssh.user must be correct linux user name(^[a-z_][a-z0-9_-]{0,31}$)")) } if !isFileExists(c.SSH.HostKey) {
M internal/handlers/repo.go

@@ -50,6 +50,7 @@ }

type RepoIndex struct { Desc string + SSHUser string IsEmpty bool Readme template.HTML Ref string

@@ -106,6 +107,7 @@ p.MirrorURL, _ = repo.RemoteURL()

p.MirrorLastSync, _ = repo.LastSync() } + p.SSHUser = h.c.SSH.User h.templ(w, "repo_index", h.pageData(repo, p)) }
M web/templates/repo_index.html

@@ -35,7 +35,7 @@

<div class="repo-index-side"> <h2>Clone urls</h2> <pre>https://{{.Meta.Host}}/{{.RepoName}}</pre> - {{ if .Meta.SSHEnabled }}<pre>git@{{.Meta.Host}}:{{.RepoName}}</pre>{{end}} + {{ if .Meta.SSHEnabled }}<pre>{{ .P.SSHUser }}@{{.Meta.Host}}:{{.RepoName}}</pre>{{end}} {{- if .P.IsMirror -}} <br> <h2>Mirror status</h2>