|
|
@ -20,9 +20,7 @@ var ( |
|
|
|
// CmdAdmin represents the available admin sub-command.
|
|
|
|
// CmdAdmin represents the available admin sub-command.
|
|
|
|
CmdAdmin = cli.Command{ |
|
|
|
CmdAdmin = cli.Command{ |
|
|
|
Name: "admin", |
|
|
|
Name: "admin", |
|
|
|
Usage: "Perform admin operations on command line", |
|
|
|
Usage: "Command line interface to perform common administrative operations", |
|
|
|
Description: `Allow using internal logic of Gitea without hacking into the source code |
|
|
|
|
|
|
|
to make automatic initialization process more smoothly`, |
|
|
|
|
|
|
|
Subcommands: []cli.Command{ |
|
|
|
Subcommands: []cli.Command{ |
|
|
|
subcmdCreateUser, |
|
|
|
subcmdCreateUser, |
|
|
|
subcmdChangePassword, |
|
|
|
subcmdChangePassword, |
|
|
@ -37,17 +35,14 @@ to make automatic initialization process more smoothly`, |
|
|
|
Flags: []cli.Flag{ |
|
|
|
Flags: []cli.Flag{ |
|
|
|
cli.StringFlag{ |
|
|
|
cli.StringFlag{ |
|
|
|
Name: "name", |
|
|
|
Name: "name", |
|
|
|
Value: "", |
|
|
|
|
|
|
|
Usage: "Username", |
|
|
|
Usage: "Username", |
|
|
|
}, |
|
|
|
}, |
|
|
|
cli.StringFlag{ |
|
|
|
cli.StringFlag{ |
|
|
|
Name: "password", |
|
|
|
Name: "password", |
|
|
|
Value: "", |
|
|
|
|
|
|
|
Usage: "User password", |
|
|
|
Usage: "User password", |
|
|
|
}, |
|
|
|
}, |
|
|
|
cli.StringFlag{ |
|
|
|
cli.StringFlag{ |
|
|
|
Name: "email", |
|
|
|
Name: "email", |
|
|
|
Value: "", |
|
|
|
|
|
|
|
Usage: "User email address", |
|
|
|
Usage: "User email address", |
|
|
|
}, |
|
|
|
}, |
|
|
|
cli.BoolFlag{ |
|
|
|
cli.BoolFlag{ |
|
|
@ -88,56 +83,42 @@ to make automatic initialization process more smoothly`, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func runChangePassword(c *cli.Context) error { |
|
|
|
func runChangePassword(c *cli.Context) error { |
|
|
|
if !c.IsSet("password") { |
|
|
|
if err := argsSet(c, "username", "password"); err != nil { |
|
|
|
return fmt.Errorf("Password is not specified") |
|
|
|
return err |
|
|
|
} else if !c.IsSet("username") { |
|
|
|
|
|
|
|
return fmt.Errorf("Username is not specified") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setting.NewContext() |
|
|
|
if err := initDB(); err != nil { |
|
|
|
models.LoadConfigs() |
|
|
|
return err |
|
|
|
|
|
|
|
|
|
|
|
setting.NewXORMLogService(false) |
|
|
|
|
|
|
|
if err := models.SetEngine(); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("models.SetEngine: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uname := c.String("username") |
|
|
|
uname := c.String("username") |
|
|
|
user, err := models.GetUserByName(uname) |
|
|
|
user, err := models.GetUserByName(uname) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if user.Salt, err = models.GetUserSalt(); err != nil { |
|
|
|
if user.Salt, err = models.GetUserSalt(); err != nil { |
|
|
|
return fmt.Errorf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
user.HashPassword(c.String("password")) |
|
|
|
user.HashPassword(c.String("password")) |
|
|
|
if err := models.UpdateUserCols(user, "passwd", "salt"); err != nil { |
|
|
|
if err := models.UpdateUserCols(user, "passwd", "salt"); err != nil { |
|
|
|
return fmt.Errorf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("User '%s' password has been successfully updated!\n", uname) |
|
|
|
fmt.Printf("%s's password has been successfully updated!\n", user.Name) |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func runCreateUser(c *cli.Context) error { |
|
|
|
func runCreateUser(c *cli.Context) error { |
|
|
|
if !c.IsSet("name") { |
|
|
|
if err := argsSet(c, "name", "password", "email"); err != nil { |
|
|
|
return fmt.Errorf("Username is not specified") |
|
|
|
return err |
|
|
|
} else if !c.IsSet("password") { |
|
|
|
|
|
|
|
return fmt.Errorf("Password is not specified") |
|
|
|
|
|
|
|
} else if !c.IsSet("email") { |
|
|
|
|
|
|
|
return fmt.Errorf("Email is not specified") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if c.IsSet("config") { |
|
|
|
if c.IsSet("config") { |
|
|
|
setting.CustomConf = c.String("config") |
|
|
|
setting.CustomConf = c.String("config") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setting.NewContext() |
|
|
|
if err := initDB(); err != nil { |
|
|
|
models.LoadConfigs() |
|
|
|
return err |
|
|
|
|
|
|
|
|
|
|
|
setting.NewXORMLogService(false) |
|
|
|
|
|
|
|
if err := models.SetEngine(); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("models.SetEngine: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := models.CreateUser(&models.User{ |
|
|
|
if err := models.CreateUser(&models.User{ |
|
|
@ -155,13 +136,8 @@ func runCreateUser(c *cli.Context) error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func runRepoSyncReleases(c *cli.Context) error { |
|
|
|
func runRepoSyncReleases(c *cli.Context) error { |
|
|
|
|
|
|
|
if err := initDB(); err != nil { |
|
|
|
setting.NewContext() |
|
|
|
return err |
|
|
|
models.LoadConfigs() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setting.NewXORMLogService(false) |
|
|
|
|
|
|
|
if err := models.SetEngine(); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("models.SetEngine: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.Trace("Synchronizing repository releases (this may take a while)") |
|
|
|
log.Trace("Synchronizing repository releases (this may take a while)") |
|
|
@ -172,8 +148,7 @@ func runRepoSyncReleases(c *cli.Context) error { |
|
|
|
Private: true, |
|
|
|
Private: true, |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal(4, "SearchRepositoryByName: %v", err) |
|
|
|
return fmt.Errorf("SearchRepositoryByName: %v", err) |
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if len(repos) == 0 { |
|
|
|
if len(repos) == 0 { |
|
|
|
break |
|
|
|
break |
|
|
@ -187,11 +162,7 @@ func runRepoSyncReleases(c *cli.Context) error { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oldnum, err := models.GetReleaseCountByRepoID(repo.ID, |
|
|
|
oldnum, err := getReleaseCount(repo.ID) |
|
|
|
models.FindReleasesOptions{ |
|
|
|
|
|
|
|
IncludeDrafts: false, |
|
|
|
|
|
|
|
IncludeTags: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Warn(" GetReleaseCountByRepoID: %v", err) |
|
|
|
log.Warn(" GetReleaseCountByRepoID: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -202,11 +173,7 @@ func runRepoSyncReleases(c *cli.Context) error { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
count, err = models.GetReleaseCountByRepoID(repo.ID, |
|
|
|
count, err = getReleaseCount(repo.ID) |
|
|
|
models.FindReleasesOptions{ |
|
|
|
|
|
|
|
IncludeDrafts: false, |
|
|
|
|
|
|
|
IncludeTags: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Warn(" GetReleaseCountByRepoID: %v", err) |
|
|
|
log.Warn(" GetReleaseCountByRepoID: %v", err) |
|
|
|
continue |
|
|
|
continue |
|
|
@ -219,3 +186,12 @@ func runRepoSyncReleases(c *cli.Context) error { |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getReleaseCount(id int64) (int64, error) { |
|
|
|
|
|
|
|
return models.GetReleaseCountByRepoID( |
|
|
|
|
|
|
|
id, |
|
|
|
|
|
|
|
models.FindReleasesOptions{ |
|
|
|
|
|
|
|
IncludeTags: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|