Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support FreeBSD #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions dist_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package osutil

import (
"io/ioutil"
"os/exec"
"strings"
)

func getFreeBSDVersion() (string, bool) {
proc := exec.Command("freebsd-version", "-u")
raw, err := proc.Output()

if err != nil {
return "", false
}

return strings.TrimRight(string(raw), "\n"), true
}

func getOSRelease() (map[string]string, bool) {
osmap := make(map[string]string)

raw, err := ioutil.ReadFile("/etc/os-release")

if err != nil {
return osmap, false
}

s := string(raw)

for _, line := range strings.Split(s, "\n") {
if line == "" {
break
}

pair := strings.Split(line, "=")
k := pair[0]
v := pair[1]

v = strings.Trim(v, "\"")

osmap[k] = v
}

return osmap, true
}

func GetDist() Distro {
var detect string
var release string

version, freeBSDVersionExists := getFreeBSDVersion()
if freeBSDVersionExists {
return Distro{"FreeBSD", version, ""}
}

osmap, osMapExists := getOSRelease()

if osMapExists {
name := osmap["NAME"]
if name != "" {
detect = name
}

version := osmap["VERSION_ID"]
if version != "" {
release = version
}
}

return Distro{detect, release, ""}
}
2 changes: 1 addition & 1 deletion os_bsd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build freebsd,openbsd,dragonfly,netbsd
// +build openbsd,dragonfly,netbsd

package osutil

Expand Down
16 changes: 16 additions & 0 deletions os_freebsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
package osutil

import "fmt"

const Name = "FreeBSD"

func GetDisplay() string {
distro := GetDist()

if distro.Display != "" {
return fmt.Sprintf("%s %s", distro.Display, distro.Release)
}

return Name
}

func GetVersion() string {
return ""
}