osutil – github.com/tredoe/osutil Index | Files | Directories

package osutil

import "github.com/tredoe/osutil"

Package osutil defines operating systems and detects the Linux distribution. Also, it handles basic operations in the management of packages in FreeBSD, Linux and macOs operating systems.

NOTE: Package management systems untested:

Index

Variables

var ListSystem = [...]System{FreeBSD, Linux, MacOS, Windows}

ListSystem is the list of allowed operating systems.

Functions

func DetectDistroVer

func DetectDistroVer() (verStr string, verNum float32, err error)

DetectDistroVer returns the Linux distro version. The 'verNum' is different to -1 when it can be converted to a numeric value.

func DetectSystemVer

func DetectSystemVer(sys System) (string, error)

DetectSystemVer returns the operating system version.

func SetupLogger

func SetupLogger(log, logShell *log.Logger)

SetupLogger setups the loggers used by some packages. 'log' is used by the packages 'edi', 'fileutil' and 'userutil'. 'logShell' is used by the packages 'executil' and 'pkg'.

func SystemFromGOOS

func SystemFromGOOS() (sys System, dist Distro, err error)

SystemFromGOOS returns the system from 'GOOS', and the distribution at Linux systems.

Types

type Distro

type Distro int

Distro represents a distribution of Linux system.

const (
	DistroUnknown Distro = iota

	Debian
	Ubuntu

	Fedora
	CentOS

	OpenSUSE

	Arch
	Manjaro
)

Most used Linux distributions.

func DetectDistro

func DetectDistro() (Distro, error)

DetectDistro returns the Linux distribution.

func (Distro) String

func (s Distro) String() string

type ManagerBrew

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

ManagerBrew is the interface to handle the macOS package manager.

func NewManagerBrew

func NewManagerBrew() ManagerBrew

NewManagerBrew returns the Homebrew package manager.

func (ManagerBrew) Clean

func (m ManagerBrew) Clean() error

func (ManagerBrew) ExecPath

func (m ManagerBrew) ExecPath() string

func (ManagerBrew) Install

func (m ManagerBrew) Install(name ...string) error

func (ManagerBrew) PackageType

func (m ManagerBrew) PackageType() string

func (ManagerBrew) Purge

func (m ManagerBrew) Purge(name ...string) error

func (ManagerBrew) Remove

func (m ManagerBrew) Remove(name ...string) error

func (ManagerBrew) Update

func (m ManagerBrew) Update() error

func (ManagerBrew) Upgrade

func (m ManagerBrew) Upgrade() error

type ManagerDeb

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

ManagerDeb is the interface to handle the package manager of Linux systems based at Debian.

func NewManagerDeb

func NewManagerDeb() ManagerDeb

NewManagerDeb returns the Deb package manager.

func (ManagerDeb) Clean

func (m ManagerDeb) Clean() error

func (ManagerDeb) ExecPath

func (m ManagerDeb) ExecPath() string

func (ManagerDeb) Install

func (m ManagerDeb) Install(name ...string) error

func (ManagerDeb) PackageType

func (m ManagerDeb) PackageType() string

func (ManagerDeb) Purge

func (m ManagerDeb) Purge(name ...string) error

func (ManagerDeb) Remove

func (m ManagerDeb) Remove(name ...string) error

func (ManagerDeb) Update

func (m ManagerDeb) Update() error

func (ManagerDeb) Upgrade

func (m ManagerDeb) Upgrade() error

type ManagerDnf

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

ManagerDnf is the interface to handle the package manager DNG of Linux systems based at Red Hat.

func NewManagerDnf

func NewManagerDnf() ManagerDnf

NewManagerDnf returns the DNF package manager.

func (ManagerDnf) Clean

func (m ManagerDnf) Clean() error

func (ManagerDnf) ExecPath

func (m ManagerDnf) ExecPath() string

func (ManagerDnf) Install

func (m ManagerDnf) Install(name ...string) error

func (ManagerDnf) PackageType

func (m ManagerDnf) PackageType() string

func (ManagerDnf) Purge

func (m ManagerDnf) Purge(name ...string) error

func (ManagerDnf) Remove

func (m ManagerDnf) Remove(name ...string) error

func (ManagerDnf) Update

func (m ManagerDnf) Update() error

func (ManagerDnf) Upgrade

func (m ManagerDnf) Upgrade() error

type ManagerEbuild

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

ManagerEbuild is the interface to handle the package manager of Linux systems based at Gentoo.

func NewManagerEbuild

func NewManagerEbuild() ManagerEbuild

NewManagerEbuild returns the Ebuild package manager.

func (ManagerEbuild) Clean

func (m ManagerEbuild) Clean() error

func (ManagerEbuild) ExecPath

func (m ManagerEbuild) ExecPath() string

func (ManagerEbuild) Install

func (m ManagerEbuild) Install(name ...string) error

func (ManagerEbuild) PackageType

func (m ManagerEbuild) PackageType() string

func (ManagerEbuild) Purge

func (m ManagerEbuild) Purge(name ...string) error

func (ManagerEbuild) Remove

func (m ManagerEbuild) Remove(name ...string) error

func (ManagerEbuild) Update

func (m ManagerEbuild) Update() error

func (ManagerEbuild) Upgrade

func (m ManagerEbuild) Upgrade() error

type ManagerPacman

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

ManagerPacman is the interface to handle the package manager of Linux systems based at Arch.

func NewManagerPacman

func NewManagerPacman() ManagerPacman

NewManagerPacman returns the Pacman package manager.

func (ManagerPacman) Clean

func (m ManagerPacman) Clean() error

func (ManagerPacman) ExecPath

func (m ManagerPacman) ExecPath() string

func (ManagerPacman) Install

func (m ManagerPacman) Install(name ...string) error

func (ManagerPacman) PackageType

func (m ManagerPacman) PackageType() string

func (ManagerPacman) Purge

func (m ManagerPacman) Purge(name ...string) error

func (ManagerPacman) Remove

func (m ManagerPacman) Remove(name ...string) error

func (ManagerPacman) Update

func (m ManagerPacman) Update() error

func (ManagerPacman) Upgrade

func (m ManagerPacman) Upgrade() error

type ManagerPkg

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

ManagerPkg is the interface to handle the FreeBSD package manager, called 'package' or 'pkg'.

func NewManagerPkg

func NewManagerPkg() ManagerPkg

NewManagerPkg returns the Pkg package manager.

func (ManagerPkg) Clean

func (m ManagerPkg) Clean() error

func (ManagerPkg) ExecPath

func (m ManagerPkg) ExecPath() string

func (ManagerPkg) Install

func (m ManagerPkg) Install(name ...string) error

func (ManagerPkg) PackageType

func (m ManagerPkg) PackageType() string

func (ManagerPkg) Purge

func (m ManagerPkg) Purge(name ...string) error

func (ManagerPkg) Remove

func (m ManagerPkg) Remove(name ...string) error

func (ManagerPkg) Update

func (m ManagerPkg) Update() error

func (ManagerPkg) Upgrade

func (m ManagerPkg) Upgrade() error

type ManagerRpm

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

ManagerRpm is the interface to handle the package manager RPM of Linux systems based at Red Hat.

func NewManagerRpm

func NewManagerRpm() ManagerRpm

NewManagerRpm returns the RPM package manager.

func (ManagerRpm) Clean

func (m ManagerRpm) Clean() error

func (ManagerRpm) ExecPath

func (m ManagerRpm) ExecPath() string

func (ManagerRpm) Install

func (m ManagerRpm) Install(name ...string) error

func (ManagerRpm) PackageType

func (m ManagerRpm) PackageType() string

func (ManagerRpm) Purge

func (m ManagerRpm) Purge(name ...string) error

func (ManagerRpm) Remove

func (m ManagerRpm) Remove(name ...string) error

func (ManagerRpm) Update

func (m ManagerRpm) Update() error

func (ManagerRpm) Upgrade

func (m ManagerRpm) Upgrade() error

type ManagerVoid

type ManagerVoid struct{}

ManagerVoid is the interface to pass a Manager with an error, avoiding to have to use a pointer.

func (ManagerVoid) Clean

func (m ManagerVoid) Clean() error

func (ManagerVoid) ExecPath

func (m ManagerVoid) ExecPath() string

func (ManagerVoid) Install

func (m ManagerVoid) Install(name ...string) error

func (ManagerVoid) PackageType

func (m ManagerVoid) PackageType() string

func (ManagerVoid) Purge

func (m ManagerVoid) Purge(name ...string) error

func (ManagerVoid) Remove

func (m ManagerVoid) Remove(name ...string) error

func (ManagerVoid) Update

func (m ManagerVoid) Update() error

func (ManagerVoid) Upgrade

func (m ManagerVoid) Upgrade() error

type ManagerYum

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

ManagerYum is the interface to handle the package manager YUM of Linux systems based at Red Hat.

func NewManagerYum

func NewManagerYum() ManagerYum

NewManagerYum returns the YUM package manager.

func (ManagerYum) Clean

func (m ManagerYum) Clean() error

func (ManagerYum) ExecPath

func (m ManagerYum) ExecPath() string

func (ManagerYum) Install

func (m ManagerYum) Install(name ...string) error

func (ManagerYum) PackageType

func (m ManagerYum) PackageType() string

func (ManagerYum) Purge

func (m ManagerYum) Purge(name ...string) error

func (ManagerYum) Remove

func (m ManagerYum) Remove(name ...string) error

func (ManagerYum) Update

func (m ManagerYum) Update() error

func (ManagerYum) Upgrade

func (m ManagerYum) Upgrade() error

type ManagerZypp

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

ManagerZypp is the interface to handle the package manager of Linux systems based at SUSE.

func NewManagerZypp

func NewManagerZypp() ManagerZypp

NewManagerZypp returns the Zypp package manager.

func (ManagerZypp) Clean

func (m ManagerZypp) Clean() error

func (ManagerZypp) ExecPath

func (m ManagerZypp) ExecPath() string

func (ManagerZypp) Install

func (m ManagerZypp) Install(name ...string) error

func (ManagerZypp) PackageType

func (m ManagerZypp) PackageType() string

func (ManagerZypp) Purge

func (m ManagerZypp) Purge(name ...string) error

func (ManagerZypp) Remove

func (m ManagerZypp) Remove(name ...string) error

func (ManagerZypp) Update

func (m ManagerZypp) Update() error

func (ManagerZypp) Upgrade

func (m ManagerZypp) Upgrade() error

type PackageType

type PackageType int8

PackageType represents a package management system.

const (
	// Linux
	Deb PackageType = iota + 1
	Dnf
	Ebuild
	Pacman
	Rpm
	Yum
	Zypp

	// BSD
	Brew
	Pkg
)

func NewPkgTypeFromStr

func NewPkgTypeFromStr(s string) (PackageType, error)

NewPkgTypeFromStr returns a package management system from the string.

func (PackageType) String

func (pkg PackageType) String() string

type PkgManager

type PkgManager interface {

	// ExecPath returns the executable path.
	ExecPath() string

	// PackageType returns the package type.
	PackageType() string

	// Install installs packages.
	Install(name ...string) error

	// Remove removes packages.
	Remove(name ...string) error

	// Purge removes packages and its configuration files (if the package system does it).
	Purge(name ...string) error

	// Update resynchronizes the package index files from their sources.
	Update() error

	// Upgrade upgrades all the packages on the system.
	Upgrade() error

	// Clean erases both packages downloaded and orphaned dependencies.
	Clean() error
	// contains filtered or unexported methods
}

PkgManager is the common interface to handle different package systems.

func DetectPkgManag

func DetectPkgManag() (PkgManager, error)

DetectPkgManag tries to get the package manager used in the system, looking for executables at directories in $PATH.

func NewPkgManagFromDistro

func NewPkgManagFromDistro(dis Distro) (PkgManager, error)

NewPkgManagFromDistro returns the package manager used by a Linux distro.

func NewPkgManagFromSystem

func NewPkgManagFromSystem(sys System, dis Distro) (PkgManager, error)

NewPkgManagFromSystem returns the package manager used by a system.

func NewPkgManagFromType

func NewPkgManagFromType(pkg PackageType) PkgManager

NewPkgManagFromType returns the interface to handle the package manager.

type System

type System uint8

System represents an operating system.

const (
	SystemUndefined System = iota
	Linux
	FreeBSD
	MacOS
	Windows
)

The operating systems.

func (System) String

func (s System) String() string

Source Files

distro.go doc.go exec.go log.go pkg.go pkg_arch.go pkg_centos.go pkg_debian.go pkg_freebsd_.go pkg_gentoo.go pkg_macos_.go pkg_suse.go pkg_void.go system.go

Directories

PathSynopsis
config
config/shconfPackage shconf implements a parser and scanner for the configuration in format shell-variable.
ediPackage edi allows edit files.
executilPackage executil lets to call to system commands.
fileutilPackage fileutil handles common operations in files.
internal
userutilPackage userutil provides access to UNIX users database in local files.
userutil/cryptPackage crypt provides interface for password crypt functions and collects common constants.
userutil/crypt/apr1_cryptPackage apr1_crypt implements the standard Unix MD5-crypt algorithm created by Poul-Henning Kamp for FreeBSD, and modified by the Apache project.
userutil/crypt/commonPackage common contains routines used by multiple password hashing algorithms.
userutil/crypt/md5_cryptPackage md5_crypt implements the standard Unix MD5-crypt algorithm created by Poul-Henning Kamp for FreeBSD.
userutil/crypt/sha256_cryptPackage sha256_crypt implements Ulrich Drepper's SHA256-crypt password hashing algorithm.
userutil/crypt/sha512_cryptPackage sha512_crypt implements Ulrich Drepper's SHA512-crypt password hashing algorithm.
Version
v1.3.2
Published
Aug 16, 2021
Platform
js/wasm
Imports
13 packages
Last checked
now

Tools for package owners.