diff options
| author | Jeff Carr <[email protected]> | 2025-09-10 22:35:20 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-10 22:35:20 -0500 |
| commit | 43d653a8c040d68a4386d1fc1cc7cfa18ce34e83 (patch) | |
| tree | 775ffc06fc9536de221a36b6855fe391132f5f7d /config.go | |
| parent | 6722b019ec1271fd95a970f14e2e2aed4cdf6116 (diff) | |
add config file support
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/config.go b/config.go new file mode 100644 index 0000000..51d0110 --- /dev/null +++ b/config.go @@ -0,0 +1,49 @@ +package main + +// functions to import and export the protobuf +// data to and from config files + +import ( + "errors" + "os" + + "go.wit.com/lib/config" + "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/log" +) + +func configSave() error { + return config.ConfigSave(me.configs) +} + +func (me *mainType) configInit() error { + if argv.Hostname != "" { + HOSTNAME = argv.Hostname + } + + // the default forged dir is /home/forge + if os.Getenv("FORGE_GOSRC") == "" { + os.Setenv("FORGE_GOSRC", "/home/forge") + } + + if os.Getenv("FORGE_PATCHDIR") == "" { + os.Setenv("FORGE_PATCHDIR", "/var/lib/forged") + } + + me.configs = new(forgepb.ForgeConfigs) + err := config.ConfigLoad(me.configs, ARGNAME, "forge") + if errors.Is(err, os.ErrNotExist) { + me.configs.ReposDir = "/home/forge" + me.configs.ReposPB = "/home/forge/repos.pb" + me.configs.PatchDir = "/var/lib/forged" + if err := configSave(); err != nil { + badExit(err) + } + log.Info("made a default config file here", me.configs.Filename) + okExit("") + } + if err != nil { + badExit(err) + } + return err +} |
