50 lines
1017 B
Go
50 lines
1017 B
Go
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 me.configs.ConfigSave()
|
|
}
|
|
|
|
func configInit() *forgepb.ForgeConfigs {
|
|
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")
|
|
}
|
|
|
|
configs := new(forgepb.ForgeConfigs)
|
|
err := config.ConfigLoad(configs, ARGNAME, "forge")
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
configs.ReposDir = "/home/forge"
|
|
configs.ReposPB = "/home/forge/repos.pb"
|
|
configs.PatchDir = "/var/lib/forged"
|
|
if err := configSave(); err != nil {
|
|
badExit(err)
|
|
}
|
|
log.Info("made a default config file here", configs.Filename)
|
|
okExit("")
|
|
}
|
|
if err != nil {
|
|
badExit(err)
|
|
}
|
|
return configs
|
|
}
|