pull/4/head
Shirou WAKAYAMA 11 years ago
parent 4b7a2b298d
commit 955c9d23c0

@ -9,9 +9,9 @@ import (
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
"strings"
"syscall" "syscall"
"unsafe" "unsafe"
"strings"
) )
type LSB struct { type LSB struct {
@ -33,13 +33,12 @@ func HostInfo() (*HostInfoStat, error) {
} }
platform, family, version, err := getPlatformInformation() platform, family, version, err := getPlatformInformation()
if err == nil{ if err == nil {
ret.Platform = platform ret.Platform = platform
ret.PlatformFamily = family ret.PlatformFamily = family
ret.PlatformVersion = version ret.PlatformVersion = version
} }
return ret, nil return ret, nil
} }
@ -162,36 +161,36 @@ func getPlatformInformation() (string, string, string, error) {
version, _ = getRedhatishVersion(contents) version, _ = getRedhatishVersion(contents)
} }
} else if pathExists("/etc/debian_version") { } else if pathExists("/etc/debian_version") {
if lsb.ID == "Ubuntu"{ if lsb.ID == "Ubuntu" {
platform = "ubuntu" platform = "ubuntu"
version = lsb.Release version = lsb.Release
}else if lsb.ID == "LinuxMint"{ } else if lsb.ID == "LinuxMint" {
platform = "linuxmint" platform = "linuxmint"
version = lsb.Release version = lsb.Release
}else{ } else {
if pathExists("/usr/bin/raspi-config"){ if pathExists("/usr/bin/raspi-config") {
platform = "raspbian" platform = "raspbian"
}else{ } else {
platform = "debian" platform = "debian"
} }
contents, err := readLines("/etc/debian_version") contents, err := readLines("/etc/debian_version")
if err == nil{ if err == nil {
version = contents[0] version = contents[0]
} }
} }
} else if pathExists("/etc/redhat-release"){ } else if pathExists("/etc/redhat-release") {
contents, err := readLines("/etc/redhat-release") contents, err := readLines("/etc/redhat-release")
if err == nil { if err == nil {
version, _ = getRedhatishVersion(contents) version, _ = getRedhatishVersion(contents)
platform, _ = getRedhatishPlatform(contents) platform, _ = getRedhatishPlatform(contents)
} }
} else if pathExists("/etc/system-release"){ } else if pathExists("/etc/system-release") {
contents, err := readLines("/etc/system-release") contents, err := readLines("/etc/system-release")
if err == nil { if err == nil {
version, _ = getRedhatishVersion(contents) version, _ = getRedhatishVersion(contents)
platform, _ = getRedhatishPlatform(contents) platform, _ = getRedhatishPlatform(contents)
} }
} else if pathExists("/etc/gentoo-release"){ } else if pathExists("/etc/gentoo-release") {
platform = "gentoo" platform = "gentoo"
contents, err := readLines("/etc/gentoo-release") contents, err := readLines("/etc/gentoo-release")
if err == nil { if err == nil {
@ -199,27 +198,26 @@ func getPlatformInformation() (string, string, string, error) {
} }
// TODO: suse detection // TODO: suse detection
// TODO: slackware detecion // TODO: slackware detecion
}else if pathExists("/etc/arch-release"){ } else if pathExists("/etc/arch-release") {
platform = "arch" platform = "arch"
// TODO: exherbo detection // TODO: exherbo detection
}else if lsb.ID == "RedHat"{ } else if lsb.ID == "RedHat" {
platform = "redhat" platform = "redhat"
version = lsb.Release version = lsb.Release
}else if lsb.ID == "Amazon"{ } else if lsb.ID == "Amazon" {
platform = "amazon" platform = "amazon"
version = lsb.Release version = lsb.Release
}else if lsb.ID == "ScientificSL"{ } else if lsb.ID == "ScientificSL" {
platform = "scientific" platform = "scientific"
version = lsb.Release version = lsb.Release
}else if lsb.ID == "XenServer"{ } else if lsb.ID == "XenServer" {
platform = "xenserver" platform = "xenserver"
version = lsb.Release version = lsb.Release
}else if lsb.ID != ""{ } else if lsb.ID != "" {
platform = strings.ToLower(lsb.ID) platform = strings.ToLower(lsb.ID)
version = lsb.Release version = lsb.Release
} }
switch platform { switch platform {
case "debian", "ubuntu", "linuxmint", "raspbian": case "debian", "ubuntu", "linuxmint", "raspbian":
family = "debian" family = "debian"

Loading…
Cancel
Save