]> source.dussan.org Git - gitea.git/commitdiff
Add option to provide configuration file on command line
authorPeter Smit <peter@smitmail.eu>
Thu, 5 Feb 2015 10:12:37 +0000 (12:12 +0200)
committerPeter Smit <peter@smitmail.eu>
Thu, 5 Feb 2015 10:17:35 +0000 (12:17 +0200)
cmd/dump.go
cmd/serve.go
cmd/update.go
cmd/web.go
models/publickey.go
models/repo.go
modules/setting/setting.go
routers/install.go

index 3e1ccdb8a3b2761571f1819dde4167bb1558630f..57f1113ea30af687c838653df456387fb0800b57 100644 (file)
@@ -26,10 +26,14 @@ It can be used for backup and capture Gogs server image to send to maintainer`,
        Action: runDump,
        Flags: []cli.Flag{
                cli.BoolFlag{"verbose, v", "show process details", ""},
+               cli.StringFlag{"config, c", "custom/conf/app.ini", "Configuration file", ""},
        },
 }
 
 func runDump(ctx *cli.Context) {
+       if ctx.IsSet("config") {
+               setting.CustomConf = ctx.String("config")
+       }
        setting.NewConfigContext()
        models.LoadModelsConfig()
        models.SetEngine()
index 239096234202ef6c9dc4027a27208e17e63c67f6..7b593f40adf11396422f06b46b6fff23e025e774 100644 (file)
@@ -27,7 +27,9 @@ var CmdServ = cli.Command{
        Usage:       "This command should only be called by SSH shell",
        Description: `Serv provide access auth for repositories`,
        Action:      runServ,
-       Flags:       []cli.Flag{},
+       Flags: []cli.Flag{
+               cli.StringFlag{"config, c", "custom/conf/app.ini", "Configuration file", ""},
+       },
 }
 
 func setup(logPath string) {
@@ -77,6 +79,9 @@ func In(b string, sl map[string]models.AccessType) bool {
 }
 
 func runServ(k *cli.Context) {
+       if k.IsSet("config") {
+               setting.CustomConf = k.String("config")
+       }
        setup("serv.log")
 
        keys := strings.Split(os.Args[2], "-")
index cc55693e2b560471ed0eccca71040cb72701f8ec..2ea7e942ddfd881a2502c7bb98243a79dcc5521d 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "github.com/gogits/gogs/models"
        "github.com/gogits/gogs/modules/log"
+       "github.com/gogits/gogs/modules/setting"
 )
 
 var CmdUpdate = cli.Command{
@@ -18,10 +19,15 @@ var CmdUpdate = cli.Command{
        Usage:       "This command should only be called by SSH shell",
        Description: `Update get pushed info and insert into database`,
        Action:      runUpdate,
-       Flags:       []cli.Flag{},
+       Flags: []cli.Flag{
+               cli.StringFlag{"config, c", "custom/conf/app.ini", "Configuration file", ""},
+       },
 }
 
 func runUpdate(c *cli.Context) {
+       if c.IsSet("config") {
+               setting.CustomConf = c.String("config")
+       }
        cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
        if cmd == "" {
                return
index 55b6bf0874f2fb581c65154fa02b1b68f6e25675..ceb2134447c4eab6531fc14364ab5ed4cc684dfb 100644 (file)
@@ -55,6 +55,7 @@ and it takes care of all the other things for you`,
        Action: runWeb,
        Flags: []cli.Flag{
                cli.StringFlag{"port, p", "3000", "Temporary port number to prevent conflict", ""},
+               cli.StringFlag{"config, c", "custom/conf/app.ini", "Configuration file", ""},
        },
 }
 
@@ -165,6 +166,9 @@ func newMacaron() *macaron.Macaron {
 }
 
 func runWeb(ctx *cli.Context) {
+       if ctx.IsSet("config") {
+               setting.CustomConf = ctx.String("config")
+       }
        routers.GlobalInit()
        checkVersion()
 
index 67ab4242f2c3bff27f8c38db041a3314790423be..893ff5c96ad02f8c5cfe2d8a56a1556ba309b3a8 100644 (file)
@@ -29,7 +29,7 @@ import (
 
 const (
        // "### autogenerated by gitgos, DO NOT EDIT\n"
-       _TPL_PUBLICK_KEY = `command="%s serv key-%d",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s` + "\n"
+       _TPL_PUBLICK_KEY = `command="%s serv --config=%s key-%d",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s` + "\n"
 )
 
 var (
@@ -98,7 +98,7 @@ func (k *PublicKey) OmitEmail() string {
 
 // GetAuthorizedString generates and returns formatted public key string for authorized_keys file.
 func (key *PublicKey) GetAuthorizedString() string {
-       return fmt.Sprintf(_TPL_PUBLICK_KEY, appPath, key.Id, key.Content)
+       return fmt.Sprintf(_TPL_PUBLICK_KEY, appPath, setting.CustomConf, key.Id, key.Content)
 }
 
 var (
index b74582175330b0990359c7c166569446cd79f40c..edd156133b690032f28d242c3d92b621bccbf788 100644 (file)
@@ -30,7 +30,7 @@ import (
 )
 
 const (
-       TPL_UPDATE_HOOK = "#!/usr/bin/env %s\n%s update $1 $2 $3\n"
+       TPL_UPDATE_HOOK = "#!/usr/bin/env %s\n%s update --config=%s $1 $2 $3\n"
 )
 
 var (
@@ -424,7 +424,7 @@ func initRepository(f string, u *User, repo *Repository, initReadme bool, repoLa
 
        // hook/post-update
        if err := createHookUpdate(filepath.Join(repoPath, "hooks", "update"),
-               fmt.Sprintf(TPL_UPDATE_HOOK, setting.ScriptType, "\""+appPath+"\"")); err != nil {
+               fmt.Sprintf(TPL_UPDATE_HOOK, setting.ScriptType, "\""+appPath+"\"", setting.CustomConf)); err != nil {
                return err
        }
 
index e7c44cdd4fce39c85b208508bd0203acfd6bdcbe..79aaf7a064878c2fb07026d313a8e9d8ffd985df 100644 (file)
@@ -124,6 +124,7 @@ var (
        Cfg          *ini.File
        ConfRootPath string
        CustomPath   string // Custom directory path.
+       CustomConf   string
        ProdMode     bool
        RunUser      string
        IsWindows    bool
@@ -172,13 +173,16 @@ func NewConfigContext() {
                CustomPath = path.Join(workDir, "custom")
        }
 
-       cfgPath := path.Join(CustomPath, "conf/app.ini")
-       if com.IsFile(cfgPath) {
-               if err = Cfg.Append(cfgPath); err != nil {
-                       log.Fatal(4, "Fail to load custom 'conf/app.ini': %v", err)
+       if len(CustomConf) == 0 {
+               CustomConf = path.Join(CustomPath, "conf/app.ini")
+       }
+
+       if com.IsFile(CustomConf) {
+               if err = Cfg.Append(CustomConf); err != nil {
+                       log.Fatal(4, "Fail to load custom conf '%s': %v", CustomConf, err)
                }
        } else {
-               log.Warn("No custom 'conf/app.ini' found, ignore this if you're running first time")
+               log.Warn("Custom config (%s) not found, ignore this if you're running first time", CustomConf)
        }
        Cfg.NameMapper = ini.AllCapsUnderscore
 
index 9c3f134d45389599d650691095ac5a3d34eeb8ec..a3583a1a98eba6fe400d1a3b6fb66e4c28bf398b 100644 (file)
@@ -9,6 +9,7 @@ import (
        "os"
        "os/exec"
        "path"
+       "path/filepath"
        "strings"
 
        "github.com/Unknwon/com"
@@ -221,8 +222,8 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
        cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
        cfg.Section("security").Key("SECRET_KEY").SetValue(base.GetRandomString(15))
 
-       os.MkdirAll("custom/conf", os.ModePerm)
-       if err := cfg.SaveTo(path.Join(setting.CustomPath, "conf/app.ini")); err != nil {
+       os.MkdirAll(filepath.Dir(setting.CustomConf), os.ModePerm)
+       if err := cfg.SaveTo(setting.CustomConf); err != nil {
                ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
                return
        }