king

package module
v0.0.0-...-157e698 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: MIT Imports: 25 Imported by: 0

README

king

Next generation of the KISS package manager

Unstable but usable. Breakage is still possible though

Dependencies

  • Go >= 1.16 (build time)

Installation

# change directory to cli sources
cd cmd/king

# build dynamic binary
go build

# build static binary
go build -tags 'osusergo netgo'

# build static binary, strip debug symbols and trim internal paths. best choice!
go build -tags 'osusergo netgo' -ldflags '-s -w' -trimpath

Documentation

Overview

Package king provides high-level interfaces to interact with kiss-compatible package system

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPackagePathNotFound = errors.New("target not owned by any package")
	ErrPackageNameNotFound = errors.New("target not found in database/repository")
)
View Source
var (
	ErrSourceGitSchemeInvalid  = errors.New("target scheme cannot be file")
	ErrSourceGitHashInvalid    = errors.New("target contains invalid commit hash")
	ErrSourceHTTPSchemeInvalid = errors.New("target scheme must be a http or https")
	ErrSourceFileNotFound      = errors.New("target not found in relative or absolute location")
)
View Source
var (
	ErrTarballNotFound   = errors.New("target has not been built yet")
	ErrTarballNotRegular = errors.New("target must be a regular file")
	ErrTarballInvalid    = errors.New("target has no separator")
)
View Source
var (
	ErrAlternativePathDirectory   = errors.New("Path cannot be a directory")
	ErrAlternativePathNotAbsolute = errors.New("Path must be absolute")
	ErrAlternativePathEmpty       = errors.New("Path must be set")

	ErrBuildCompressionNotSupported = errors.New("Compression contains an unsupported format")
	ErrBuildPackageDirEmpty         = errors.New("PackageDir must be set")
	ErrBuildBuildDirEmpty           = errors.New("BuildDir must be set")

	ErrConfigRootDirNotDirectory = errors.New("RootDir must be a directory")
	ErrConfigAlternativeDirEmpty = errors.New("AlternativeDir must be set")
	ErrConfigDatabaseDirEmpty    = errors.New("DatabaseDir must be set")
	ErrConfigSourceDirEmpty      = errors.New("SourceDir must be set")
	ErrConfigBinaryDirEmpty      = errors.New("BinaryDir must be set")

	ErrInstallExtractDirEmpty = errors.New("ExtractDir must be set")

	ErrPackagePathNameExclusive = errors.New("Path and Name are mutually exclusive")
)
View Source
var (
	ErrSha256NotRegular = errors.New("target must be a regular file")
	ErrVerifyMismatch   = errors.New("checksum mismatch")
)
View Source
var ErrAlternativeNotFound = errors.New("conflict has not been occured yet")
View Source
var ErrDownloadAlreadyExist = errors.New("target already downloaded")
View Source
var ErrInstallUnmetDependencies = errors.New("target requires other packages")
View Source
var ErrRemoveUnresolvedDependencies = errors.New("other packages depend on target")
View Source
var ErrReverseDependenciesNotFound = errors.New("no package depends on target")
View Source
var ErrVersionInvalid = errors.New("target must contain only two fields")

Functions

This section is empty.

Types

type Alternative

type Alternative struct {
	Name string
	Path string
	// contains filtered or unexported fields
}

Alternative represents conflict between multiple packages.

See https://k1sslinux.org/package-manager#3.2

func Alternatives

func Alternatives(c *Config) ([]*Alternative, error)

func NewAlternative

func NewAlternative(c *Config, ao *AlternativeOptions) (*Alternative, error)

func (*Alternative) String

func (a *Alternative) String() string

func (*Alternative) Swap

func (a *Alternative) Swap() (*Alternative, error)

type AlternativeOptions

type AlternativeOptions struct {
	Name string
	Path string
}

func (*AlternativeOptions) Validate

func (ao *AlternativeOptions) Validate() error

type BuildOptions

type BuildOptions struct {

	// Output points where build log will be written.
	Output io.Writer

	// Compression defines which compression format will be used to create tarball.
	//
	// TODO allow none format
	// Valid formats are sz, br, gz, xz, zst, bz2, lz4.
	Compression string

	// TODO mention that p.Name is appended
	// BuildDir specifies where build will happen.
	BuildDir string

	// TODO mention that p.Name is appended
	// PackageDir specifies where build script places package files
	// to turn them into tarball later.
	PackageDir string

	// Debug preserves BuildDir and PackageDir. Useful for debugging purposes.
	Debug bool
}

BuildOptions provides facilities for building package.

func (*BuildOptions) Validate

func (bo *BuildOptions) Validate() error

type Config

type Config struct {
	// Repositories contains list of user-defined repositories.
	Repositories []string

	// DatabaseDir contains path with prepended RootDir to installed packages.
	DatabaseDir string

	// AlternativeDir contains path with prepended RootDir to occurred conflicts.
	AlternativeDir string

	// BinaryDir contains path to pre-built packages.
	BinaryDir string

	// SourceDir contains path to package sources.
	SourceDir string

	// RootDir contains path to real root.
	RootDir string
	// contains filtered or unexported fields
}

Config represents in-memory copy of configuration.

See https://k1sslinux.org/package-manager#4.0 TODO embed ConfigOptions TODO add SystemPackages[musl, pkgconf, ...]

func NewConfig

func NewConfig(co *ConfigOptions) (*Config, error)

NewConfig allocates new instance of configuration.

func (*Config) ResetOwnedPaths

func (c *Config) ResetOwnedPaths()

ResetOwnedPaths resets cached manifests of installed packages.

func (*Config) ResetReverseDependencies

func (c *Config) ResetReverseDependencies()

ResetReverseDependencies resets cached reverse dependencies.

type ConfigOptions

type ConfigOptions struct {
	// Repositories contains list of user-defined repositories.
	Repositories []string

	// AlternativeDir contains path with prepended RootDir to occurred conflicts.
	AlternativeDir string

	// DatabaseDir contains path with prepended RootDir to installed packages.
	DatabaseDir string

	// BinaryDir points where pre-built packages will be located.
	BinaryDir string

	// SourceDir points where sources of packages will be downloaded.
	SourceDir string

	// RootDir intended to specify real root of filesystem. Default is '/'.
	// Useful to bootstrap new system.
	RootDir string
}

ConfigOptions allows to configure returned configuration.

func (*ConfigOptions) Validate

func (co *ConfigOptions) Validate() error

type Dependency

type Dependency struct {
	Name   string
	IsMake bool
}

Dependency represents dependency of package.

See https://k1sslinux.org/package-system#3.0

func (*Dependency) String

func (d *Dependency) String() string

type DownloadOptions

type DownloadOptions struct {
	Overwrite bool
	Progress  io.Writer
}

func (*DownloadOptions) Validate

func (do *DownloadOptions) Validate() error

type Downloader

type Downloader interface {
	Download(do *DownloadOptions) error
	DownloadContext(ctx context.Context, do *DownloadOptions) error
}

type Extractor

type Extractor interface {
	Extract(d string) error
	ExtractDir() string
}

Extractor represents interface of extractable source.

type File

type File struct {
	Path string
	// contains filtered or unexported fields
}

File represents absolute or relative (to the path of package) file source.

func (*File) Extract

func (f *File) Extract(d string) error

Extract copies file to specified directory.

func (*File) ExtractDir

func (f *File) ExtractDir() string

ExtractDir returns extraction directory (second field within sources file)

func (*File) Sha256

func (f *File) Sha256() (string, error)

func (*File) String

func (f *File) String() string

func (*File) Verify

func (f *File) Verify() error

type Git

type Git struct {
	URL string
	// contains filtered or unexported fields
}

Git represents git source.

func (*Git) Extract

func (g *Git) Extract(d string) error

Extract clones git source into specified directory.

func (*Git) ExtractDir

func (g *Git) ExtractDir() string

ExtractDir returns extraction directory (second field within sources file)

func (*Git) String

func (g *Git) String() string

type HTTP

type HTTP struct {
	URL string
	// contains filtered or unexported fields
}

HTTP represents source that can be downloaded.

func (*HTTP) Download

func (h *HTTP) Download(do *DownloadOptions) error

func (*HTTP) DownloadContext

func (h *HTTP) DownloadContext(ctx context.Context, do *DownloadOptions) error

func (*HTTP) Extract

func (h *HTTP) Extract(d string) error

Extract copies (or extracts - it depends on ?no-extract flag) source into specified directory.

func (*HTTP) ExtractDir

func (h *HTTP) ExtractDir() string

ExtractDir returns extraction directory (second field within sources file)

func (*HTTP) Sha256

func (h *HTTP) Sha256() (string, error)

func (*HTTP) String

func (h *HTTP) String() string

func (*HTTP) Verify

func (h *HTTP) Verify() error

type InstallOptions

type InstallOptions struct {
	// NoCheckDependencies forcefully installs package without
	// checking if dependencies are met.
	NoCheckDependencies bool

	// OverwriteEtcFiles overwrites /etc/* files without special handling.
	//
	// See https://k1sslinux.org/package-manager#3.3
	OverwriteEtcFiles bool

	// TODO mention that t.Name is appended
	// ExtractDir specifies where pre-built package will be extracted.
	ExtractDir string

	// Debug preserves ExtractDir. Useful for debugging purposes.
	Debug bool
}

InstallOptions provides facilities for installing package.

func (*InstallOptions) Validate

func (lo *InstallOptions) Validate() error

type Package

type Package struct {
	Name string
	Path string

	From RepositoryType
	// contains filtered or unexported fields
}

Package represents package within repository or database.

See https://k1sslinux.org/package-system#1.0

func NewPackage

func NewPackage(c *Config, po *PackageOptions) (*Package, error)

NewPackage allocates new instance of package.

func Update

func Update(c *Config, uo *UpdateOptions) ([]*Package, error)

Update optionally updates repositories and parses candidates for upgrade.

func UpdateContext

func UpdateContext(ctx context.Context, c *Config, uo *UpdateOptions) ([]*Package, error)

func (*Package) Build

func (p *Package) Build(bo *BuildOptions) (*Tarball, error)

Build builds package and turns it into installable tarball.

See https://k1sslinux.org/package-system#2.0

func (*Package) BuildContext

func (p *Package) BuildContext(ctx context.Context, bo *BuildOptions) (*Tarball, error)

func (*Package) Dependencies

func (p *Package) Dependencies() ([]*Dependency, error)

func (*Package) RecursiveDependencies

func (p *Package) RecursiveDependencies() ([]*Dependency, error)

func (*Package) Remove

func (p *Package) Remove(ro *RemoveOptions) error

Remove purges package from the system and gracefully swaps dangling alternatives if they are exist.

func (*Package) ReverseDependencies

func (p *Package) ReverseDependencies() ([]string, error)

func (*Package) Sources

func (p *Package) Sources() ([]Source, error)

Sources parses package sources. Lines that starts with '#' will be ignored.

func (*Package) String

func (p *Package) String() string

func (*Package) Tarball

func (p *Package) Tarball() (*Tarball, error)

Tarball tries to find pre-built tarball within BinaryDir.

func (*Package) Version

func (p *Package) Version() (*Version, error)

type PackageOptions

type PackageOptions struct {
	// Name defines package name that will be used to traverse
	// repositories or database.
	Name string

	// Path defines path that will be used to grep manifests files
	// within database to find owner of that path.
	Path string

	// From defines where to search package. Applies only to Name field.
	From RepositoryType
}

PackageOptions intended to configure searching of package.

func (*PackageOptions) Validate

func (po *PackageOptions) Validate() error

type RemoveOptions

type RemoveOptions struct {
	// NoCheckReverseDependencies forcefully removes package even if other
	// installed packages depends on it.
	NoCheckReverseDependencies bool

	// RemoveEtcFiles forcefully removes /etc/* files without special handling
	RemoveEtcFiles bool
}

RemoveOptions provides facilities for removing package.

type RepositoryType

type RepositoryType uint
const (
	All RepositoryType = iota
	Database
	Repository
)

func (RepositoryType) String

func (rt RepositoryType) String() string

type Source

type Source interface {
	String() string

	Extractor
}

Source represents package source. See https://k1sslinux.org/package-system#4.0

type Tarball

type Tarball struct {
	Name string
	Path string
	// contains filtered or unexported fields
}

Tarball represents pre-built package.

func NewTarball

func NewTarball(c *Config, p string) (*Tarball, error)

NewTarball allocates new instance of pre-built package.

func (*Tarball) Install

func (t *Tarball) Install(lo *InstallOptions) (*Package, error)

Install deploys pre-built package into system and carefully handles occurred conflicts.

func (*Tarball) String

func (t *Tarball) String() string

type UpdateOptions

type UpdateOptions struct {
	// NoUpdateRepositories disables updating repositories.
	NoUpdateRepositories bool

	// ContinueOnError ignores possible errors during updating repositories.
	ContinueOnError bool

	// ExcludePackages ignores update for specified packages.
	ExcludePackages []string
}

UpdateOptions provides facilities for updating repositories.

type Verifier

type Verifier interface {
	Sha256() (string, error) // TODO unexport ?
	Verify() error
}

type Version

type Version struct {
	Version string
	Release string
}

Version represents content of the version file.

See https://k1sslinux.org/package-system#5.0

func (*Version) String

func (v *Version) String() string

Directories

Path Synopsis
Package checksums provides in-memory structure for checksums file
Package checksums provides in-memory structure for checksums file
cmd
Package etcsums provides in-memory structure for etcsums file
Package etcsums provides in-memory structure for etcsums file
internal
cp
log
Package manifest provides in-memory structure for manifest file
Package manifest provides in-memory structure for manifest file

Jump to

Keyboard shortcuts

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