From 81057ee6859dbf0757035d507f313fb7aa30188d Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Thu, 2 Nov 2023 14:10:04 +0100 Subject: [PATCH] add option -initonly to "mox localserve", to only create config files and then quit for issue #89 by naturalethic --- doc.go | 2 ++ localserve.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/doc.go b/doc.go index 4797ca2..ec1e971 100644 --- a/doc.go +++ b/doc.go @@ -346,6 +346,8 @@ during those commands instead of during "data". usage: mox localserve -dir string configuration storage directory (default "$userconfigdir/mox-localserve") + -initonly + write configuration files and exit -ip string serve on this ip instead of default 127.0.0.1 and ::1. only used when writing configuration, at first launch. diff --git a/localserve.go b/localserve.go index 65d052b..52cd661 100644 --- a/localserve.go +++ b/localserve.go @@ -66,8 +66,10 @@ during those commands instead of during "data". } var dir, ip string + var initOnly bool c.flag.StringVar(&dir, "dir", filepath.Join(userConfDir, "mox-localserve"), "configuration storage directory") c.flag.StringVar(&ip, "ip", "", "serve on this ip instead of default 127.0.0.1 and ::1. only used when writing configuration, at first launch.") + c.flag.BoolVar(&initOnly, "initonly", false, "write configuration files and exit") args := c.Parse() if len(args) != 0 { c.Usage() @@ -77,6 +79,18 @@ during those commands instead of during "data". mox.FilesImmediate = true + if initOnly { + if _, err := os.Stat(dir); err == nil { + log.Print("warning: directory for configuration files already exists, continuing") + } + log.Print("creating mox localserve config", mlog.Field("dir", dir)) + err := writeLocalConfig(log, dir, ip) + if err != nil { + log.Fatalx("creating mox localserve config", err, mlog.Field("dir", dir)) + } + return + } + // Load config, creating a new one if needed. var existingConfig bool if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {