diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/cert_stub.go | 9 | ||||
-rw-r--r-- | cmd/dump.go | 4 | ||||
-rw-r--r-- | cmd/fix.go | 184 | ||||
-rw-r--r-- | cmd/serve.go | 12 | ||||
-rw-r--r-- | cmd/update.go | 8 | ||||
-rw-r--r-- | cmd/web.go | 8 |
6 files changed, 27 insertions, 198 deletions
diff --git a/cmd/cert_stub.go b/cmd/cert_stub.go index 69c9821e..1b68ca83 100644 --- a/cmd/cert_stub.go +++ b/cmd/cert_stub.go @@ -9,7 +9,6 @@ package cmd import ( "fmt" "os" - "time" "github.com/codegangsta/cli" ) @@ -20,14 +19,6 @@ var CmdCert = cli.Command{ Description: `Generate a self-signed X.509 certificate for a TLS server. Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`, Action: runCert, - Flags: []cli.Flag{ - cli.StringFlag{"host", "", "Comma-separated hostnames and IPs to generate a certificate for", ""}, - cli.StringFlag{"ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521", ""}, - cli.IntFlag{"rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set", ""}, - cli.StringFlag{"start-date", "", "Creation date formatted as Jan 1 15:04:05 2011", ""}, - cli.DurationFlag{"duration", 365 * 24 * time.Hour, "Duration that certificate is valid for", ""}, - cli.BoolFlag{"ca", "whether this cert should be its own Certificate Authority", ""}, - }, } func runCert(ctx *cli.Context) { diff --git a/cmd/dump.go b/cmd/dump.go index 3e1ccdb8..36bb4f03 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -25,11 +25,15 @@ var CmdDump = cli.Command{ It can be used for backup and capture Gogs server image to send to maintainer`, Action: runDump, Flags: []cli.Flag{ + cli.StringFlag{"config, c", "custom/conf/app.ini", "Custom configuration file path", ""}, cli.BoolFlag{"verbose, v", "show process details", ""}, }, } func runDump(ctx *cli.Context) { + if ctx.IsSet("config") { + setting.CustomConf = ctx.String("config") + } setting.NewConfigContext() models.LoadModelsConfig() models.SetEngine() diff --git a/cmd/fix.go b/cmd/fix.go deleted file mode 100644 index eff85d62..00000000 --- a/cmd/fix.go +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "bufio" - "fmt" - "io" - "io/ioutil" - "os" - "path" - "runtime" - "strings" - - "github.com/Unknwon/com" - "github.com/codegangsta/cli" - - "github.com/gogits/gogs/models" - "github.com/gogits/gogs/modules/setting" -) - -var CmdFix = cli.Command{ - Name: "fix", - Usage: "This command for upgrade from old version", - Action: runFix, - Subcommands: fixCommands, - Flags: []cli.Flag{}, -} - -func runFix(ctx *cli.Context) { -} - -var fixCommands = []cli.Command{ - { - Name: "location", - Usage: "Change Gogs app location", - Description: `Command location fixes location change of Gogs - -gogs fix location <old Gogs path> -`, - Action: runFixLocation, - }, -} - -// rewriteAuthorizedKeys replaces old Gogs path to the new one. -func rewriteAuthorizedKeys(sshPath, oldPath, newPath string) error { - fr, err := os.Open(sshPath) - if err != nil { - return err - } - defer fr.Close() - - tmpPath := sshPath + ".tmp" - fw, err := os.Create(tmpPath) - if err != nil { - return err - } - defer fw.Close() - - oldPath = "command=\"" + oldPath + " serv" - newPath = "command=\"" + newPath + " serv" - buf := bufio.NewReader(fr) - for { - line, errRead := buf.ReadString('\n') - line = strings.TrimSpace(line) - - if errRead != nil { - if errRead != io.EOF { - return errRead - } - - // Reached end of file, if nothing to read then break, - // otherwise handle the last line. - if len(line) == 0 { - break - } - } - - // Still finding the line, copy the line that currently read. - if _, err = fw.WriteString(strings.Replace(line, oldPath, newPath, 1) + "\n"); err != nil { - return err - } - - if errRead == io.EOF { - break - } - } - - if err = os.Remove(sshPath); err != nil { - return err - } - return os.Rename(tmpPath, sshPath) -} - -func rewriteUpdateHook(path, appPath string) error { - if runtime.GOOS == "windows" { - rp := strings.NewReplacer("\\", "/") - appPath = "\"" + rp.Replace(appPath) + "\"" - } else { - rp := strings.NewReplacer("\\", "/", " ", "\\ ") - appPath = rp.Replace(appPath) - } - - if err := ioutil.WriteFile(path, []byte(fmt.Sprintf(models.TPL_UPDATE_HOOK, - setting.ScriptType, appPath)), os.ModePerm); err != nil { - return err - } - return nil -} - -func walkDir(rootPath, recPath, appPath string, depth int) error { - depth++ - if depth > 3 { - return nil - } else if depth == 3 { - if err := rewriteUpdateHook(path.Join(rootPath, "hooks/update"), appPath); err != nil { - return err - } - } - - dir, err := os.Open(rootPath) - if err != nil { - return err - } - defer dir.Close() - - fis, err := dir.Readdir(0) - if err != nil { - return err - } - - for _, fi := range fis { - if strings.Contains(fi.Name(), ".DS_Store") { - continue - } - - relPath := path.Join(recPath, fi.Name()) - curPath := path.Join(rootPath, fi.Name()) - if fi.IsDir() { - if err = walkDir(curPath, relPath, appPath, depth); err != nil { - return err - } - } - } - return nil -} - -func runFixLocation(ctx *cli.Context) { - if len(ctx.Args()) != 1 { - fmt.Println("Incorrect arguments number, expect 1") - os.Exit(2) - } - - execPath, _ := setting.ExecPath() - - oldPath := ctx.Args().First() - fmt.Printf("Old location: %s\n", oldPath) - fmt.Println("This command should be executed in the new Gogs path") - fmt.Printf("Do you want to change Gogs app path from old location to:\n") - fmt.Printf("-> %s?\n", execPath) - fmt.Print("Press <enter> to continue, use <Ctrl+c> to exit.") - fmt.Scanln() - - // Fix in authorized_keys file. - sshPath := path.Join(models.SSHPath, "authorized_keys") - if com.IsFile(sshPath) { - fmt.Printf("Fixing pathes in file: %s\n", sshPath) - if err := rewriteAuthorizedKeys(sshPath, oldPath, execPath); err != nil { - fmt.Println(err) - os.Exit(1) - } - } - - // Fix position in gogs-repositories. - setting.NewConfigContext() - fmt.Printf("Fixing pathes in repositories: %s\n", setting.RepoRootPath) - if err := walkDir(setting.RepoRootPath, "", execPath, 0); err != nil { - fmt.Println(err) - os.Exit(1) - } - fmt.Println("Fix position finished!") -} diff --git a/cmd/serve.go b/cmd/serve.go index 1f5d944d..25f7dd91 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -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", "Custom configuration file path", ""}, + }, } func setup(logPath string) { @@ -83,9 +85,15 @@ 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], "-") + if len(k.Args()) < 1 { + log.GitLogger.Fatal(2, "Not enough arguments") + } + keys := strings.Split(k.Args()[0], "-") if len(keys) != 2 { println("Gogs: auth file format error") log.GitLogger.Fatal(2, "Invalid auth file format: %s", os.Args[2]) diff --git a/cmd/update.go b/cmd/update.go index cc55693e..c9eaeccf 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -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", "Custom configuration file path", ""}, + }, } func runUpdate(c *cli.Context) { + if c.IsSet("config") { + setting.CustomConf = c.String("config") + } cmd := os.Getenv("SSH_ORIGINAL_COMMAND") if cmd == "" { return @@ -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", "Custom configuration file path", ""}, }, } @@ -78,7 +79,7 @@ func checkVersion() { // Check dependency version. checkers := []VerChecker{ {"github.com/Unknwon/macaron", macaron.Version, "0.5.1"}, - {"github.com/macaron-contrib/binding", binding.Version, "0.0.4"}, + {"github.com/macaron-contrib/binding", binding.Version, "0.0.5"}, {"github.com/macaron-contrib/cache", cache.Version, "0.0.7"}, {"github.com/macaron-contrib/csrf", csrf.Version, "0.0.3"}, {"github.com/macaron-contrib/i18n", i18n.Version, "0.0.5"}, @@ -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() @@ -225,7 +229,7 @@ func runWeb(ctx *cli.Context) { }) m.Any("/*", func(ctx *middleware.Context) { - ctx.JSON(404, &base.ApiJsonErr{"Not Found", base.DOC_URL}) + ctx.HandleAPI(404, "Page not found") }) }) }) |