2019-01-05 22:44:33 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2020-05-31 23:12:36 +00:00
|
|
|
|
2023-06-15 01:08:09 +00:00
|
|
|
"github.com/gtsteffaniak/filebrowser/settings"
|
2019-01-05 22:44:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
configCmd.AddCommand(configInitCmd)
|
2023-09-02 17:24:55 +00:00
|
|
|
addConfigFlags(configInitCmd.Flags())
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var configInitCmd = &cobra.Command{
|
|
|
|
Use: "init",
|
|
|
|
Short: "Initialize a new database",
|
|
|
|
Long: `Initialize a new database to use with File Browser. All of
|
|
|
|
this options can be changed in the future with the command
|
2019-01-08 16:37:02 +00:00
|
|
|
'filebrowser config set'. The user related flags apply
|
2019-01-05 22:44:33 +00:00
|
|
|
to the defaults when creating new users and you don't
|
|
|
|
override the options.`,
|
|
|
|
Args: cobra.NoArgs,
|
2019-01-07 20:24:23 +00:00
|
|
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
2023-09-02 18:02:50 +00:00
|
|
|
auther := getAuthentication()
|
|
|
|
s := settings.GlobalConfiguration
|
|
|
|
s.Key = generateKey()
|
|
|
|
err := d.store.Settings.Save(&s)
|
2019-01-05 22:44:33 +00:00
|
|
|
checkErr(err)
|
2023-09-02 18:02:50 +00:00
|
|
|
err = d.store.Settings.SaveServer(&s.Server)
|
2019-01-08 14:07:55 +00:00
|
|
|
checkErr(err)
|
2019-01-07 20:24:23 +00:00
|
|
|
err = d.store.Auth.Save(auther)
|
2019-01-05 22:44:33 +00:00
|
|
|
checkErr(err)
|
|
|
|
|
|
|
|
fmt.Printf(`
|
|
|
|
Congratulations! You've set up your database to use with File Browser.
|
2020-11-04 16:47:36 +00:00
|
|
|
Now add your first user via 'filebrowser users add' and then you just
|
2019-01-05 22:44:33 +00:00
|
|
|
need to call the main command to boot up the server.
|
|
|
|
`)
|
2023-09-02 18:02:50 +00:00
|
|
|
printSettings(&s.Server, &s, auther)
|
2019-01-07 20:24:23 +00:00
|
|
|
}, pythonConfig{noDB: true}),
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|