kairos-agent/internal/agent/config.go
Eng Zer Jun c868bbaf9e art: Move from io/ioutil to io and os packages (#470)
refactor: move from io/ioutil to io and os packages

The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-11-22 01:11:03 +08:00

68 lines
1.4 KiB
Go

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