![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) | ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) | ||||
##### Current version: 0.8.10 | |||||
##### Current version: 0.8.11 | |||||
| Web | UI | Preview | | | Web | UI | Preview | | ||||
|:-------------:|:-------:|:-------:| | |:-------------:|:-------:|:-------:| |
; Whether use builtin SSH server or not. | ; Whether use builtin SSH server or not. | ||||
START_SSH_SERVER = false | START_SSH_SERVER = false | ||||
SSH_PORT = 22 | SSH_PORT = 22 | ||||
; Root path of SSH directory | |||||
SSH_ROOT_PATH = | |||||
; Disable CDN even in "prod" mode | ; Disable CDN even in "prod" mode | ||||
OFFLINE_MODE = false | OFFLINE_MODE = false | ||||
DISABLE_ROUTER_LOG = false | DISABLE_ROUTER_LOG = false |
"github.com/gogits/gogs/modules/setting" | "github.com/gogits/gogs/modules/setting" | ||||
) | ) | ||||
const APP_VER = "0.8.10.1219" | |||||
const APP_VER = "0.8.11.1219" | |||||
func init() { | func init() { | ||||
runtime.GOMAXPROCS(runtime.NumCPU()) | runtime.GOMAXPROCS(runtime.NumCPU()) |
) | ) | ||||
var sshOpLocker = sync.Mutex{} | var sshOpLocker = sync.Mutex{} | ||||
var SSHPath string // SSH directory. | |||||
// homeDir returns the home directory of current user. | |||||
func homeDir() string { | |||||
home, err := com.HomeDir() | |||||
if err != nil { | |||||
log.Fatal(4, "Fail to get home directory: %v", err) | |||||
} | |||||
return home | |||||
} | |||||
func init() { | |||||
// Determine and create .ssh path. | |||||
SSHPath = filepath.Join(homeDir(), ".ssh") | |||||
if err := os.MkdirAll(SSHPath, 0700); err != nil { | |||||
log.Fatal(4, "fail to create '%s': %v", SSHPath, err) | |||||
} | |||||
} | |||||
type KeyType int | type KeyType int | ||||
sshOpLocker.Lock() | sshOpLocker.Lock() | ||||
defer sshOpLocker.Unlock() | defer sshOpLocker.Unlock() | ||||
fpath := filepath.Join(SSHPath, "authorized_keys") | |||||
fpath := filepath.Join(setting.SSHRootPath, "authorized_keys") | |||||
f, err := os.OpenFile(fpath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600) | f, err := os.OpenFile(fpath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600) | ||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
return nil | return nil | ||||
} | } | ||||
fpath := filepath.Join(SSHPath, "authorized_keys") | |||||
tmpPath := filepath.Join(SSHPath, "authorized_keys.tmp") | |||||
fpath := filepath.Join(setting.SSHRootPath, "authorized_keys") | |||||
tmpPath := filepath.Join(setting.SSHRootPath, "authorized_keys.tmp") | |||||
if err = rewriteAuthorizedKeys(key, fpath, tmpPath); err != nil { | if err = rewriteAuthorizedKeys(key, fpath, tmpPath); err != nil { | ||||
return err | return err | ||||
} else if err = os.Remove(fpath); err != nil { | } else if err = os.Remove(fpath); err != nil { | ||||
sshOpLocker.Lock() | sshOpLocker.Lock() | ||||
defer sshOpLocker.Unlock() | defer sshOpLocker.Unlock() | ||||
tmpPath := filepath.Join(SSHPath, "authorized_keys.tmp") | |||||
tmpPath := filepath.Join(setting.SSHRootPath, "authorized_keys.tmp") | |||||
f, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) | f, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) | ||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
return err | return err | ||||
} | } | ||||
fpath := filepath.Join(SSHPath, "authorized_keys") | |||||
fpath := filepath.Join(setting.SSHRootPath, "authorized_keys") | |||||
if com.IsExist(fpath) { | if com.IsExist(fpath) { | ||||
if err = os.Remove(fpath); err != nil { | if err = os.Remove(fpath); err != nil { | ||||
return err | return err |
StartSSHServer bool | StartSSHServer bool | ||||
SSHDomain string | SSHDomain string | ||||
SSHPort int | SSHPort int | ||||
SSHRootPath string | |||||
OfflineMode bool | OfflineMode bool | ||||
DisableRouterLog bool | DisableRouterLog bool | ||||
CertFile, KeyFile string | CertFile, KeyFile string | ||||
log.Fatal(4, "Fail to load custom conf '%s': %v", CustomConf, err) | log.Fatal(4, "Fail to load custom conf '%s': %v", CustomConf, err) | ||||
} | } | ||||
} else { | } else { | ||||
log.Warn("Custom config (%s) not found, ignore this if you're running first time", CustomConf) | |||||
log.Warn("Custom config '%s' not found, ignore this if you're running first time", CustomConf) | |||||
} | } | ||||
Cfg.NameMapper = ini.AllCapsUnderscore | Cfg.NameMapper = ini.AllCapsUnderscore | ||||
homeDir, err := com.HomeDir() | |||||
if err != nil { | |||||
log.Fatal(4, "Fail to get home directory: %v", err) | |||||
} | |||||
homeDir = strings.Replace(homeDir, "\\", "/", -1) | |||||
LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(workDir, "log")) | LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(workDir, "log")) | ||||
forcePathSeparator(LogRootPath) | forcePathSeparator(LogRootPath) | ||||
// Check if has app suburl. | // Check if has app suburl. | ||||
url, err := url.Parse(AppUrl) | url, err := url.Parse(AppUrl) | ||||
if err != nil { | if err != nil { | ||||
log.Fatal(4, "Invalid ROOT_URL(%s): %s", AppUrl, err) | |||||
log.Fatal(4, "Invalid ROOT_URL '%s': %s", AppUrl, err) | |||||
} | } | ||||
AppSubUrl = strings.TrimSuffix(url.Path, "/") | AppSubUrl = strings.TrimSuffix(url.Path, "/") | ||||
} | } | ||||
SSHDomain = sec.Key("SSH_DOMAIN").MustString(Domain) | SSHDomain = sec.Key("SSH_DOMAIN").MustString(Domain) | ||||
SSHPort = sec.Key("SSH_PORT").MustInt(22) | SSHPort = sec.Key("SSH_PORT").MustInt(22) | ||||
SSHRootPath = sec.Key("SSH_ROOT_PATH").MustString(path.Join(homeDir, ".ssh")) | |||||
if err := os.MkdirAll(SSHRootPath, 0700); err != nil { | |||||
log.Fatal(4, "Fail to create '%s': %v", SSHRootPath, err) | |||||
} | |||||
OfflineMode = sec.Key("OFFLINE_MODE").MustBool() | OfflineMode = sec.Key("OFFLINE_MODE").MustBool() | ||||
DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool() | DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool() | ||||
StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(workDir) | StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(workDir) | ||||
} | } | ||||
// Determine and create root git repository path. | // Determine and create root git repository path. | ||||
homeDir, err := com.HomeDir() | |||||
if err != nil { | |||||
log.Fatal(4, "Fail to get home directory: %v", err) | |||||
} | |||||
homeDir = strings.Replace(homeDir, "\\", "/", -1) | |||||
sec = Cfg.Section("repository") | sec = Cfg.Section("repository") | ||||
RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gogs-repositories")) | RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gogs-repositories")) | ||||
forcePathSeparator(RepoRootPath) | forcePathSeparator(RepoRootPath) |
0.8.10.1219 | |||||
0.8.11.1219 |