summaryrefslogtreecommitdiff
path: root/config.go
blob: 51d01101a310377e1dbb060649eb3429a508c53b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
}