distrodetector

package module
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

README

distrodetector

GoDoc License Go Report Card

Detects which Linux distro or BSD a system is running.

Aims to detect:

  • The 100 most popular Linux distros and BSDs, according to distrowatch
  • macOS

The distro utility and the distrodetector package has no external dependencies.

Pull requests for additional systems are welcome!

Installation of the distro utility

The distro utility can be used as a drop-in replacement for the distro command that comes with python-distro.

Installation of the development version of the distro utility:

go get -u github.com/xyproto/distrodetector/cmd/distro

Example use:

distro

Use of the Go package

package main

import (
    "fmt"
    "github.com/xyproto/distrodetector"
)

func main() {
    distro := distrodetector.New()
    fmt.Println(distro.Name())
}

Example output

The parts can be retrieved separately with .Platform(), .Name(), .Codename() and .Version(). A combined string can be returned with the .String() function:

Linux (Arch Linux)
Linux (Ubuntu Bionic 18.04)
macOS (High Sierra 10.13.3)
Linux (Void Linux)

Testing

  • More testing is always needed when detecting Linux distros and BSDs.
  • Please test the distro detection on your distro/BSD and submit an issue or pull request if it should fail.

General Info

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppleCodename

func AppleCodename(version string) string

AppleCodename returns a codename, or an empty string. Will first use the lookup table, and then try to fetch it from Apple over HTTP.

func Has

func Has(executable string) bool

Has returns the full path to the given executable, or the original string

func Run

func Run(shellCommand string) string

Run a shell command and return the output, or an empty string

Types

type Distro

type Distro struct {
	// contains filtered or unexported fields
}

Distro represents the platform, contents of /etc/*release* and name of the detected Linux distribution or BSD.

func New

func New() *Distro

New detects the platform and distro/BSD, then returns a pointer to a Distro struct.

func (*Distro) Codename

func (d *Distro) Codename() string

Codename returns the detected codename of the current distro/BSD, or an empty string.

func (*Distro) EtcRelease

func (d *Distro) EtcRelease() string

EtcRelease returns the contents of /etc/*release + /etc/issue, or an empty string. The contents are cached.

func (*Distro) Grep

func (d *Distro) Grep(name string) bool

Grep /etc/*release* for the given string. If the search fails, a case-insensitive string search is attempted. The contents of /etc/*release* is cached.

func (*Distro) Name

func (d *Distro) Name() string

Name returns the detected name of the current distro/BSD, or "Unknown".

func (*Distro) Platform

func (d *Distro) Platform() string

Platform returns the name of the current platform. This is the same as `runtime.GOOS`, but capitalized.

func (*Distro) String

func (d *Distro) String() string

String returns a string with the current platform, distro codename and release version (if available). Example strings:

Linux (Ubuntu Bionic 18.04)
Darwin (10.13.3)

func (*Distro) Version

func (d *Distro) Version() string

Version returns the detected release version of the current distro/BSD, or an empty string.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL