osrelease

package module
v0.0.0-...-9b29269 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: Apache-2.0 Imports: 4 Imported by: 12

README

osrelease - Go library/binary for parsing osrelease

See the os-release documentation.

Building

make deps      # Install dependencies
...
make osrelease # Create the binary
...

Usage

Note: OSRelease type directly supports fields as defined by the os-release documentation. Fields that are present but are not explicitly part of said documentation are added in ADDITIONAL_FIELDS. When using the command line binary these fields are accesses the same way as supported fields. When using osrelease as a library to find unsupported fields ADDITIONAL_FIELDS (map[string]string) will need to be searched.

Command Line
# A single field
./osrelease field ID
fedora$

# A field that is not considered part of the supported set
./osrelease field REDHAT_BUGZILLA_PRODUCT_VERSION
26$

# A field that doesn't exist
$ ./osrelease field idonotexist
$ echo $?
1

# In a format
./osrelease yaml
name: Fedora
version: 26 (Workstation Edition)
id: fedora
...
$
Library

import (
	"errors"

	"github.com/ashcrow/osrelease"
)

func RequireFedora() error {
	// The OSRelease instance using the default paths
	or, err := osrelease.New(nil)
	// Or to inspect the files in /sysroot
	//or, err := osrelease.NewWithOverrides("/sysroot/etc/osrelease", "/tmp/someplace/usr/lib/os-release"))
	// Handle the error however you see fit
	if err != nil {
		return err
	}

	if or.ID != "fedora" {
		return errors.New("Fedora Linux is a requirement")
	}

	// Everything is fine
	return nil
}

Documentation

Overview

Package osrelease package provides access to parsed os-release information

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OSRelease

type OSRelease struct {
	NAME               string            // OS Identifier
	VERSION            string            // Full OS Version
	ID                 string            // Lowercase OS identifier
	ID_LIKE            string            // Coma seperated list of closely related OSes
	VERSION_ID         string            // Lowercase OS version
	VERSION_CODENAME   string            // Lowercase OS release codename
	PRETTY_NAME        string            // Human presented OS/Release name
	ANSI_COLOR         string            // Suggested color for showing OS name
	CPE_NAME           string            // See http://scap.nist.gov/specifications/cpe/
	HOME_URL           string            // Main link for the OS
	BUG_REPORT_URL     string            // Bug report link for the OS
	PRIVACY_POLICY_URL string            // Privacy policy link for the OS
	VARIANT            string            // Human presnted OS Variant
	VARIANT_ID         string            // Lowercase OS Variant identifier
	ADDITIONAL_FIELDS  map[string]string // Custom/unsupported fields
	// contains filtered or unexported fields
}

OSRelease implements the format noted at https://www.freedesktop.org/software/systemd/man/os-release.html

func New

func New() (OSRelease, error)

New creates and returns a new insance of OSRelease. Generally New should be used to create a new instance.

func NewWithOverrides

func NewWithOverrides(etcOverridePath, usrOverridePath string) (OSRelease, error)

NewWithOverrides creates and returns a new instance of OSRelease using the paths passed in.

func (*OSRelease) GetField

func (o *OSRelease) GetField(key string) (string, error)

GetField returns a field from the instance. If the field is not present then an error us returned.

func (*OSRelease) Populate

func (o *OSRelease) Populate(paths []string) error

Populate reads the os-release file, parses it, and sets fields for use.

func (*OSRelease) SetField

func (o *OSRelease) SetField(key, value string)

SetField sets a field on an instance of OSRelease. If the field is not a supported field it will be added to ADDITIONAL_FIELDS.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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