2019-01-06 06:44:33 +08:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2020-06-01 07:12:36 +08:00
|
|
|
|
|
|
|
"github.com/filebrowser/filebrowser/v2/settings"
|
2019-01-06 06:44:33 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
configCmd.AddCommand(configInitCmd)
|
2019-01-08 18:50:37 +08:00
|
|
|
addConfigFlags(configInitCmd.Flags())
|
2019-01-06 06:44:33 +08: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-09 00:37:02 +08:00
|
|
|
'filebrowser config set'. The user related flags apply
|
2019-01-06 06:44:33 +08:00
|
|
|
to the defaults when creating new users and you don't
|
|
|
|
override the options.`,
|
|
|
|
Args: cobra.NoArgs,
|
2019-01-08 04:24:23 +08:00
|
|
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
2019-01-06 06:44:33 +08:00
|
|
|
defaults := settings.UserDefaults{}
|
2019-01-08 22:07:55 +08:00
|
|
|
flags := cmd.Flags()
|
|
|
|
getUserDefaults(flags, &defaults, true)
|
|
|
|
authMethod, auther := getAuthentication(flags)
|
2019-01-06 06:44:33 +08:00
|
|
|
|
|
|
|
s := &settings.Settings{
|
2019-01-12 04:25:39 +08:00
|
|
|
Key: generateKey(),
|
2019-01-08 22:07:55 +08:00
|
|
|
Signup: mustGetBool(flags, "signup"),
|
2020-10-05 15:52:27 +08:00
|
|
|
Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")),
|
2019-01-06 06:44:33 +08:00
|
|
|
AuthMethod: authMethod,
|
|
|
|
Defaults: defaults,
|
|
|
|
Branding: settings.Branding{
|
2019-01-08 22:07:55 +08:00
|
|
|
Name: mustGetString(flags, "branding.name"),
|
|
|
|
DisableExternal: mustGetBool(flags, "branding.disableExternal"),
|
|
|
|
Files: mustGetString(flags, "branding.files"),
|
2019-01-06 06:44:33 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-01-08 22:07:55 +08:00
|
|
|
ser := &settings.Server{
|
|
|
|
Address: mustGetString(flags, "address"),
|
2019-05-17 18:48:06 +08:00
|
|
|
Socket: mustGetString(flags, "socket"),
|
2019-01-08 22:07:55 +08:00
|
|
|
Root: mustGetString(flags, "root"),
|
|
|
|
BaseURL: mustGetString(flags, "baseurl"),
|
|
|
|
TLSKey: mustGetString(flags, "key"),
|
|
|
|
TLSCert: mustGetString(flags, "cert"),
|
|
|
|
Port: mustGetString(flags, "port"),
|
|
|
|
Log: mustGetString(flags, "log"),
|
|
|
|
}
|
|
|
|
|
2019-01-08 04:24:23 +08:00
|
|
|
err := d.store.Settings.Save(s)
|
2019-01-06 06:44:33 +08:00
|
|
|
checkErr(err)
|
2019-01-08 22:07:55 +08:00
|
|
|
err = d.store.Settings.SaveServer(ser)
|
|
|
|
checkErr(err)
|
2019-01-08 04:24:23 +08:00
|
|
|
err = d.store.Auth.Save(auther)
|
2019-01-06 06:44:33 +08:00
|
|
|
checkErr(err)
|
|
|
|
|
|
|
|
fmt.Printf(`
|
|
|
|
Congratulations! You've set up your database to use with File Browser.
|
2020-11-05 00:47:36 +08:00
|
|
|
Now add your first user via 'filebrowser users add' and then you just
|
2019-01-06 06:44:33 +08:00
|
|
|
need to call the main command to boot up the server.
|
|
|
|
`)
|
2019-01-08 22:07:55 +08:00
|
|
|
printSettings(ser, s, auther)
|
2019-01-08 04:24:23 +08:00
|
|
|
}, pythonConfig{noDB: true}),
|
2019-01-06 06:44:33 +08:00
|
|
|
}
|