DoConfig runs the interactive configuration process.
(app *App, configSections string)
| 647 | |
| 648 | // DoConfig runs the interactive configuration process. |
| 649 | func DoConfig(app *App, configSections string) { |
| 650 | if configSections == "" { |
| 651 | configSections = "server db app" |
| 652 | } |
| 653 | // let's check there aren't any garbage in the list |
| 654 | configSectionsArray := strings.Split(configSections, " ") |
| 655 | for _, element := range configSectionsArray { |
| 656 | if element != "server" && element != "db" && element != "app" { |
| 657 | log.Error("Invalid argument to --sections. Valid arguments are only \"server\", \"db\" and \"app\"") |
| 658 | os.Exit(1) |
| 659 | } |
| 660 | } |
| 661 | d, err := config.Configure(app.cfgFile, configSections) |
| 662 | if err != nil { |
| 663 | log.Error("Unable to configure: %v", err) |
| 664 | os.Exit(1) |
| 665 | } |
| 666 | app.cfg = d.Config |
| 667 | connectToDatabase(app) |
| 668 | defer shutdown(app) |
| 669 | |
| 670 | if !app.db.DatabaseInitialized() { |
| 671 | err = adminInitDatabase(app) |
| 672 | if err != nil { |
| 673 | log.Error(err.Error()) |
| 674 | os.Exit(1) |
| 675 | } |
| 676 | } else { |
| 677 | log.Info("Database already initialized.") |
| 678 | } |
| 679 | |
| 680 | if d.User != nil { |
| 681 | u := &User{ |
| 682 | Username: d.User.Username, |
| 683 | HashedPass: d.User.HashedPass, |
| 684 | Created: time.Now().Truncate(time.Second).UTC(), |
| 685 | } |
| 686 | |
| 687 | // Create blog |
| 688 | log.Info("Creating user %s...\n", u.Username) |
| 689 | err = app.db.CreateUser(app.cfg, u, app.cfg.App.SiteName, "") |
| 690 | if err != nil { |
| 691 | log.Error("Unable to create user: %s", err) |
| 692 | os.Exit(1) |
| 693 | } |
| 694 | log.Info("Done!") |
| 695 | } |
| 696 | os.Exit(0) |
| 697 | } |
| 698 | |
| 699 | // GenerateKeyFiles creates app encryption keys and saves them into the configured KeysParentDir. |
| 700 | func GenerateKeyFiles(app *App) error { |
no test coverage detected