Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Last active January 12, 2018 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jniltinho/c8a5911bccbbda1c9e9365869ae89c37 to your computer and use it in GitHub Desktop.
Save jniltinho/c8a5911bccbbda1c9e9365869ae89c37 to your computer and use it in GitHub Desktop.
Get Linux Dist
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