Create syncthing.ini template (fixes #39)

This commit is contained in:
Jakob Borg 2014-01-22 14:28:14 +01:00
parent 1dde9ec2d8
commit 20a47695fb

43
main.go
View File

@ -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.