utils

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func ActivateLVM added in v0.0.18

func ActivateLVM() error

func AppendSlash

func AppendSlash(path string) string

AppendSlash it's in the name. Appends a slash.

func BootStateToLabelDevice added in v0.0.11

func BootStateToLabelDevice() string

BootStateToLabelDevice lets us know the device we need to mount sysroot on based on labels.

func CleanSysrootForFstab

func CleanSysrootForFstab(path string) string

CleanSysrootForFstab will clean up the pesky sysroot dir from entries to make them suitable to be written in the fstab As we mount on /sysroot during initramfs but the fstab file is for the real init process, we need to remove Any mentions to /sysroot from the fstab lines, otherwise they won't work Special care for the root (/sysroot) path as we can't just simple remove that path and call it a day as that will return an empty mountpoint which will break fstab mounting.

func CleanupSlice

func CleanupSlice(slice []string) []string

CleanupSlice will clean a slice of strings of empty items Typos can be made on writing the cos-layout.env file and that could introduce empty items In the lists that we need to go over, which causes bad stuff.

func CloseLogFiles added in v0.0.13

func CloseLogFiles()

func CommandWithPath added in v0.0.13

func CommandWithPath(c string) (string, error)

CommandWithPath runs a command adding the usual PATH to environment Useful under UKI as there is nothing setting the PATH.

func CreateIfNotExists

func CreateIfNotExists(path string) error

CreateIfNotExists will check if a path exists and create it if needed.

func DisableImmucore added in v0.0.11

func DisableImmucore() bool

DisableImmucore identifies if we need to be disabled We disable if we boot from CD, netboot, squashfs recovery or have the rd.cos.disable stanza in cmdline.

func DiskFSType

func DiskFSType(s string) string

DiskFSType will return the FS type for a given disk Does NOT need to be mounted Needs full path so either /dev/sda1 or /dev/disk/by-{label,uuid}/{label,uuid} .

func DropToEmergencyShell added in v0.1.22

func DropToEmergencyShell()

func Fsck added in v0.0.11

func Fsck(device string) error

Fsck will run fsck over the device options are set on cmdline, but they are for systemd-fsck, so we need to interpret ourselves.

func GetHostProcCmdline added in v0.0.13

func GetHostProcCmdline() string

GetHostProcCmdline returns the path to /proc/cmdline Mainly used to override the cmdline during testing.

func GetOemLabel added in v0.0.13

func GetOemLabel() string

GetOemLabel will ge the oem label to mount, first from the cmdline and if that fails, from the runtime This way users can override the oem label.

func GetOemTimeout added in v0.0.13

func GetOemTimeout() int

GetOemTimeout parses the cmdline to get the oem timeout to use. Defaults to 5 (converted into seconds afterwards).

func GetOverlayBase added in v0.0.13

func GetOverlayBase() string

GetOverlayBase parses the cdmline and gets the overlay config Format is rd.cos.overlay=tmpfs:20% or rd.cos.overlay=LABEL=$LABEL or rd.cos.overlay=UUID=$UUID Notice that this can be later override by the config coming from cos-layout.env .

func GetRootDir

func GetRootDir() string

GetRootDir returns the proper dir to mount all the stuff Useful if we want to move to a no-pivot boot.

func GetState added in v0.0.11

func GetState() string

GetState returns the disk-by-label of the state partition to mount This is only valid for either active/passive or normal recovery.

func GetTarget added in v0.0.11

func GetTarget(dryRun bool) (string, string, error)

GetTarget gets the target image and device to mount in /sysroot.

func IsMounted added in v0.0.11

func IsMounted(dev string) bool

IsMounted lets us know if the given device is currently mounted.

func IsUKI added in v0.0.13

func IsUKI() bool

func Mount added in v0.1.26

func Mount(source string, target string, fstype string, flags uintptr, data string) (err error)

Mount will mount the given source to the target with the given fstype and flags.

func MountBasic added in v0.1.6

func MountBasic()

MountBasic will mount /proc and /run For now proc is needed to read the cmdline fully in uki mode in normal modes this should already be done by the initramfs process, so we can skip this. /run is needed to start logging from the start.

func MountToFstab

func MountToFstab(m mount.Mount) *fstab.Mount

MountToFstab transforms a mount.Mount into a fstab.Mount so we can transform existing mounts into the fstab format.

func NewYipExecutor added in v0.0.13

func NewYipExecutor(l logger.Interface) executor.Executor

func PCRExtend added in v0.1.26

func PCRExtend(pcr int, data []byte) error

PCRExtend extends the given pcr with the give data.

func ParseMount

func ParseMount(s string) string

ParseMount will return a proper full disk path based on UUID or LABEL given input: LABEL=FOO:/mount output: /dev/disk...:/mount .

func PrepareCommandWithPath added in v0.0.14

func PrepareCommandWithPath(c string) *exec.Cmd

PrepareCommandWithPath prepares a cmd with the proper env For running under yip.

func ReadCMDLineArg

func ReadCMDLineArg(arg string) []string

ReadCMDLineArg will return the pair of arg=value for a given arg if it was passed on the cmdline TODO: Split this into GetBool and GetValue to return decent defaults.

func ReadEnv

func ReadEnv(file string) (map[string]string, error)

ReadEnv will read an env file (key=value) and return a nice map.

func RootRW added in v0.0.11

func RootRW() string

RootRW tells us if the mode to mount root.

func RunStage added in v0.0.13

func RunStage(stage string) (bytes.Buffer, error)

func SetLogger added in v0.0.13

func SetLogger()

func Sync added in v0.1.26

func Sync()

Force flushing the data to disk.

func SyncState

func SyncState(src, dst string) error

SyncState will rsync source into destination. Useful for Bind mounts.

func UniqueSlice

func UniqueSlice(slice []string) []string

UniqueSlice removes duplicated entries from a slice.So dumb. Like really? Why not have a set which enforces uniqueness????

func UpgradeKcryptPartitions added in v0.0.23

func UpgradeKcryptPartitions() error

UpgradeKcryptPartitions will try check for the uuid of the persistent partition and upgrade its uuid.

Types

type Chroot added in v0.0.13

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 added in v0.0.13

func NewChroot(path string) *Chroot

func (*Chroot) Close added in v0.0.13

func (c *Chroot) Close() error

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

func (*Chroot) Prepare added in v0.0.13

func (c *Chroot) Prepare() error

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

func (*Chroot) Run added in v0.0.13

func (c *Chroot) Run(command string) (string, error)

Run executes a command inside a chroot.

func (*Chroot) RunCallback added in v0.0.13

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

RunCallback runs the given callback in a chroot environment.

type ImmucoreConsole added in v0.0.14

type ImmucoreConsole struct {
}

ImmucoreConsole is the console for yip. As we have to hijack the Run method to be able to run under UKI To add the paths, we need to create our own console.

func (ImmucoreConsole) Run added in v0.0.14

func (s ImmucoreConsole) Run(cmd string, opts ...func(cmd *exec.Cmd)) (string, error)

func (ImmucoreConsole) RunTemplate added in v0.0.14

func (s ImmucoreConsole) RunTemplate(st []string, template string) error

func (ImmucoreConsole) Start added in v0.0.14

func (s ImmucoreConsole) Start(cmd *exec.Cmd, opts ...func(cmd *exec.Cmd)) error

type MiddleLog added in v0.1.6

type MiddleLog struct {
	zerolog.Logger
}

MiddleLog implements the bridge between zerolog and the logger.Interface that yip needs.

func (MiddleLog) Debug added in v0.1.6

func (m MiddleLog) Debug(args ...interface{})

func (MiddleLog) Debugf added in v0.1.6

func (m MiddleLog) Debugf(tpl string, args ...interface{})

func (MiddleLog) Error added in v0.1.6

func (m MiddleLog) Error(args ...interface{})

func (MiddleLog) Errorf added in v0.1.6

func (m MiddleLog) Errorf(tpl string, args ...interface{})

func (MiddleLog) Fatal added in v0.1.6

func (m MiddleLog) Fatal(args ...interface{})

func (MiddleLog) Fatalf added in v0.1.6

func (m MiddleLog) Fatalf(tpl string, args ...interface{})

func (MiddleLog) Info added in v0.1.6

func (m MiddleLog) Info(args ...interface{})

func (MiddleLog) Infof added in v0.1.6

func (m MiddleLog) Infof(tpl string, args ...interface{})

func (MiddleLog) Panic added in v0.1.6

func (m MiddleLog) Panic(args ...interface{})

func (MiddleLog) Panicf added in v0.1.6

func (m MiddleLog) Panicf(tpl string, args ...interface{})

func (MiddleLog) Trace added in v0.1.6

func (m MiddleLog) Trace(args ...interface{})

func (MiddleLog) Tracef added in v0.1.6

func (m MiddleLog) Tracef(tpl string, args ...interface{})

func (MiddleLog) Warn added in v0.1.6

func (m MiddleLog) Warn(args ...interface{})

func (MiddleLog) Warnf added in v0.1.6

func (m MiddleLog) Warnf(tpl string, args ...interface{})

Jump to

Keyboard shortcuts

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