mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-17 01:19:29 +08:00
drop lsb_release
Signed-off-by: Chronophylos <nikolai@chronophylos.com>
This commit is contained in:
parent
e38d6e7ef0
commit
9de2f66f50
68
cmd/linux.go
68
cmd/linux.go
@ -44,52 +44,11 @@ type DistroInfo struct {
|
|||||||
// GetLinuxDistroInfo returns information about the running linux distribution
|
// GetLinuxDistroInfo returns information about the running linux distribution
|
||||||
func GetLinuxDistroInfo() *DistroInfo {
|
func GetLinuxDistroInfo() *DistroInfo {
|
||||||
result := &DistroInfo{Distribution: Unknown}
|
result := &DistroInfo{Distribution: Unknown}
|
||||||
program := NewProgramHelper()
|
|
||||||
// Does lsb_release exist?
|
|
||||||
|
|
||||||
lsbRelease := program.FindProgram("lsb_release")
|
_, err := os.Stat("/etc/os-release")
|
||||||
if lsbRelease != nil {
|
if !os.IsNotExist(err) {
|
||||||
stdout, _, _, err := lsbRelease.Run("-a")
|
|
||||||
if err != nil {
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
result.DiscoveredBy = "lsb"
|
|
||||||
for _, line := range strings.Split(stdout, "\n") {
|
|
||||||
if strings.Contains(line, ":") {
|
|
||||||
// Iterate lines a
|
|
||||||
details := strings.Split(line, ":")
|
|
||||||
key := strings.TrimSpace(details[0])
|
|
||||||
value := strings.TrimSpace(details[1])
|
|
||||||
switch key {
|
|
||||||
case "Distributor ID":
|
|
||||||
result.DistributorID = value
|
|
||||||
switch value {
|
|
||||||
case "Ubuntu":
|
|
||||||
result.Distribution = Ubuntu
|
|
||||||
case "Arch", "ManjaroLinux":
|
|
||||||
result.Distribution = Arch
|
|
||||||
case "Debian":
|
|
||||||
result.Distribution = Debian
|
|
||||||
case "Gentoo":
|
|
||||||
result.Distribution = Gentoo
|
|
||||||
case "Zorin":
|
|
||||||
result.Distribution = Zorin
|
|
||||||
case "Fedora":
|
|
||||||
result.Distribution = RedHat
|
|
||||||
}
|
|
||||||
case "Description":
|
|
||||||
result.Description = value
|
|
||||||
case "Release":
|
|
||||||
result.Release = value
|
|
||||||
case "Codename":
|
|
||||||
result.Codename = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check if /etc/os-release exists
|
|
||||||
} else if _, err := os.Stat("/etc/os-release"); !os.IsNotExist(err) {
|
|
||||||
// Default value
|
// Default value
|
||||||
osName := "Unknown"
|
osID := "unknown"
|
||||||
version := ""
|
version := ""
|
||||||
// read /etc/os-release
|
// read /etc/os-release
|
||||||
osRelease, _ := ioutil.ReadFile("/etc/os-release")
|
osRelease, _ := ioutil.ReadFile("/etc/os-release")
|
||||||
@ -104,8 +63,8 @@ func GetLinuxDistroInfo() *DistroInfo {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch splitLine[0] {
|
switch splitLine[0] {
|
||||||
case "NAME":
|
case "ID":
|
||||||
osName = strings.Trim(splitLine[1], "\"")
|
osID = strings.Trim(splitLine[1], "\"")
|
||||||
case "VERSION_ID":
|
case "VERSION_ID":
|
||||||
version = strings.Trim(splitLine[1], "\"")
|
version = strings.Trim(splitLine[1], "\"")
|
||||||
}
|
}
|
||||||
@ -114,21 +73,22 @@ func GetLinuxDistroInfo() *DistroInfo {
|
|||||||
// Check distro name against list of distros
|
// Check distro name against list of distros
|
||||||
result.Release = version
|
result.Release = version
|
||||||
result.DiscoveredBy = "os-release"
|
result.DiscoveredBy = "os-release"
|
||||||
switch osName {
|
switch osID {
|
||||||
case "Fedora":
|
case "fedora":
|
||||||
result.Distribution = RedHat
|
result.Distribution = RedHat
|
||||||
case "CentOS":
|
case "arch":
|
||||||
result.Distribution = RedHat
|
|
||||||
case "Arch Linux":
|
|
||||||
result.Distribution = Arch
|
result.Distribution = Arch
|
||||||
case "Debian GNU/Linux":
|
case "debian":
|
||||||
result.Distribution = Debian
|
result.Distribution = Debian
|
||||||
case "Gentoo/Linux":
|
case "gentoo":
|
||||||
result.Distribution = Gentoo
|
result.Distribution = Gentoo
|
||||||
|
case "zorin":
|
||||||
|
result.Distribution = Zorin
|
||||||
default:
|
default:
|
||||||
result.Distribution = Unknown
|
result.Distribution = Unknown
|
||||||
result.DistributorID = osName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.DistributorID = osID
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user