2019-01-05 22:44:33 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2020-05-31 23:12:36 +00:00
|
|
|
|
|
|
|
"github.com/filebrowser/filebrowser/v2/settings"
|
2019-01-05 22:44:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
configCmd.AddCommand(configInitCmd)
|
2019-01-08 10:50:37 +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,
|
2024-04-01 16:24:06 +00:00
|
|
|
Run: python(func(cmd *cobra.Command, _ []string, d pythonData) {
|
2019-01-05 22:44:33 +00:00
|
|
|
defaults := settings.UserDefaults{}
|
2019-01-08 14:07:55 +00:00
|
|
|
flags := cmd.Flags()
|
|
|
|
getUserDefaults(flags, &defaults, true)
|
|
|
|
authMethod, auther := getAuthentication(flags)
|
2019-01-05 22:44:33 +00:00
|
|
|
|
|
|
|
s := &settings.Settings{
|
2024-01-30 09:14:50 +00:00
|
|
|
Key: generateKey(),
|
|
|
|
Signup: mustGetBool(flags, "signup"),
|
|
|
|
CreateUserDir: mustGetBool(flags, "create-user-dir"),
|
|
|
|
Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")),
|
|
|
|
AuthMethod: authMethod,
|
|
|
|
Defaults: defaults,
|
2019-01-05 22:44:33 +00:00
|
|
|
Branding: settings.Branding{
|
2023-02-15 22:30:48 +00:00
|
|
|
Name: mustGetString(flags, "branding.name"),
|
|
|
|
DisableExternal: mustGetBool(flags, "branding.disableExternal"),
|
2023-08-05 09:53:42 +00:00
|
|
|
DisableUsedPercentage: mustGetBool(flags, "branding.disableUsedPercentage"),
|
2023-12-28 08:52:40 +00:00
|
|
|
Theme: mustGetString(flags, "branding.theme"),
|
2023-02-15 22:30:48 +00:00
|
|
|
Files: mustGetString(flags, "branding.files"),
|
2019-01-05 22:44:33 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-01-08 14:07:55 +00:00
|
|
|
ser := &settings.Server{
|
|
|
|
Address: mustGetString(flags, "address"),
|
2019-05-17 10:48:06 +00:00
|
|
|
Socket: mustGetString(flags, "socket"),
|
2019-01-08 14:07:55 +00: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-07 20:24:23 +00:00
|
|
|
err := d.store.Settings.Save(s)
|
2019-01-05 22:44:33 +00:00
|
|
|
checkErr(err)
|
2019-01-08 14:07:55 +00:00
|
|
|
err = d.store.Settings.SaveServer(ser)
|
|
|
|
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.
|
|
|
|
`)
|
2019-01-08 14:07:55 +00:00
|
|
|
printSettings(ser, s, auther)
|
2019-01-07 20:24:23 +00:00
|
|
|
}, pythonConfig{noDB: true}),
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|