mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-20 04:37:13 +00:00
Bug fix #45
This commit is contained in:
parent
a6e12aaef6
commit
9f91dee53f
|
@ -43,9 +43,9 @@ func NewTestEngine(x *xorm.Engine) (err error) {
|
||||||
case "postgres":
|
case "postgres":
|
||||||
x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
|
x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
|
||||||
DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode))
|
DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode))
|
||||||
case "sqlite3":
|
// case "sqlite3":
|
||||||
os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
|
// os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
|
||||||
x, err = xorm.NewEngine("sqlite3", DbCfg.Path)
|
// x, err = xorm.NewEngine("sqlite3", DbCfg.Path)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type)
|
return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type)
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,7 +253,7 @@ func NewConfigContext() {
|
||||||
cfgPath := filepath.Join(workDir, "conf/app.ini")
|
cfgPath := filepath.Join(workDir, "conf/app.ini")
|
||||||
Cfg, err = goconfig.LoadConfigFile(cfgPath)
|
Cfg, err = goconfig.LoadConfigFile(cfgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Cannot load config file '%s'\n", cfgPath)
|
fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
Cfg.BlockMode = false
|
Cfg.BlockMode = false
|
||||||
|
@ -261,7 +261,7 @@ func NewConfigContext() {
|
||||||
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
|
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
|
||||||
if com.IsFile(cfgPath) {
|
if com.IsFile(cfgPath) {
|
||||||
if err = Cfg.AppendFiles(cfgPath); err != nil {
|
if err = Cfg.AppendFiles(cfgPath); err != nil {
|
||||||
fmt.Printf("Cannot load config file '%s'\n", cfgPath)
|
fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/Unknwon/goconfig"
|
"github.com/Unknwon/goconfig"
|
||||||
"github.com/codegangsta/martini"
|
"github.com/codegangsta/martini"
|
||||||
// "github.com/lunny/xorm"
|
"github.com/lunny/xorm"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/auth"
|
"github.com/gogits/gogs/modules/auth"
|
||||||
|
@ -113,12 +113,10 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||||
models.DbCfg.SslMode = form.SslMode
|
models.DbCfg.SslMode = form.SslMode
|
||||||
models.DbCfg.Path = form.DatabasePath
|
models.DbCfg.Path = form.DatabasePath
|
||||||
|
|
||||||
// ctx.RenderWithErr("Database setting is not correct: ", "install", &form)
|
// Set test engine.
|
||||||
// return
|
|
||||||
log.Trace("00000000000000000000000000000000000000000000")
|
|
||||||
var x *xorm.Engine
|
var x *xorm.Engine
|
||||||
if err := models.NewTestEngine(x); err != nil {
|
if err := models.NewTestEngine(x); err != nil {
|
||||||
if strings.Contains(err.Error(), `unknown driver "sqlite3"`) {
|
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
|
||||||
ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+
|
ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+
|
||||||
"from https://github.com/gogits/gogs/wiki/Install-from-binary, NOT the gobuild version.", "install", &form)
|
"from https://github.com/gogits/gogs/wiki/Install-from-binary, NOT the gobuild version.", "install", &form)
|
||||||
} else {
|
} else {
|
||||||
|
@ -133,15 +131,6 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create admin account.
|
|
||||||
if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd,
|
|
||||||
IsAdmin: true, IsActive: true}); err != nil {
|
|
||||||
if err != models.ErrUserAlreadyExist {
|
|
||||||
ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save settings.
|
// Save settings.
|
||||||
base.Cfg.SetValue("database", "DB_TYPE", models.DbCfg.Type)
|
base.Cfg.SetValue("database", "DB_TYPE", models.DbCfg.Type)
|
||||||
base.Cfg.SetValue("database", "HOST", models.DbCfg.Host)
|
base.Cfg.SetValue("database", "HOST", models.DbCfg.Host)
|
||||||
|
@ -168,13 +157,22 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||||
|
|
||||||
base.Cfg.SetValue("security", "INSTALL_LOCK", "true")
|
base.Cfg.SetValue("security", "INSTALL_LOCK", "true")
|
||||||
|
|
||||||
if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app1.ini"); err != nil {
|
if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil {
|
||||||
ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form)
|
ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalInit()
|
GlobalInit()
|
||||||
|
|
||||||
|
// Create admin account.
|
||||||
|
if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd,
|
||||||
|
IsAdmin: true, IsActive: true}); err != nil {
|
||||||
|
if err != models.ErrUserAlreadyExist {
|
||||||
|
ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Info("First-time run install finished!")
|
log.Info("First-time run install finished!")
|
||||||
ctx.Redirect("/user/login")
|
ctx.Redirect("/user/login")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue