kairos-agent/internal/agent/config.go
mudler 122d29cbac art: Expose interactive install to providers
In this way install can be driven from providers too

Part of: https://github.com/c3os-io/c3os/issues/68
2022-08-12 12:21:12 +02:00

65 lines
1.3 KiB
Go

package agent
import (
"io/ioutil"
"github.com/c3os-io/c3os/internal/c3os"
"gopkg.in/yaml.v2"
)
type BrandingText struct {
InteractiveInstall string `yaml:"install"`
Install string `yaml:"install"`
Reset string `yaml:"reset"`
Recovery string `yaml:"recovery"`
}
type Config struct {
Branding BrandingText `yaml:"branding"`
}
func LoadConfig(path ...string) (*Config, error) {
if len(path) == 0 {
path = append(path, "/etc/c3os/agent.yaml", "/etc/elemental/config.yaml")
}
cfg := &Config{}
for _, p := range path {
f, err := ioutil.ReadFile(p)
if err == nil {
yaml.Unmarshal(f, cfg) //nolint:errcheck
}
}
if cfg.Branding.InteractiveInstall == "" {
f, err := ioutil.ReadFile(c3os.BrandingFile("interactive_install_text"))
if err == nil {
cfg.Branding.InteractiveInstall = string(f)
}
}
if cfg.Branding.Install == "" {
f, err := ioutil.ReadFile(c3os.BrandingFile("install_text"))
if err == nil {
cfg.Branding.Install = string(f)
}
}
if cfg.Branding.Recovery == "" {
f, err := ioutil.ReadFile(c3os.BrandingFile("recovery_text"))
if err == nil {
cfg.Branding.Recovery = string(f)
}
}
if cfg.Branding.Reset == "" {
f, err := ioutil.ReadFile(c3os.BrandingFile("reset_text"))
if err == nil {
cfg.Branding.Recovery = string(f)
}
}
return cfg, nil
}