|
|
@ -73,12 +73,7 @@ func GlobalInit() { |
|
|
|
checkRunMode() |
|
|
|
checkRunMode() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func renderDbOption(ctx *middleware.Context) { |
|
|
|
func InstallInit(ctx *middleware.Context) { |
|
|
|
ctx.Data["DbOptions"] = []string{"MySQL", "PostgreSQL", "SQLite3"} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @router /install [get]
|
|
|
|
|
|
|
|
func Install(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
|
|
|
|
if setting.InstallLock { |
|
|
|
if setting.InstallLock { |
|
|
|
ctx.Handle(404, "Install", errors.New("Installation is prohibited")) |
|
|
|
ctx.Handle(404, "Install", errors.New("Installation is prohibited")) |
|
|
|
return |
|
|
|
return |
|
|
@ -87,29 +82,22 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("install.install") |
|
|
|
ctx.Data["Title"] = ctx.Tr("install.install") |
|
|
|
ctx.Data["PageIsInstall"] = true |
|
|
|
ctx.Data["PageIsInstall"] = true |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: when i'm ckeching length here? should they all be 0 no matter when?
|
|
|
|
ctx.Data["DbOptions"] = []string{"MySQL", "PostgreSQL", "SQLite3"} |
|
|
|
// Get and assign values to install form.
|
|
|
|
} |
|
|
|
if len(form.DbHost) == 0 { |
|
|
|
|
|
|
|
|
|
|
|
func Install(ctx *middleware.Context) { |
|
|
|
|
|
|
|
form := auth.InstallForm{} |
|
|
|
|
|
|
|
|
|
|
|
form.DbHost = models.DbCfg.Host |
|
|
|
form.DbHost = models.DbCfg.Host |
|
|
|
} |
|
|
|
|
|
|
|
if len(form.DbUser) == 0 { |
|
|
|
|
|
|
|
form.DbUser = models.DbCfg.User |
|
|
|
form.DbUser = models.DbCfg.User |
|
|
|
} |
|
|
|
form.DbPasswd = models.DbCfg.Passwd |
|
|
|
if len(form.DbPasswd) == 0 { |
|
|
|
form.DbName = models.DbCfg.Name |
|
|
|
form.DbPasswd = models.DbCfg.Pwd |
|
|
|
form.DbPath = models.DbCfg.Path |
|
|
|
} |
|
|
|
|
|
|
|
if len(form.DatabaseName) == 0 { |
|
|
|
|
|
|
|
form.DatabaseName = models.DbCfg.Name |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if len(form.DatabasePath) == 0 { |
|
|
|
|
|
|
|
form.DatabasePath = models.DbCfg.Path |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(form.RepoRootPath) == 0 { |
|
|
|
|
|
|
|
form.RepoRootPath = setting.RepoRootPath |
|
|
|
form.RepoRootPath = setting.RepoRootPath |
|
|
|
} |
|
|
|
|
|
|
|
if len(form.RunUser) == 0 { |
|
|
|
// Note(unknwon): it's hard for Windows users change a running user,
|
|
|
|
// Note: it's not normall to use SSH in windows so current user can be first option(not git).
|
|
|
|
// so just use current one if config says default.
|
|
|
|
if setting.IsWindows && setting.RunUser == "git" { |
|
|
|
if setting.IsWindows && setting.RunUser == "git" { |
|
|
|
form.RunUser = os.Getenv("USER") |
|
|
|
form.RunUser = os.Getenv("USER") |
|
|
|
if len(form.RunUser) == 0 { |
|
|
|
if len(form.RunUser) == 0 { |
|
|
@ -118,15 +106,11 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
form.RunUser = setting.RunUser |
|
|
|
form.RunUser = setting.RunUser |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if len(form.Domain) == 0 { |
|
|
|
|
|
|
|
form.Domain = setting.Domain |
|
|
|
form.Domain = setting.Domain |
|
|
|
} |
|
|
|
form.HTTPPort = setting.HttpPort |
|
|
|
if len(form.AppUrl) == 0 { |
|
|
|
|
|
|
|
form.AppUrl = setting.AppUrl |
|
|
|
form.AppUrl = setting.AppUrl |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderDbOption(ctx) |
|
|
|
|
|
|
|
curDbOp := "" |
|
|
|
curDbOp := "" |
|
|
|
if models.EnableSQLite3 { |
|
|
|
if models.EnableSQLite3 { |
|
|
|
curDbOp = "SQLite3" // Default when enabled.
|
|
|
|
curDbOp = "SQLite3" // Default when enabled.
|
|
|
@ -138,16 +122,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func InstallPost(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
func InstallPost(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
if setting.InstallLock { |
|
|
|
ctx.Data["CurDbOption"] = form.DbType |
|
|
|
ctx.Handle(404, "InstallPost", errors.New("Installation is prohibited")) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["Title"] = ctx.Tr("install.install") |
|
|
|
|
|
|
|
ctx.Data["PageIsInstall"] = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderDbOption(ctx) |
|
|
|
|
|
|
|
ctx.Data["CurDbOption"] = form.Database |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
if ctx.HasError() { |
|
|
|
ctx.HTML(200, INSTALL) |
|
|
|
ctx.HTML(200, INSTALL) |
|
|
@ -162,18 +137,17 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
// Pass basic check, now test configuration.
|
|
|
|
// Pass basic check, now test configuration.
|
|
|
|
// Test database setting.
|
|
|
|
// Test database setting.
|
|
|
|
dbTypes := map[string]string{"MySQL": "mysql", "PostgreSQL": "postgres", "SQLite3": "sqlite3"} |
|
|
|
dbTypes := map[string]string{"MySQL": "mysql", "PostgreSQL": "postgres", "SQLite3": "sqlite3"} |
|
|
|
models.DbCfg.Type = dbTypes[form.Database] |
|
|
|
models.DbCfg.Type = dbTypes[form.DbType] |
|
|
|
models.DbCfg.Host = form.DbHost |
|
|
|
models.DbCfg.Host = form.DbHost |
|
|
|
models.DbCfg.User = form.DbUser |
|
|
|
models.DbCfg.User = form.DbUser |
|
|
|
models.DbCfg.Pwd = form.DbPasswd |
|
|
|
models.DbCfg.Passwd = form.DbPasswd |
|
|
|
models.DbCfg.Name = form.DatabaseName |
|
|
|
models.DbCfg.Name = form.DbName |
|
|
|
models.DbCfg.SslMode = form.SslMode |
|
|
|
models.DbCfg.SSLMode = form.SSLMode |
|
|
|
models.DbCfg.Path = form.DatabasePath |
|
|
|
models.DbCfg.Path = form.DbPath |
|
|
|
|
|
|
|
|
|
|
|
// Set test engine.
|
|
|
|
// Set test engine.
|
|
|
|
var x *xorm.Engine |
|
|
|
var x *xorm.Engine |
|
|
|
if err := models.NewTestEngine(x); err != nil { |
|
|
|
if err := models.NewTestEngine(x); err != nil { |
|
|
|
// FIXME: should use core.QueryDriver (github.com/go-xorm/core)
|
|
|
|
|
|
|
|
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) { |
|
|
|
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) { |
|
|
|
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "http://gogs.io/docs/installation/install_from_binary.html"), INSTALL, &form) |
|
|
|
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "http://gogs.io/docs/installation/install_from_binary.html"), INSTALL, &form) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -194,7 +168,6 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
if len(curUser) == 0 { |
|
|
|
if len(curUser) == 0 { |
|
|
|
curUser = os.Getenv("USERNAME") |
|
|
|
curUser = os.Getenv("USERNAME") |
|
|
|
} |
|
|
|
} |
|
|
|
// Does not check run user when the install lock is off.
|
|
|
|
|
|
|
|
if form.RunUser != curUser { |
|
|
|
if form.RunUser != curUser { |
|
|
|
ctx.Data["Err_RunUser"] = true |
|
|
|
ctx.Data["Err_RunUser"] = true |
|
|
|
ctx.RenderWithErr(ctx.Tr("install.run_user_not_match", form.RunUser, curUser), INSTALL, &form) |
|
|
|
ctx.RenderWithErr(ctx.Tr("install.run_user_not_match", form.RunUser, curUser), INSTALL, &form) |
|
|
@ -202,31 +175,36 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check admin password.
|
|
|
|
// Check admin password.
|
|
|
|
if form.AdminPasswd != form.ConfirmPasswd { |
|
|
|
if form.AdminPasswd != form.AdminConfirmPasswd { |
|
|
|
ctx.Data["Err_AdminPasswd"] = true |
|
|
|
ctx.Data["Err_AdminPasswd"] = true |
|
|
|
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), INSTALL, form) |
|
|
|
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), INSTALL, form) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form.AppUrl[len(form.AppUrl)-1] != '/' { |
|
|
|
|
|
|
|
form.AppUrl += "/" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Save settings.
|
|
|
|
// Save settings.
|
|
|
|
setting.Cfg.Section("database").Key("DB_TYPE").SetValue(models.DbCfg.Type) |
|
|
|
setting.Cfg.Section("database").Key("DB_TYPE").SetValue(models.DbCfg.Type) |
|
|
|
setting.Cfg.Section("database").Key("HOST").SetValue(models.DbCfg.Host) |
|
|
|
setting.Cfg.Section("database").Key("HOST").SetValue(models.DbCfg.Host) |
|
|
|
setting.Cfg.Section("database").Key("NAME").SetValue(models.DbCfg.Name) |
|
|
|
setting.Cfg.Section("database").Key("NAME").SetValue(models.DbCfg.Name) |
|
|
|
setting.Cfg.Section("database").Key("USER").SetValue(models.DbCfg.User) |
|
|
|
setting.Cfg.Section("database").Key("USER").SetValue(models.DbCfg.User) |
|
|
|
setting.Cfg.Section("database").Key("PASSWD").SetValue(models.DbCfg.Pwd) |
|
|
|
setting.Cfg.Section("database").Key("PASSWD").SetValue(models.DbCfg.Passwd) |
|
|
|
setting.Cfg.Section("database").Key("SSL_MODE").SetValue(models.DbCfg.SslMode) |
|
|
|
setting.Cfg.Section("database").Key("SSL_MODE").SetValue(models.DbCfg.SSLMode) |
|
|
|
setting.Cfg.Section("database").Key("PATH").SetValue(models.DbCfg.Path) |
|
|
|
setting.Cfg.Section("database").Key("PATH").SetValue(models.DbCfg.Path) |
|
|
|
|
|
|
|
|
|
|
|
setting.Cfg.Section("repository").Key("ROOT").SetValue(form.RepoRootPath) |
|
|
|
setting.Cfg.Section("repository").Key("ROOT").SetValue(form.RepoRootPath) |
|
|
|
setting.Cfg.Section("").Key("RUN_USER").SetValue(form.RunUser) |
|
|
|
setting.Cfg.Section("").Key("RUN_USER").SetValue(form.RunUser) |
|
|
|
setting.Cfg.Section("server").Key("DOMAIN").SetValue(form.Domain) |
|
|
|
setting.Cfg.Section("server").Key("DOMAIN").SetValue(form.Domain) |
|
|
|
|
|
|
|
setting.Cfg.Section("server").Key("HTTP_PORT").SetValue(form.HTTPPort) |
|
|
|
setting.Cfg.Section("server").Key("ROOT_URL").SetValue(form.AppUrl) |
|
|
|
setting.Cfg.Section("server").Key("ROOT_URL").SetValue(form.AppUrl) |
|
|
|
|
|
|
|
|
|
|
|
if len(strings.TrimSpace(form.SmtpHost)) > 0 { |
|
|
|
if len(strings.TrimSpace(form.SMTPHost)) > 0 { |
|
|
|
setting.Cfg.Section("mailer").Key("ENABLED").SetValue("true") |
|
|
|
setting.Cfg.Section("mailer").Key("ENABLED").SetValue("true") |
|
|
|
setting.Cfg.Section("mailer").Key("HOST").SetValue(form.SmtpHost) |
|
|
|
setting.Cfg.Section("mailer").Key("HOST").SetValue(form.SMTPHost) |
|
|
|
setting.Cfg.Section("mailer").Key("USER").SetValue(form.SmtpEmail) |
|
|
|
setting.Cfg.Section("mailer").Key("USER").SetValue(form.SMTPEmail) |
|
|
|
setting.Cfg.Section("mailer").Key("PASSWD").SetValue(form.SmtpPasswd) |
|
|
|
setting.Cfg.Section("mailer").Key("PASSWD").SetValue(form.SMTPPasswd) |
|
|
|
|
|
|
|
|
|
|
|
setting.Cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").SetValue(com.ToStr(form.RegisterConfirm == "on")) |
|
|
|
setting.Cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").SetValue(com.ToStr(form.RegisterConfirm == "on")) |
|
|
|
setting.Cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").SetValue(com.ToStr(form.MailNotify == "on")) |
|
|
|
setting.Cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").SetValue(com.ToStr(form.MailNotify == "on")) |
|
|
@ -264,5 +242,5 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { |
|
|
|
|
|
|
|
|
|
|
|
log.Info("First-time run install finished!") |
|
|
|
log.Info("First-time run install finished!") |
|
|
|
ctx.Flash.Success(ctx.Tr("install.install_success")) |
|
|
|
ctx.Flash.Success(ctx.Tr("install.install_success")) |
|
|
|
ctx.Redirect(setting.AppSubUrl + "/user/login") |
|
|
|
ctx.Redirect(form.AppUrl + "user/login") |
|
|
|
} |
|
|
|
} |
|
|
|