github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/util/distro/distrodetect.go (about) 1 package distro 2 3 import ( 4 "github.com/go-ini/ini" 5 ) 6 7 // FIXME: find something smaller than go-ini 8 func DistroDetect(sysroot string) (DistroInfo, error) { 9 // try os-release 10 cfg, err := ini.Load(sysroot + "/etc/os-release") 11 if err != nil { 12 return DistroInfo{}, err 13 } 14 15 sect := cfg.Section("") 16 inf := DistroInfo{ 17 Id: sect.Key("ID").String(), 18 IdLike: sect.Key("ID_LIKE").String(), 19 Name: sect.Key("NAME").String(), 20 Version: sect.Key("VERSION").String(), 21 VersionId: sect.Key("VERSION_ID").String(), 22 VersionCodename: sect.Key("VERSION_CODENAME").String(), 23 PrettyName: sect.Key("PRETTY_NAME").String(), 24 HomeUrl: sect.Key("HOME_URL").String(), 25 SupportUrl: sect.Key("SUPPORT_URL").String(), 26 BugReportUrl: sect.Key("BUG_REPORT_URL").String(), 27 } 28 29 if inf.IdLike == "" { 30 inf.IdLike = inf.Id 31 } 32 33 return inf, nil 34 }