Last active
January 12, 2018 20:33
-
-
Save jniltinho/c8a5911bccbbda1c9e9365869ae89c37 to your computer and use it in GitHub Desktop.
Get Linux Dist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os/exec" | |
"strings" | |
) | |
func main() { | |
// https://unix.stackexchange.com/q/35183 | |
var DISTRIB string | |
std, err := exec.Command("lsb_release", "-i", "-r", "-c").CombinedOutput() | |
if err != nil { | |
log.Fatal(err) | |
} | |
id, release, codename := "", "", "" | |
// strings.TrimRight(string(std), "\n\t ") | |
for _, s := range strings.Split(string(std), "\n") { | |
b := strings.Split(s, "\t") | |
if len(b) == 2 { | |
if b[0] == "Distributor ID:" { | |
id = strings.ToLower(b[1]) | |
continue | |
} else if b[0] == "Release:" { | |
release = strings.ToLower(b[1]) | |
continue | |
} else if b[0] == "Codename:" { | |
codename = strings.ToLower(b[1]) | |
continue | |
} | |
} | |
} | |
if id == "" { | |
println("Could not identify Distributor ID") | |
} | |
if release == "" { | |
println("Could not identify Release") | |
} | |
if codename == "" { | |
println("Could not identify Codename") | |
} | |
if id == "" || release == "" || codename == "" { | |
return | |
} | |
DISTRIB = id + " " + release + " " + codename | |
println(DISTRIB) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment