mirror of
https://github.com/rancher/os.git
synced 2025-09-18 08:06:48 +00:00
- Use burmilla GitHub repos - Release under burmilla Docker Hub - GitHub action for create releases - Updated boot image and login banner - Use Debian as default console - Updated system-cron to v0.5.0 - Updated services to latest versions - Bump up kernel to 4.14.206 - Include burmilla/os-debianconsole:v1.9.0 to initrd
98 lines
2.4 KiB
Go
98 lines
2.4 KiB
Go
package config
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"strings"
|
|
|
|
"github.com/burmilla/os/config/cmdline"
|
|
"github.com/burmilla/os/pkg/util"
|
|
yaml "github.com/cloudfoundry-incubator/candiedyaml"
|
|
)
|
|
|
|
const Banner = `
|
|
|||||| ||||||| |||||
|
|
| | | | ||||| | | | | | || | | | |
|
|
| | | | | | || || | | | | | | | |
|
|
|||||| | | | | | || | | | | | | | | |||||
|
|
| | | | ||||| | | | | | |||||| | | |
|
|
| | | | | | | | | | | | | | | | |
|
|
|||||| |||| | | | | | |||||| |||||| | | ||||||| |||||
|
|
|
|
BurmillaOS \v \n \l
|
|
`
|
|
|
|
func Merge(bytes []byte) error {
|
|
data, err := readConfigs(bytes, false, true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
existing, err := readConfigs(nil, false, true, CloudConfigFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return WriteToFile(util.Merge(existing, data), CloudConfigFile)
|
|
}
|
|
|
|
func Export(private, full bool) (string, error) {
|
|
rawCfg := loadRawConfig("", full)
|
|
rawCfg = filterAdditional(rawCfg)
|
|
if !private {
|
|
rawCfg = filterPrivateKeys(rawCfg)
|
|
}
|
|
|
|
bytes, err := yaml.Marshal(rawCfg)
|
|
return string(bytes), err
|
|
}
|
|
func filterPrivateKeys(data map[interface{}]interface{}) map[interface{}]interface{} {
|
|
for _, privateKey := range PrivateKeys {
|
|
_, data = filterKey(data, strings.Split(privateKey, "."))
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
func filterAdditional(data map[interface{}]interface{}) map[interface{}]interface{} {
|
|
for _, additional := range Additional {
|
|
_, data = filterKey(data, strings.Split(additional, "."))
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
func Get(key string) (interface{}, error) {
|
|
cfg := LoadConfig()
|
|
|
|
data := map[interface{}]interface{}{}
|
|
if err := util.ConvertIgnoreOmitEmpty(cfg, &data); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
v, _ := cmdline.GetOrSetVal(key, data, nil)
|
|
return v, nil
|
|
}
|
|
|
|
func Set(key string, value interface{}) error {
|
|
existing, err := readConfigs(nil, false, true, CloudConfigFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, modified := cmdline.GetOrSetVal(key, existing, value)
|
|
|
|
c := &CloudConfig{}
|
|
if err = util.Convert(modified, c); err != nil {
|
|
return err
|
|
}
|
|
|
|
return WriteToFile(modified, CloudConfigFile)
|
|
}
|
|
|
|
func GetKernelVersion() string {
|
|
b, err := ioutil.ReadFile("/proc/version")
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
elem := strings.Split(string(b), " ")
|
|
return elem[2]
|
|
}
|