platform

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package platform provides ownership preservation utilities for sudo environments.

Package platform provides system and platform detection utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckGO

func CheckGO() bool

CheckGO checks if the Go compiler is installed and available.

func GOSetup

func GOSetup() error

GOSetup installs and configures the Go compiler if not already present.

func GetArchitecture

func GetArchitecture() string

GetArchitecture returns the system architecture mapped to package manager conventions.

func IsPrivilegedHost added in v2.1.0

func IsPrivilegedHost() bool

IsPrivilegedHost reports whether the current process is running as uid 0 (root). The installers in pkg/aptinstall and pkg/apkindex use this as the heuristic for "we're inside a yap build container and it's safe to write to /, /var/lib/dpkg, /lib/apk/db, etc.".

Non-root callers (developer workstations) hit the strict path and must either set RootDir / AllowRootInstall explicitly or run as root.

func IsRunningSudo

func IsRunningSudo() bool

IsRunningSudo returns true if yap is currently running under sudo.

func PreserveOwnership

func PreserveOwnership(path string) error

PreserveOwnership changes ownership to original user if running under sudo.

func PreserveOwnershipRecursive

func PreserveOwnershipRecursive(path string) error

PreserveOwnershipRecursive recursively changes ownership to original user if under sudo.

In container environments (detected via YAP_IN_CONTAINER=1, baked into all yap Docker images by build/deploy/generate.sh) the chown is skipped. The container's runtime user is already the intended build user, so chowning the source tree adds nothing and on overlayfs can trigger copy-up races that cause execve() of freshly-chowned scripts to return ENOEXEC (observed in k3s/Fedora CoreOS Jenkins pods).

func PullContainers

func PullContainers(distro string) error

PullContainers downloads the specified container image for the given distribution.

Types

type OSRelease

type OSRelease struct {
	ID       string
	Codename string // VERSION_CODENAME from /etc/os-release (e.g. "jammy" for Ubuntu 22.04)
}

OSRelease represents operating system release information.

func ParseOSRelease

func ParseOSRelease() (OSRelease, error)

ParseOSRelease reads and parses the /etc/os-release file. It populates ID (e.g. "ubuntu") and Codename (e.g. "jammy") from the VERSION_CODENAME field so that callers can resolve distro-codename-specific PKGBUILD directives such as depends__ubuntu_jammy.

type OriginalUser

type OriginalUser struct {
	UID  int
	GID  int
	Name string
	Home string
}

OriginalUser holds information about the original user when running under sudo.

func GetOriginalUser

func GetOriginalUser() (*OriginalUser, error)

GetOriginalUser detects if yap is running under sudo and returns original user info. Returns (nil, nil) if not running under sudo - this is not an error condition.

func (*OriginalUser) ChownRecursiveToOriginalUser

func (ou *OriginalUser) ChownRecursiveToOriginalUser(path string) error

ChownRecursiveToOriginalUser recursively changes ownership of directory to original user.

func (*OriginalUser) ChownToOriginalUser

func (ou *OriginalUser) ChownToOriginalUser(path string) error

ChownToOriginalUser changes ownership of the given path to the original user.

Jump to

Keyboard shortcuts

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