units

package
v0.0.0-...-28ebc5c Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package units implements logic to build TwitchyLinux as a series of units.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotMountpoint is returned from mountpointType if the given path
	// was not a mountpoint.
	ErrNotMountpoint = errors.New("not a mountpoint")
)

Functions

func CheckSHA256

func CheckSHA256(path, wantHash string) error

CheckSHA256 compares the hash of the file with wantHash, returning an error is a mismatch occurs.

func CmdCombined

func CmdCombined(ctx context.Context, bin string, args ...string) (string, error)

CmdCombined returns the full standard output and standard error for the invocation of the provided binary given the provided arguments.

func CmdOutput

func CmdOutput(ctx context.Context, bin string, args ...string) (string, error)

CmdOutput returns the full standard output of invoking the given binary given the provided arguments.

func CompareExtractSemver

func CompareExtractSemver(version, wantVersion string) (int, error)

CompareExtractSemver extracts a semver from the version string, returning the result of a version comparison with wantVersion.

func CopyResource

func CopyResource(ctx context.Context, opts *Opts, resourcePath, toPath string) error

CopyResource copies a file from the resource directory into the system. Both paths are relative to the resource and base system directory respectively.

func DownloadFile

func DownloadFile(ctx context.Context, opts *Opts, url, outPath string) error

DownloadFile downloads a file.

func FindBinary

func FindBinary(bin string) (string, error)

FindBinary returns the full path to the binary specified by resolving paths registered in the PATH environment variable.

func InstallConfigResources

func InstallConfigResources(ctx context.Context, opts *Opts, base, resourceDir string) error

InstallConfigResources copies config files within resourceDir into the directory at base. Both paths are relative to the resouce and base system directory respectively.

func Shell

func Shell(ctx context.Context, opts *Opts, bin string, args ...string) error

Shell runs the command, connecting standard output to the terminal.

Types

type Append

type Append struct {
	To   string
	Data string
}

Append appends a line to a file

func (*Append) Name

func (c *Append) Name() string

Name implements Unit.

func (*Append) Run

func (c *Append) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type CheckHash

type CheckHash struct {
	File         string
	ExpectedHash string
}

CheckHash represents the validation of the sha256 checksum of a file.

func (*CheckHash) Name

func (c *CheckHash) Name() string

Name implements Unit.

func (*CheckHash) Run

func (c *CheckHash) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Chroot

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

Chroot represents a directory configured to be used as a chroot.

func (*Chroot) AptInstall

func (c *Chroot) AptInstall(ctx context.Context, opts *Opts, packages ...string) error

AptInstall installs the given packages.

func (*Chroot) Close

func (c *Chroot) Close() error

Close releases all resources associated with the chroot.

func (*Chroot) CmdContext

func (c *Chroot) CmdContext(ctx context.Context, opts *Opts, bin string, args ...string) (*exec.Cmd, error)

CmdContext prepares an execution within the chroot.

func (*Chroot) Shell

func (c *Chroot) Shell(ctx context.Context, opts *Opts, bin string, args ...string) error

Shell runs a simple command within the chroot.

type Clean

type Clean struct {
}

Clean is a unit which cleans up unneeded files from the system.

func (*Clean) Name

func (i *Clean) Name() string

Name implements Unit.

func (*Clean) Run

func (i *Clean) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Cmd

type Cmd struct {
	Bin  string
	Args []string
	Env  map[string]string
}

Cmd represents the execution of a command within a chroot.

func (*Cmd) Name

func (c *Cmd) Name() string

Name implements Unit.

func (*Cmd) Run

func (c *Cmd) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Composite

type Composite struct {
	UnitName string
	Order    int
	Ops      []Unit
}

Composite is a unit made up of a sequence of simpler operations.

func (*Composite) Name

func (c *Composite) Name() string

Name implements Unit.

func (*Composite) Run

func (c *Composite) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Debootstrap

type Debootstrap struct {
	Track string
	URL   string
}

Debootstrap bootstraps the base debian system.

func (*Debootstrap) Name

func (d *Debootstrap) Name() string

Name implements Unit.

func (*Debootstrap) Run

func (d *Debootstrap) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Download

type Download struct {
	URL string
	To  string
}

Download represents the download of a file into the system.

func (*Download) Name

func (d *Download) Name() string

Name implements Unit.

func (*Download) Run

func (d *Download) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type EnableUnit

type EnableUnit struct {
	Unit, Target string
}

EnableUnit enables a systemd unit.

func (*EnableUnit) Name

func (c *EnableUnit) Name() string

Name implements Unit.

func (*EnableUnit) Run

func (c *EnableUnit) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type FileInfo

type FileInfo struct {
	Path  string
	Data  []byte
	Perms os.FileMode
}

FileInfo describes a file to be installed in the target system.

type FinalizeApt

type FinalizeApt struct {
	Track string
}

FinalizeApt configures apt into an ideal state.

func (*FinalizeApt) Name

func (u *FinalizeApt) Name() string

Name implements Unit.

func (*FinalizeApt) Run

func (u *FinalizeApt) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Gnome

type Gnome struct {
	NeedPkgs []string
}

Gnome installs the GNOME graphical environment

func (*Gnome) Name

func (d *Gnome) Name() string

Name implements Unit.

func (*Gnome) Run

func (d *Gnome) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Grub2

type Grub2 struct {
	DistroName string
	Quiet      bool

	ColorNormal    GrubColorPair
	ColorHighlight GrubColorPair
}

Grub2 is a unit which installs Grub2.

func (*Grub2) Name

func (i *Grub2) Name() string

Name implements Unit.

func (*Grub2) Run

func (i *Grub2) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type GrubColorPair

type GrubColorPair struct {
	FG, BG string
}

GrubColorPair describes a color pair in grub config.

type InstallFiles

type InstallFiles struct {
	UnitName string
	Mkdir    string
	Files    []FileInfo
}

InstallFiles installs files into the target system.

func (*InstallFiles) Name

func (i *InstallFiles) Name() string

Name implements Unit.

func (*InstallFiles) Run

func (i *InstallFiles) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type InstallTools

type InstallTools struct {
	UnitName string
	Pkgs     []string

	Order int
}

InstallTools is a unit which installs packages from apt.

func (*InstallTools) Name

func (i *InstallTools) Name() string

Name implements Unit.

func (*InstallTools) Run

func (i *InstallTools) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Installer

type Installer struct {
}

Installer is a unit which installs the graphical installer.

func (*Installer) Name

func (i *Installer) Name() string

Name implements Unit.

func (*Installer) Run

func (i *Installer) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Linux

type Linux struct {
	Version      string
	URL          string
	SHA256       string
	BuildDepPkgs []string
}

Linux is a unit that builds the Linux kernel.

func (*Linux) Name

func (l *Linux) Name() string

Name implements Unit.

func (*Linux) Run

func (l *Linux) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Locale

type Locale struct {
	Area, Zone string
	Generate   []string
	Default    string
}

Locale is a unit which sets the system locale and timezone.

func (*Locale) Name

func (d *Locale) Name() string

Name implements Unit.

func (*Locale) Run

func (d *Locale) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Logger

type Logger interface {
	Stderr() io.Writer
	Stdout() io.Writer
	SetSubstage(string)
	SetProgress(msg string, fraction float64)
}

Logger implements status reporting and logging for executing units.

type Mkdir

type Mkdir struct {
	Dir string
}

Mkdir represents the execution of mkdir on the target system.

func (*Mkdir) Name

func (c *Mkdir) Name() string

Name implements Unit.

func (*Mkdir) Run

func (c *Mkdir) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type OptPackage

type OptPackage struct {
	OptName, Version string
	DisplayName      string
	Packages         []string
}

OptPackage is a unit which installs packages from apt.

func (*OptPackage) Name

func (i *OptPackage) Name() string

Name implements Unit.

func (*OptPackage) Run

func (i *OptPackage) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Opts

type Opts struct {
	// Dir represents the path the system is being built at.
	Dir string
	// Resources is the path to the builder resources directory.
	Resources string
	// Version is the current version of TwitchyLinux.
	Version string

	// Num indicates which unit (in execution order) the unit is.
	Num int
	// L is a logger which units can use to communicate state.
	L Logger

	// NumThreads is the number of concurrent threads to be used while building.
	NumThreads int

	DebProxy string
}

Opts describes options provided to the units.

type Preflight

type Preflight struct{}

Preflight checks the building system has the requisite packages and programs installed.

func (*Preflight) Name

func (p *Preflight) Name() string

Name implements Unit.

func (*Preflight) Run

func (p *Preflight) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type ShellCustomization

type ShellCustomization struct {
	AdditionalSkel           []byte
	AdditionalProfileScripts map[string][]byte
	Users                    []UserSpec
}

ShellCustomization is a unit which customizes the accounts + shell.

func (*ShellCustomization) Name

func (d *ShellCustomization) Name() string

Name implements Unit.

func (*ShellCustomization) Run

func (d *ShellCustomization) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Systemd

type Systemd struct {
}

Systemd is a unit which installs systemd and sets up basic configuration.

func (*Systemd) Name

func (s *Systemd) Name() string

Name implements Unit.

func (*Systemd) Run

func (s *Systemd) Run(ctx context.Context, opts Opts) error

Run implements Unit.

type Unit

type Unit interface {
	Name() string
	Run(ctx context.Context, opts Opts) error
}

Unit describes an execution unit for building the system.

type UserSpec

type UserSpec struct {
	Username string
	Password string
	Groups   []string
}

UserSpec configures a user account.

Jump to

Keyboard shortcuts

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