utils

package
v2.10.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UkiHDD            state.Boot = "uki_boot_mode"
	UkiRemovableMedia state.Boot = "uki_install_mode"
)

Variables

This section is empty.

Functions

func CalcFileChecksum

func CalcFileChecksum(fs v1.FS, fileName string) (string, error)

CalcFileChecksum opens the given file and returns the sha256 checksum of it.

func ChrootedCallback

func ChrootedCallback(cfg *agentConfig.Config, path string, bindMounts map[string]string, callback func() error) error

ChrootedCallback runs the given callback in a chroot environment

func CommandExists

func CommandExists(command string) bool

func ConcatFiles

func ConcatFiles(fs v1.FS, sources []string, target string) (err error)

ConcatFiles Copies source files to target file using Fs interface. Source files are concatenated into target file in the given order. If target is a directory source is copied into that directory using 1st source name file.

func CopyFile

func CopyFile(fs v1.FS, source string, target string) (err error)

CopyFile Copies source file to target file using Fs interface. If target is directory source is copied into that directory using source name file.

func CosignVerify

func CosignVerify(fs v1.FS, runner v1.Runner, image string, publicKey string) (string, error)

CosignVerify runs a cosign validation for the give image and given public key. If no key is provided then it attempts a keyless validation (experimental feature).

func CreateDirStructure

func CreateDirStructure(fs v1.FS, target string) error

Copies source file to target file using Fs interface

func CreateSquashFS

func CreateSquashFS(runner v1.Runner, logger sdkTypes.KairosLogger, source string, destination string, options []string) error

CreateSquashFS creates a squash file at destination from a source, with options TODO: Check validity of source maybe?

func FindCommand

func FindCommand(defaultPath string, options []string) string

FindCommand will search for the command(s) in the options given to find the current command If it cant find it returns the default value give. Useful for the same binaries with different names across OS

func FindFileWithPrefix

func FindFileWithPrefix(fs v1.FS, path string, prefixes ...string) (string, error)

FindFileWithPrefix looks for a file in the given path matching one of the given prefixes. Returns the found file path including the given path. It does not check subfolders recusively

func GetDeviceByLabel

func GetDeviceByLabel(runner v1.Runner, label string, attempts int) (string, error)

GetDeviceByLabel will try to return the device that matches the given label. attempts value sets the number of attempts to find the device, it waits a second between attempts.

func GetFullDeviceByLabel

func GetFullDeviceByLabel(runner v1.Runner, label string, attempts int) (*v1.Partition, error)

GetFullDeviceByLabel works like GetDeviceByLabel, but it will try to get as much info as possible from the existing partition and return a v1.Partition object

func GetSource

func GetSource(config *agentConfig.Config, source string, destination string) error

GetSource copies given source to destination, if source is a local path it simply copies files, if source is a remote URL it tries to download URL to destination.

func GetTempDir

func GetTempDir(config *agentConfig.Config, suffix string) string

GetTempDir returns the dir for storing related temporal files It will respect TMPDIR and use that if exists, fallback to try the persistent partition if its mounted and finally the default /tmp/ dir suffix is what is appended to the dir name elemental-suffix. If empty it will randomly generate a number

func IsHTTPURI

func IsHTTPURI(uri string) (bool, error)

IsHTTPURI returns true if the uri has "http" or "https" scheme, returns false otherwise. Error is not nil only if the url can't be parsed.

func IsLocalURI

func IsLocalURI(uri string) (bool, error)

IsLocalURI returns true if the uri has "file" scheme or no scheme and URI is not prefixed with a domain (container registry style). Returns false otherwise. Error is not nil only if the url can't be parsed.

func IsMounted

func IsMounted(config *agentConfig.Config, part *v1.Partition) (bool, error)

func IsUki added in v2.6.3

func IsUki() bool

IsUki returns true if the system is running in UKI mode. Checks the cmdline as UKI artifacts have the rd.immucore.uki flag

func IsUkiWithFs added in v2.7.13

func IsUkiWithFs(fs v1.FS) bool

IsUkiWithFs checks if the system is running in UKI mode by checking the kernel command line for the rd.immucore.uki flag Uses a v1.Fs interface to allow for testing

func LoadEnvFile

func LoadEnvFile(fs v1.FS, file string) (map[string]string, error)

LoadEnvFile will try to parse the file given and return a map with the kye/values

func Reboot

func Reboot(runner v1.Runner, delay time.Duration) error

Reboot reboots the system afater the given delay (in seconds) time passed.

func RunStage

func RunStage(cfg *agentConfig.Config, stage string) error

RunStage will run yip

func Shutdown

func Shutdown(runner v1.Runner, delay time.Duration) error

Shutdown halts the system afater the given delay (in seconds) time passed.

func SyncData

func SyncData(log sdkTypes.KairosLogger, runner v1.Runner, fs v1.FS, source string, target string, excludes ...string) error

SyncData rsync's source folder contents to a target folder content, both are expected to exist beforehand.

func SystemdBootConfReader added in v2.7.6

func SystemdBootConfReader(vfs v1.FS, filePath string) (map[string]string, error)

SystemdBootConfReader reads a systemd-boot conf file and returns a map with the key/value pairs TODO: Move this to the sdk with the FS interface

func SystemdBootConfWriter added in v2.7.13

func SystemdBootConfWriter(fs v1.FS, filePath string, conf map[string]string) error

SystemdBootConfWriter writes a map to a systemd-boot conf file TODO: Move this to the sdk with the FS interface

func UkiBootMode added in v2.6.3

func UkiBootMode() state.Boot

UkiBootMode will return where the system is running from, either HDD or RemovableMedia HDD means we are booting from an already installed system RemovableMedia means we are booting from a live media like a CD or USB

func ValidContainerReference

func ValidContainerReference(ref string) bool

ValidContainerReferece returns true if the given string matches a container registry reference, false otherwise

func ValidTaggedContainerReference

func ValidTaggedContainerReference(ref string) bool

ValidTaggedContainerReferece returns true if the given string matches a container registry reference including a tag, false otherwise.

Types

type Chroot

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

Chroot represents the struct that will allow us to run commands inside a given chroot

func NewChroot

func NewChroot(path string, config *agentConfig.Config) *Chroot

func (*Chroot) Close

func (c *Chroot) Close() error

Close will unmount all active mounts created in Prepare on reverse order

func (*Chroot) Prepare

func (c *Chroot) Prepare() error

Prepare will mount the defaultMounts as bind mounts, to be ready when we run chroot

func (*Chroot) Run

func (c *Chroot) Run(command string, args ...string) (out []byte, err error)

Run executes a command inside a chroot

func (*Chroot) RunCallback

func (c *Chroot) RunCallback(callback func() error) (err error)

RunCallback runs the given callback in a chroot environment

func (*Chroot) SetExtraMounts

func (c *Chroot) SetExtraMounts(extraMounts map[string]string)

Sets additional bind mounts for the chroot enviornment. They are represented in a map where the key is the path outside the chroot and the value is the path inside the chroot.

type CleanJob

type CleanJob func() error

type CleanStack

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

Stack is a basic LIFO stack that resizes as needed.

func NewCleanStack

func NewCleanStack() *CleanStack

NewCleanStack returns a new stack.

func (*CleanStack) Cleanup

func (clean *CleanStack) Cleanup(err error) error

Cleanup runs the whole cleanup stack. In case of error it runs all jobs and returns the first error occurrence.

func (*CleanStack) Pop

func (clean *CleanStack) Pop() CleanJob

Pop removes and returns a node from the stack in last to first order.

func (*CleanStack) Push

func (clean *CleanStack) Push(job CleanJob)

Push adds a node to the stack

type Grub

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

Grub is the struct that will allow us to install grub to the target device

func NewGrub

func NewGrub(config *agentConfig.Config) *Grub

func (Grub) Install

func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool, stateLabel string) (err error)

Install installs grub into the device, copy the config file and add any extra TTY to grub

func (Grub) SetPersistentVariables

func (g Grub) SetPersistentVariables(grubEnvFile string, vars map[string]string) error

Sets the given key value pairs into as grub variables into the given file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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