templatefile/pkg/utils/os.go

28 lines
553 B
Go

package utils
import (
"fmt"
ini "gopkg.in/ini.v1"
)
var osReleaseFile = "/etc/os-release"
func ReadOSRelease() (map[string]string, error) {
cfg, err := ini.Load(osReleaseFile)
if err != nil {
return nil, fmt.Errorf("Fail to read file: %v ", err)
}
ConfigParams := make(map[string]string)
ConfigParams["ID"] = cfg.Section("").Key("ID").String()
idLike := cfg.Section("").Key("ID_LIKE").String()
if idLike != "" {
ConfigParams["ID_LIKE"] = idLike
} else {
ConfigParams["ID_LIKE"] = ConfigParams["ID"]
}
return ConfigParams, nil
}