From 20a47695fb8a936835a63d0605b7defe20f67652 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 22 Jan 2014 14:28:14 +0100 Subject: [PATCH] Create syncthing.ini template (fixes #39) --- main.go | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 3d8b29232..24978eb88 100644 --- a/main.go +++ b/main.go @@ -124,6 +124,37 @@ func main() { log.SetPrefix("[" + myID[0:5] + "] ") logger.SetPrefix("[" + myID[0:5] + "] ") + // Load the configuration file, if it exists. + // If it does not, create a template. + + cfgFile := path.Join(opts.ConfDir, confFileName) + cf, err := os.Open(cfgFile) + + if err != nil { + infoln("No config file; creating a template") + config = ini.Config{} + config.AddComment("repository", "Set the following to the directory you wish to synchronize") + config.AddComment("repository", "dir = ~/Syncthing") + config.Set("nodes", myID, "auto") + config.AddComment("nodes", "Add peer nodes here") + fd, err := os.Create(cfgFile) + if err != nil { + fatalln(err) + } + config.Write(fd) + fd.Close() + infof("Edit %s to suit and restart syncthing.", cfgFile) + os.Exit(0) + } + + config = ini.Parse(cf) + cf.Close() + + var dir = expandTilde(config.Get("repository", "dir")) + if len(dir) == 0 { + fatalln("No repository directory. Set dir under [repository] in syncthing.ini.") + } + if opts.Debug.Profiler != "" { go func() { err := http.ListenAndServe(opts.Debug.Profiler, nil) @@ -146,18 +177,6 @@ func main() { MinVersion: tls.VersionTLS12, } - // Load the configuration file, if it exists. - - cf, err := os.Open(path.Join(opts.ConfDir, confFileName)) - if err != nil { - fatalln("No config file") - config = ini.Config{} - } - config = ini.Parse(cf) - cf.Close() - - var dir = expandTilde(config.Get("repository", "dir")) - // Create a map of desired node connections based on the configuration file // directives.