deb

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AdditionalControlFiles = []string{"templates", "triggers", "shlibs", "symbols"}

AdditionalControlFiles are non-executable control members accepted.

View Source
var ErrInvalidArchive = errors.New("invalid ar archive")

ErrInvalidArchive reports a malformed Unix ar archive.

View Source
var MaintainerScripts = []string{"preinst", "postinst", "prerm", "postrm", "config"}

MaintainerScripts are the only executable control members accepted.

Functions

func CompareVersions

func CompareVersions(a, b string) int

CompareVersions compares two Debian versions using dpkg semantics. It returns -1, 0 or 1 when a is lower than, equal to or greater than b.

func IsMaintainerScript

func IsMaintainerScript(name string) bool

IsMaintainerScript reports whether name is a known maintainer script.

func ParseControl

func ParseControl(data []byte) (*Control, *Fields, error)

ParseControl parses a control stanza into typed fields.

func RelationName

func RelationName(relation string) (string, string)

RelationName extracts the package name and version constraint from a dependency relation such as "libc6 (>= 2.38) [amd64]" or "foo | bar".

func SplitDescription

func SplitDescription(value string) (string, string)

SplitDescription separates the synopsis from the extended description.

func SplitRelations

func SplitRelations(value string) []string

SplitRelations splits a comma separated dependency field.

Types

type Archive

type Archive struct {
	Control            Control
	Fields             []Field
	RawControl         []byte
	Members            []Member
	Entries            []Entry
	MD5Sums            map[string]string
	Conffiles          []string
	Scripts            map[string]Script
	ControlFiles       map[string]Script
	ControlCompression Compression
	DataCompression    Compression
	DebianBinary       string
	Size               int64
	MD5                string
	SHA1               string
	SHA256             string
}

Archive is a parsed binary package.

func Read

func Read(r io.Reader) (*Archive, error)

Read parses a .deb stream.

func ReadFile

func ReadFile(name string) (*Archive, error)

ReadFile parses a .deb from disk.

func (*Archive) AuditMD5

func (a *Archive) AuditMD5() MDAudit

AuditMD5 compares declared checksums with the payload.

func (*Archive) File

func (a *Archive) File(entryPath string) (Entry, bool)

File returns the payload entry at path, if present.

func (*Archive) Script

func (a *Archive) Script(name string) (Script, bool)

Script returns a maintainer script by name.

type Compression

type Compression string

Compression identifies a tar payload compressor supported by dpkg.

const (
	CompressionGzip  Compression = "gzip"
	CompressionZstd  Compression = "zstd"
	CompressionXz    Compression = "xz"
	CompressionBzip2 Compression = "bzip2"
)

Supported compressors. bzip2 is accepted when reading but never written.

func CompressionFromMember

func CompressionFromMember(name string) (Compression, bool)

CompressionFromMember detects the compressor from a tar member name.

func ParseCompression

func ParseCompression(value string) (Compression, error)

ParseCompression validates a user supplied compressor name.

func (Compression) Ext

func (c Compression) Ext() string

Ext returns the file extension used in member names.

func (Compression) TarName

func (c Compression) TarName(base string) string

TarName returns a member name such as "data.tar.zst".

func (Compression) Writable

func (c Compression) Writable() bool

Writable reports whether this compressor can be used for new packages.

type Control

type Control struct {
	Package       string
	Source        string
	Version       string
	Architecture  string
	Maintainer    string
	InstalledSize int64
	Section       string
	Priority      string
	MultiArch     string
	Essential     bool
	Homepage      string
	Description   string
	Extended      string
	PreDepends    []string
	Depends       []string
	Recommends    []string
	Suggests      []string
	Enhances      []string
	Breaks        []string
	Conflicts     []string
	Replaces      []string
	Provides      []string
	BuiltUsing    string
	Extra         map[string]string
}

Control is the binary package metadata kept in control.tar.

func (*Control) Fields

func (c *Control) Fields() *Fields

Fields renders the control stanza in canonical field order.

func (*Control) Render

func (c *Control) Render() []byte

Render serialises the control stanza.

type Entry

type Entry struct {
	Path     string
	IsDir    bool
	Mode     fs.FileMode
	Size     int64
	Link     string
	Typeflag byte
	UID      int
	GID      int
	Uname    string
	Gname    string
	MD5      string
	ModTime  time.Time
}

Entry is one data.tar member.

type Field

type Field struct {
	Name  string
	Value string
}

Field is a single deb822 control field.

type Fields

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

Fields preserves the order of deb822 fields.

func NewFields

func NewFields() *Fields

NewFields returns an empty field set.

func ParseFields

func ParseFields(data []byte) (*Fields, error)

ParseFields parses the first deb822 stanza in data. Any trailing stanzas are ignored; every caller in debsmith works with single-stanza documents.

func (*Fields) All

func (f *Fields) All() []Field

All returns a copy of the fields in order.

func (*Fields) Delete

func (f *Fields) Delete(name string)

Delete removes a field.

func (*Fields) Get

func (f *Fields) Get(name string) string

Get returns the value of a field, case-insensitively.

func (*Fields) Has

func (f *Fields) Has(name string) bool

Has reports whether a field exists.

func (*Fields) Len

func (f *Fields) Len() int

Len reports the number of fields.

func (*Fields) Render

func (f *Fields) Render() []byte

Render serialises the fields as a deb822 stanza.

func (*Fields) Set

func (f *Fields) Set(name, value string)

Set inserts or replaces a field, preserving its position.

type File

type File struct {
	Path  string
	IsDir bool
	Mode  fs.FileMode
	Data  []byte
	Link  string
}

File is a single payload entry of a binary package.

type MDAudit

type MDAudit struct {
	MissingSums  []string
	MissingFiles []string
	Mismatched   []string
}

MDAudit lists checksum integrity problems.

type Member

type Member struct {
	Name    string
	Size    int64
	Mode    int64
	ModTime int64
}

Member describes one ar member of a .deb file.

type Options

type Options struct {
	Compression        Compression
	ControlCompression Compression
	Epoch              time.Time
}

Options controls archive layout and compression.

type Package

type Package struct {
	Control      Control
	Files        []File
	Conffiles    []string
	Scripts      map[string][]byte
	ControlFiles map[string][]byte
}

Package is the complete input of a .deb build.

type Script

type Script struct {
	Data []byte
	Mode fs.FileMode
}

Script is a control member with its mode.

type Summary

type Summary struct {
	Files         int
	InstalledSize int64
	DataSize      int64
	ControlSize   int64
	TotalSize     int64
	MD5Sums       map[string]string
}

Summary reports what was written.

func Write

func Write(w io.Writer, pkg *Package, opts Options) (Summary, error)

Write builds a binary package and writes it to w.

Jump to

Keyboard shortcuts

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