os

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 5

Documentation

Overview

Package os provides a platform-independent interface to operating system functionality.

Index

Constants

This section is empty.

Variables

View Source
var ErrCommandFailed = errors.New("command failed")

ErrCommandFailed is returned when a command fails

View Source
var ErrInitSystemNotSupported = errors.New("init system not supported")

ErrInitSystemNotSupported is returned when the init system is not supported

Functions

This section is empty.

Types

type FileInfo added in v0.6.0

type FileInfo struct {
	FName    string
	FSize    int64
	FMode    fs.FileMode
	FModTime time.Time
	FIsDir   bool
}

FileInfo implements fs.FileInfo for stat on remote files

func (*FileInfo) IsDir added in v0.6.0

func (f *FileInfo) IsDir() bool

IsDir returns true if the file path points to a directory

func (*FileInfo) ModTime added in v0.6.0

func (f *FileInfo) ModTime() time.Time

ModTime returns the last modification time of a file

func (*FileInfo) Mode added in v0.6.0

func (f *FileInfo) Mode() fs.FileMode

Mode returns the file permission mode

func (*FileInfo) Name added in v0.6.0

func (f *FileInfo) Name() string

Name returns the file name

func (*FileInfo) Size added in v0.6.0

func (f *FileInfo) Size() int64

Size returns the file size

type Host

type Host interface {
	Upload(source, destination string, opts ...exec.Option) error
	Exec(cmd string, opts ...exec.Option) error
	ExecOutput(cmd string, opts ...exec.Option) (string, error)
	Execf(cmd string, argsOrOpts ...any) error
	ExecOutputf(cmd string, argsOrOpts ...any) (string, error)
	ExecStreams(cmd string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer, opts ...exec.Option) (exec.Waiter, error)
	String() string
	Sudo(cmd string) (string, error)
}

Host is an interface to a host object that has the functions needed by the various OS support packages

type Linux

type Linux struct{}

Linux is a base module for various linux OS support packages

func (Linux) CheckPrivilege

func (c Linux) CheckPrivilege(h Host) error

CheckPrivilege checks if the current user has root privileges

func (Linux) Chmod added in v0.4.6

func (c Linux) Chmod(h Host, s, perm string, opts ...exec.Option) error

Chmod updates permissions of a path

func (Linux) CleanupEnvironment

func (c Linux) CleanupEnvironment(h Host, env map[string]string) error

CleanupEnvironment removes environment variable configuration

func (Linux) CleanupServiceEnvironment added in v0.3.24

func (c Linux) CleanupServiceEnvironment(h Host, s string) error

CleanupServiceEnvironment updates environment variables for a service

func (Linux) CommandExist

func (c Linux) CommandExist(h Host, cmd string) bool

CommandExist returns true if the command exists

func (Linux) DaemonReload

func (c Linux) DaemonReload(h Host) error

DaemonReload performs an init system config reload

func (Linux) DeleteFile

func (c Linux) DeleteFile(h Host, path string) error

DeleteFile deletes a file from the host.

func (Linux) DisableService

func (c Linux) DisableService(h Host, s string) error

DisableService disables a service on the host

func (Linux) EnableService

func (c Linux) EnableService(h Host, s string) error

EnableService enables a service on the host

func (Linux) FileExist

func (c Linux) FileExist(h Host, path string) bool

FileExist checks if a file exists on the host

func (Linux) FixContainer

func (c Linux) FixContainer(h Host) error

FixContainer makes a container work like a real host

func (Linux) Hostname

func (c Linux) Hostname(h Host) string

Hostname resolves the short hostname

func (Linux) InstallFile added in v0.4.0

func (c Linux) InstallFile(h Host, src, dst, permissions string) error

InstallFile installs a file to the host

func (Linux) IsContainer

func (c Linux) IsContainer(h Host) bool

IsContainer returns true if the host is actually a container

func (Linux) JoinPath

func (c Linux) JoinPath(parts ...string) string

JoinPath joins a path

func (Linux) Kind

func (c Linux) Kind() string

Kind returns "linux"

func (Linux) LineIntoFile

func (c Linux) LineIntoFile(h Host, path, matcher, newLine string) error

LineIntoFile tries to find a line starting with the matcher and replace it with a new entry. If match isn't found, the string is appended to the file. TODO add exec.Opts (requires modifying readfile and writefile signatures)

func (Linux) LongHostname

func (c Linux) LongHostname(h Host) string

LongHostname resolves the FQDN (long) hostname

func (Linux) MkDir added in v0.4.6

func (c Linux) MkDir(h Host, s string, opts ...exec.Option) error

MkDir creates a directory (including intermediate directories)

func (Linux) Pwd

func (c Linux) Pwd(h Host) string

Pwd returns the current working directory of the session

func (Linux) ReadFile

func (c Linux) ReadFile(h Host, path string) (string, error)

ReadFile reads a files contents from the host.

func (Linux) Reboot

func (c Linux) Reboot(h Host) error

Reboot executes the reboot command

func (Linux) RestartService

func (c Linux) RestartService(h Host, s string) error

RestartService restarts a service on the host

func (Linux) SELinuxEnabled

func (c Linux) SELinuxEnabled(h Host) bool

SELinuxEnabled is true when SELinux is enabled

func (Linux) ServiceIsRunning

func (c Linux) ServiceIsRunning(h Host, s string) bool

ServiceIsRunning returns true if the service is running on the host

func (Linux) ServiceScriptPath

func (c Linux) ServiceScriptPath(h Host, s string) (string, error)

ServiceScriptPath returns the service definition file path on the host

func (Linux) Sha256sum added in v0.16.0

func (c Linux) Sha256sum(h Host, path string, opts ...exec.Option) (string, error)

Sha256sum calculates the sha256 checksum of a file

func (Linux) StartService

func (c Linux) StartService(h Host, s string) error

StartService starts a service on the host

func (Linux) Stat added in v0.6.0

func (c Linux) Stat(h Host, path string, opts ...exec.Option) (*FileInfo, error)

Stat gets file / directory information

func (Linux) StopService

func (c Linux) StopService(h Host, s string) error

StopService stops a service on the host

func (Linux) Touch added in v0.6.0

func (c Linux) Touch(h Host, path string, ts time.Time, opts ...exec.Option) error

Touch updates a file's last modified time. It creates a new empty file if it didn't exist prior to the call to Touch.

func (Linux) UpdateEnvironment

func (c Linux) UpdateEnvironment(h Host, env map[string]string) error

UpdateEnvironment updates the hosts's environment variables

func (Linux) UpdateServiceEnvironment added in v0.3.24

func (c Linux) UpdateServiceEnvironment(h Host, s string, env map[string]string) error

UpdateServiceEnvironment updates environment variables for a service

func (Linux) WriteFile

func (c Linux) WriteFile(h Host, path string, data string, permissions string) error

WriteFile writes file to host with given contents. Do not use for large files.

type Windows

type Windows struct{}

Windows is the base package for windows OS support

func (Windows) CheckPrivilege

func (c Windows) CheckPrivilege(h Host) error

CheckPrivilege returns an error if the user does not have admin access to the host

func (Windows) Chmod added in v0.4.6

func (c Windows) Chmod(_ Host, _, _ string, _ ...exec.Option) error

Chmod on windows does nothing

func (Windows) CleanupEnvironment

func (c Windows) CleanupEnvironment(h Host, env map[string]string) error

CleanupEnvironment removes environment variable configuration

func (Windows) CleanupServiceEnvironment added in v0.3.24

func (c Windows) CleanupServiceEnvironment(_ Host, _ string) error

CleanupServiceEnvironment does nothing on windows

func (Windows) CommandExist

func (c Windows) CommandExist(h Host, cmd string) bool

CommandExist returns true if the provided command exists

func (Windows) DaemonReload

func (c Windows) DaemonReload(_ Host) error

DaemonReload reloads init system configuration. No-op on windows.

func (Windows) DeleteFile

func (c Windows) DeleteFile(h Host, path string) error

DeleteFile deletes a file from the host.

func (Windows) DisableService

func (c Windows) DisableService(h Host, s string) error

DisableService disables a service

func (Windows) EnableService

func (c Windows) EnableService(h Host, s string) error

EnableService enables a service

func (Windows) FileExist

func (c Windows) FileExist(h Host, path string) bool

FileExist checks if a file exists on the host

func (Windows) FixContainer

func (c Windows) FixContainer(_ Host) error

FixContainer makes a container work like a real host (does nothing on windows for now)

func (Windows) Hostname

func (c Windows) Hostname(h Host) string

Hostname resolves the short hostname

func (Windows) InstallFile added in v0.4.0

func (c Windows) InstallFile(h Host, src, dst, _ string) error

InstallFile on windows is a regular file move operation

func (Windows) InstallPackage

func (c Windows) InstallPackage(h Host, s ...string) error

InstallPackage enables an optional windows feature

func (Windows) IsContainer

func (c Windows) IsContainer(_ Host) bool

IsContainer returns true if the host is actually a container (always false on windows for now)

func (Windows) JoinPath

func (c Windows) JoinPath(parts ...string) string

JoinPath joins a path

func (Windows) Kind

func (c Windows) Kind() string

Kind returns "windows"

func (Windows) LineIntoFile added in v0.6.2

func (c Windows) LineIntoFile(h Host, path, matcher, newLine string) error

LineIntoFile tries to find a line starting with the matcher and replace it with a new entry. If match isn't found, the string is appended to the file. TODO this is a straight copypaste from linux, figure out a way to share these

func (Windows) LongHostname

func (c Windows) LongHostname(h Host) string

LongHostname resolves the FQDN (long) hostname

func (Windows) MkDir added in v0.4.6

func (c Windows) MkDir(h Host, s string, opts ...exec.Option) error

MkDir creates a directory (including intermediate directories)

func (Windows) Pwd

func (c Windows) Pwd(h Host) string

Pwd returns the current working directory

func (Windows) ReadFile

func (c Windows) ReadFile(h Host, path string) (string, error)

ReadFile reads a file's contents from the host.

func (Windows) Reboot

func (c Windows) Reboot(h Host) error

Reboot executes the reboot command

func (Windows) RestartService

func (c Windows) RestartService(h Host, s string) error

RestartService restarts a service

func (Windows) SELinuxEnabled

func (c Windows) SELinuxEnabled(_ Host) bool

SELinuxEnabled is true when SELinux is enabled (always false on windows for now)

func (Windows) ServiceIsRunning

func (c Windows) ServiceIsRunning(h Host, s string) bool

ServiceIsRunning returns true if a service is running

func (Windows) ServiceScriptPath

func (c Windows) ServiceScriptPath(_ Host, _ string) (string, error)

ServiceScriptPath returns the path to a service configuration file

func (Windows) Sha256sum added in v0.16.0

func (c Windows) Sha256sum(h Host, path string, opts ...exec.Option) (string, error)

Sha256sum returns the sha256sum of a file

func (Windows) StartService

func (c Windows) StartService(h Host, s string) error

StartService starts a service

func (Windows) Stat added in v0.6.0

func (c Windows) Stat(h Host, path string, opts ...exec.Option) (*FileInfo, error)

Stat gets file / directory information

func (Windows) StopService

func (c Windows) StopService(h Host, s string) error

StopService stops a service

func (Windows) Touch added in v0.6.0

func (c Windows) Touch(h Host, path string, ts time.Time, opts ...exec.Option) error

Touch updates a file's last modified time or creates a new empty file

func (Windows) UpdateEnvironment

func (c Windows) UpdateEnvironment(h Host, env map[string]string) error

UpdateEnvironment updates the hosts's environment variables

func (Windows) UpdateServiceEnvironment added in v0.3.24

func (c Windows) UpdateServiceEnvironment(_ Host, _ string, _ map[string]string) error

UpdateServiceEnvironment does nothing on windows

func (Windows) WriteFile

func (c Windows) WriteFile(h Host, path string, data string, _ string) error

WriteFile writes file to host with given contents. Do not use for large files. The permissions argument is ignored on windows.

Directories

Path Synopsis
Package initsystem provides an abstraction over several supported init systems.
Package initsystem provides an abstraction over several supported init systems.
Package linux contains configurers for various linux based distributions
Package linux contains configurers for various linux based distributions
enterpriselinux
Package enterpriselinux provides OS modules for Enterprise Linux based distributions
Package enterpriselinux provides OS modules for Enterprise Linux based distributions
Package darwin provides a configurer for macOS
Package darwin provides a configurer for macOS
Package registry is a registry of OS support modules
Package registry is a registry of OS support modules
Package support can be imported to load all the stock os support packages.
Package support can be imported to load all the stock os support packages.
Package windows provides OS support for Windows.
Package windows provides OS support for Windows.

Jump to

Keyboard shortcuts

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