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,
|
2024-04-02 00:24:06 +08:00
|
|
|
Run: python(func(cmd *cobra.Command, _ []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{
|
2024-01-30 17:14:50 +08:00
|
|
|
Key: generateKey(),
|
|
|
|
Signup: mustGetBool(flags, "signup"),
|
|
|
|
CreateUserDir: mustGetBool(flags, "create-user-dir"),
|
|
|
|
Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")),
|
|
|
|
AuthMethod: authMethod,
|
|
|
|
Defaults: defaults,
|
2019-01-06 06:44:33 +08:00
|
|
|
Branding: settings.Branding{
|
2023-02-16 06:30:48 +08:00
|
|
|
Name: mustGetString(flags, "branding.name"),
|
|
|
|
DisableExternal: mustGetBool(flags, "branding.disableExternal"),
|
2023-08-05 17:53:42 +08:00
|
|
|
DisableUsedPercentage: mustGetBool(flags, "branding.disableUsedPercentage"),
|
2023-12-28 16:52:40 +08:00
|
|
|
Theme: mustGetString(flags, "branding.theme"),
|
2023-02-16 06:30:48 +08:00
|
|
|
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
|
|
|
}
|