summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/init.go22
-rw-r--r--routers/install/install.go20
-rw-r--r--routers/install/setting.go51
-rw-r--r--routers/web/admin/config.go15
4 files changed, 22 insertions, 86 deletions
diff --git a/routers/init.go b/routers/init.go
index 5737ef3dc0..f2c509b368 100644
--- a/routers/init.go
+++ b/routers/init.go
@@ -28,7 +28,6 @@ import (
"code.gitea.io/gitea/modules/system"
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation"
- "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
actions_router "code.gitea.io/gitea/routers/api/actions"
packages_router "code.gitea.io/gitea/routers/api/packages"
@@ -101,21 +100,16 @@ func syncAppConfForGit(ctx context.Context) error {
return nil
}
-// GlobalInitInstalled is for global installed configuration.
-func GlobalInitInstalled(ctx context.Context) {
- if !setting.InstallLock {
- log.Fatal("Gitea is not installed")
- }
+func InitWebInstallPage(ctx context.Context) {
+ translation.InitLocales(ctx)
+ setting.LoadSettingsForInstall()
+ mustInit(svg.Init)
+}
+// InitWebInstalled is for global installed configuration.
+func InitWebInstalled(ctx context.Context) {
mustInitCtx(ctx, git.InitFull)
- log.Info("Gitea Version: %s%s", setting.AppVer, setting.AppBuiltWith)
- log.Info("Git Version: %s (home: %s)", git.VersionInfo(), git.HomeDir())
- log.Info("AppPath: %s", setting.AppPath)
- log.Info("AppWorkPath: %s", setting.AppWorkPath)
- log.Info("Custom path: %s", setting.CustomPath)
- log.Info("Log path: %s", setting.Log.RootPath)
- log.Info("Configuration file: %s", setting.CustomConf)
- log.Info("Run Mode: %s", util.ToTitleCase(setting.RunMode))
+ log.Info("Git version: %s (home: %s)", git.VersionInfo(), git.HomeDir())
// Setup i18n
translation.InitLocales(ctx)
diff --git a/routers/install/install.go b/routers/install/install.go
index b76b7fdc30..f121f31376 100644
--- a/routers/install/install.go
+++ b/routers/install/install.go
@@ -32,6 +32,7 @@ import (
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/modules/web/middleware"
+ "code.gitea.io/gitea/routers/common"
"code.gitea.io/gitea/services/forms"
"gitea.com/go-chi/session"
@@ -368,11 +369,16 @@ func SubmitInstall(ctx *context.Context) {
}
// Save settings.
- cfg, err := setting.NewConfigProviderFromFile(&setting.Options{CustomConf: setting.CustomConf, AllowEmpty: true})
+ cfg, err := setting.NewConfigProviderFromFile(setting.CustomConf)
if err != nil {
log.Error("Failed to load custom conf '%s': %v", setting.CustomConf, err)
}
+ cfg.Section("").Key("APP_NAME").SetValue(form.AppName)
+ cfg.Section("").Key("RUN_USER").SetValue(form.RunUser)
+ cfg.Section("").Key("WORK_PATH").SetValue(setting.AppWorkPath)
+ cfg.Section("").Key("RUN_MODE").SetValue("prod")
+
cfg.Section("database").Key("DB_TYPE").SetValue(setting.Database.Type.String())
cfg.Section("database").Key("HOST").SetValue(setting.Database.Host)
cfg.Section("database").Key("NAME").SetValue(setting.Database.Name)
@@ -383,9 +389,7 @@ func SubmitInstall(ctx *context.Context) {
cfg.Section("database").Key("PATH").SetValue(setting.Database.Path)
cfg.Section("database").Key("LOG_SQL").SetValue("false") // LOG_SQL is rarely helpful
- cfg.Section("").Key("APP_NAME").SetValue(form.AppName)
cfg.Section("repository").Key("ROOT").SetValue(form.RepoRootPath)
- cfg.Section("").Key("RUN_USER").SetValue(form.RunUser)
cfg.Section("server").Key("SSH_DOMAIN").SetValue(form.Domain)
cfg.Section("server").Key("DOMAIN").SetValue(form.Domain)
cfg.Section("server").Key("HTTP_PORT").SetValue(form.HTTPPort)
@@ -447,8 +451,6 @@ func SubmitInstall(ctx *context.Context) {
cfg.Section("service").Key("NO_REPLY_ADDRESS").SetValue(fmt.Sprint(form.NoReplyAddress))
cfg.Section("cron.update_checker").Key("ENABLED").SetValue(fmt.Sprint(form.EnableUpdateChecker))
- cfg.Section("").Key("RUN_MODE").SetValue("prod")
-
cfg.Section("session").Key("PROVIDER").SetValue("file")
cfg.Section("log").Key("MODE").MustString("console")
@@ -511,7 +513,13 @@ func SubmitInstall(ctx *context.Context) {
// ---- All checks are passed
// Reload settings (and re-initialize database connection)
- reloadSettings(ctx)
+ setting.InitCfgProvider(setting.CustomConf)
+ setting.LoadCommonSettings()
+ setting.MustInstalled()
+ setting.LoadDBSetting()
+ if err := common.InitDBEngine(ctx); err != nil {
+ log.Fatal("ORM engine initialization failed: %v", err)
+ }
// Create admin account
if len(form.AdminName) > 0 {
diff --git a/routers/install/setting.go b/routers/install/setting.go
deleted file mode 100644
index c14843d8ee..0000000000
--- a/routers/install/setting.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2021 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package install
-
-import (
- "context"
-
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/svg"
- "code.gitea.io/gitea/modules/translation"
- "code.gitea.io/gitea/routers/common"
-)
-
-// PreloadSettings preloads the configuration to check if we need to run install
-func PreloadSettings(ctx context.Context) bool {
- setting.Init(&setting.Options{
- AllowEmpty: true,
- })
- if !setting.InstallLock {
- log.Info("AppPath: %s", setting.AppPath)
- log.Info("AppWorkPath: %s", setting.AppWorkPath)
- log.Info("Custom path: %s", setting.CustomPath)
- log.Info("Log path: %s", setting.Log.RootPath)
- log.Info("Configuration file: %s", setting.CustomConf)
- log.Info("Prepare to run install page")
- translation.InitLocales(ctx)
- if setting.EnableSQLite3 {
- log.Info("SQLite3 is supported")
- }
-
- setting.LoadSettingsForInstall()
- _ = svg.Init()
- }
-
- return !setting.InstallLock
-}
-
-// reloadSettings reloads the existing settings and starts up the database
-func reloadSettings(ctx context.Context) {
- setting.Init(&setting.Options{})
- setting.LoadDBSetting()
- if setting.InstallLock {
- if err := common.InitDBEngine(ctx); err == nil {
- log.Info("ORM engine initialization successful!")
- } else {
- log.Fatal("ORM engine initialization failed: %v", err)
- }
- }
-}
diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go
index be662c22ef..2c6989a71d 100644
--- a/routers/web/admin/config.go
+++ b/routers/web/admin/config.go
@@ -8,7 +8,6 @@ import (
"fmt"
"net/http"
"net/url"
- "os"
"strconv"
"strings"
@@ -167,20 +166,6 @@ func Config(ctx *context.Context) {
ctx.Data["SessionConfig"] = sessionCfg
ctx.Data["Git"] = setting.Git
-
- type envVar struct {
- Name, Value string
- }
-
- envVars := map[string]*envVar{}
- if len(os.Getenv("GITEA_WORK_DIR")) > 0 {
- envVars["GITEA_WORK_DIR"] = &envVar{"GITEA_WORK_DIR", os.Getenv("GITEA_WORK_DIR")}
- }
- if len(os.Getenv("GITEA_CUSTOM")) > 0 {
- envVars["GITEA_CUSTOM"] = &envVar{"GITEA_CUSTOM", os.Getenv("GITEA_CUSTOM")}
- }
-
- ctx.Data["EnvVars"] = envVars
ctx.Data["AccessLogTemplate"] = setting.Log.AccessLogTemplate
ctx.Data["LogSQL"] = setting.Database.LogSQL