Documentation
¶
Overview ¶
Package pack writes rpm packages. It is pure Go and needs no rpmbuild.
Describe the package with RPMMetaData, create it with NewRPM, add the files with RPM.AddFile (or RPM.AddFS) and the scripts with RPM.AddScriptlet, RPM.AddTrigger and RPM.AddFileTrigger, and write the result with RPM.Write:
r, err := pack.NewRPM(pack.RPMMetaData{Name: "example", Version: "3", Release: "1"})
if err != nil { ... }
r.AddFile(pack.RPMFile{Name: "/usr/local/hello", Body: []byte("hello"), Mode: 0o644})
err = r.Write(w)
Streaming ¶
The content of a file is a byte slice (Body), an io.Reader of a known Size, a function that opens it (Open) or a path of the file system. Write compresses the payload into a temporary file (RPMMetaData.TempDir), because the header of an rpm precedes the payload and needs its digests and sizes, so memory use does not depend on the size of the package.
What is written ¶
- Scriptlets with interpreter arguments, flags (expand, qformat, critical) and Lua; pretrans, posttrans, preuntrans, postuntrans and verify scripts.
- Package triggers, file triggers and transaction file triggers with priorities, laid out as rpmbuild lays them out.
- Hard links (content is stored once, also in the v6 stripped cpio), devices, fifos and sockets, file capabilities, verify flags, languages, classes, file dependencies, ghost, config, doc, license, readme, artifact files.
- The file digest algorithms SHA-256, SHA-512, SHA3-256 and SHA3-512.
- Every kind of dependency, with its scope and the rich (boolean) syntax checked, and the rpmlib() requirements that follow from the features used.
- Header metadata: prefixes, changelog, translations, sysusers, modularity label, dist tag, vcs, bug url, source rpm, platform and more.
- Signatures of the package (SetPGPSigner) and of the files (SetFileSigning: IMA and fs-verity).
Set RPMMetaData.Format to FormatV6 to write the format of rpm 6.0 instead of the default FormatV4.
FromTar builds a package from a tar archive; the tar2rpm command in github.com/M0Rf30/pkgformat/cmd/tar2rpm is a front end for it.
Index ¶
- Constants
- Variables
- func ValidateRich(s string) error
- type AddFSOptions
- type ChangelogEntry
- type FileSigning
- type FileTrigger
- type FileTriggerKind
- type FileType
- type IndexEntry
- func EntryBytes(value []byte) IndexEntry
- func EntryInt16(value []int16) IndexEntry
- func EntryInt32(value []int32) IndexEntry
- func EntryInt64(value []int64) IndexEntry
- func EntryString(value string) IndexEntry
- func EntryStringSlice(value []string) IndexEntry
- func EntryUint16(value []uint16) IndexEntry
- func EntryUint32(value []uint32) IndexEntry
- func EntryUint64(value []uint64) IndexEntry
- type RPM
- func (r *RPM) AddCustomSig(tag int, e IndexEntry)
- func (r *RPM) AddCustomTag(tag int, e IndexEntry)
- func (r *RPM) AddFS(fsys fs.FS, opts AddFSOptions) error
- func (r *RPM) AddFile(f RPMFile)
- func (r *RPM) AddFileTrigger(t FileTrigger)
- func (r *RPM) AddPostin(s string)
- func (r *RPM) AddPosttrans(s string)
- func (r *RPM) AddPostun(s string)
- func (r *RPM) AddPostuntrans(s string)
- func (r *RPM) AddPrein(s string)
- func (r *RPM) AddPretrans(s string)
- func (r *RPM) AddPreun(s string)
- func (r *RPM) AddPreuntrans(s string)
- func (r *RPM) AddScriptlet(kind ScriptKind, s Scriptlet)
- func (r *RPM) AddTrigger(t Trigger)
- func (r *RPM) AddVerifyScript(s string)
- func (r *RPM) AllowListDirs(allowList map[string]bool)
- func (r *RPM) FullVersion() string
- func (r *RPM) SetFileSigning(s FileSigning)
- func (r *RPM) SetPGPSigner(f Signer)
- func (r *RPM) Write(w io.Writer) error
- type RPMFile
- type RPMMetaData
- type Relation
- type Relations
- type ScriptFlags
- type ScriptKind
- type Scriptlet
- type Sense
- type Signer
- type Translation
- type Trigger
- type TriggerKind
- type VerifyFlags
Examples ¶
Constants ¶
const ( ModeSocket uint = 0140000 ModeBlock uint = 060000 ModeChar uint = 020000 ModeFifo uint = 010000 )
The file type bits of RPMFile.Mode in addition to the regular file, directory and symlink types.
const ( // DigestSHA256 is the default file digest algorithm. DigestSHA256 = 8 // DigestSHA512 selects SHA-512. DigestSHA512 = 10 // DigestSHA3256 selects SHA3-256. DigestSHA3256 = 12 // DigestSHA3512 selects SHA3-512. DigestSHA3512 = 14 )
File digest algorithms of rpm (the values of FILEDIGESTALGO).
const ( // FormatV4 selects the classic RPM v4 package format. It is the default. FormatV4 = 4 // FormatV6 selects the RPM v6 package format written by rpm >= 6.0. FormatV6 = 6 )
const DefaultInterpreter = "/bin/sh"
DefaultInterpreter runs scriptlets that name no interpreter.
const DefaultTriggerPriority = 1000000
DefaultTriggerPriority is the priority of file triggers that set none.
const LuaInterpreter = "<lua>"
LuaInterpreter selects the Lua interpreter built into rpm.
const ( // NoEpoch skips adding the epoch tag to the RPM. // // We decided to use this approach instead of making epoch a *uint32 to // avoid a breaking change. // For reference, this is the max uint32 value, which is 4294967295. NoEpoch = ^uint32(0) )
const VerifyAll = VerifyDigest | VerifySize | VerifyLinkTo | VerifyUser | VerifyGroup | VerifyMTime | VerifyMode | VerifyRdev | VerifyCaps | VerifyContexts
VerifyAll is the union of all the verify flags.
Variables ¶
var ( // ErrWriteAfterClose is returned when a user calls Write() on a closed rpm. ErrWriteAfterClose = errors.New("rpm write after close") // ErrWrongFileOrder is returned when files are not sorted by name. ErrWrongFileOrder = errors.New("wrong file addition order") // ErrInvalidFile is returned by Write when a file added with AddFile cannot be // represented in an rpm: a name that is not a clean absolute path, embedded NUL // bytes, mode bits outside the 16 bit rpm file mode, an inconsistent content // source or hard link, or (for the v4 format) a body larger than the 4 GiB limit // of the cpio payload. ErrInvalidFile = errors.New("invalid rpm file") // ErrInvalidMetadata is returned by Write when a package metadata value cannot // be represented in the rpm header: strings with embedded NUL bytes, nil // relations, or times outside the unsigned 32 bit range rpm stores. ErrInvalidMetadata = errors.New("invalid rpm metadata") )
var ErrFileSigning = errors.New("rpm file signing")
ErrFileSigning is returned for IMA and fs-verity signing failures: a missing key or certificate, or a file digest algorithm that cannot be signed.
var ErrHeaderTooLarge = header.ErrHeaderTooLarge
ErrHeaderTooLarge is returned when a header does not fit the 31 bit offsets and counts of the rpm header format.
var ErrInvalidCompressor = errors.New("invalid rpm payload compressor")
ErrInvalidCompressor is returned for a compressor setting that rpm packages cannot use.
var ErrInvalidDigest = errors.New("unsupported rpm file digest algorithm")
ErrInvalidDigest is returned for a file digest algorithm rpm does not support.
var ErrInvalidRelation = errors.New("invalid rpm dependency")
ErrInvalidRelation is returned for dependencies that cannot be parsed or that are malformed boolean ("rich") dependencies.
var ErrInvalidScript = errors.New("invalid rpm scriptlet")
ErrInvalidScript is returned by Write for scriptlets, triggers and file triggers that cannot be represented in an rpm header.
Functions ¶
func ValidateRich ¶ added in v0.4.0
ValidateRich checks that s is a well formed boolean dependency in the syntax rpm accepts: a parenthesized expression of operands joined by a chain of "and", "or", "with" or "without" (chains do not mix without parentheses), or "if"/"unless" with an optional "else". An operand is a name with an optional comparison and version, or a nested expression. Names may contain balanced parentheses, as in "perl(Foo)". It checks the syntax only: rpm further limits where "if" and "unless" may appear depending on the kind of dependency, which Write enforces for each list.
Types ¶
type AddFSOptions ¶ added in v0.4.0
type AddFSOptions struct {
// Dir is the directory of fsys that is added. The default is ".".
Dir string
// Prefix is the directory of the package the files are placed in. The
// default is "/".
Prefix string
// Owner and Group own the files. The default is root.
Owner, Group string
// Type is set on every regular file.
Type FileType
// SkipDirs leaves out the directories, adding only files and symlinks.
SkipDirs bool
}
AddFSOptions are the options of AddFS.
type ChangelogEntry ¶
ChangelogEntry represents a single entry in the RPM changelog.
type FileSigning ¶ added in v0.4.0
type FileSigning struct {
// IMAKey signs the file digests for the Linux IMA appraisal (the
// security.ima extended attribute). The signatures use the digest
// algorithm of the package files, which must be SHA-256 or SHA-512.
IMAKey *rsa.PrivateKey
// VerityKey and VerityCert sign the fs-verity digest of every file with a
// detached PKCS#7 signature, as fsverity-utils and rpmsign produce. The
// certificate names the key: its issuer and serial number identify the signer.
VerityKey *rsa.PrivateKey
VerityCert *x509.Certificate
}
FileSigning holds the keys that sign every file of a package while it is written, as "rpmsign --signfiles" and "rpmsign --signverity" do afterwards.
type FileTrigger ¶ added in v0.4.0
type FileTrigger struct {
Kind FileTriggerKind
Transaction bool
// Prefixes are the absolute directories that fire the trigger.
Prefixes []string
// Priority orders the triggers; lower runs first. Zero selects
// DefaultTriggerPriority.
Priority int32
// Script is the trigger script. Its interpreter cannot have arguments.
Script Scriptlet
}
FileTrigger is a scriptlet that runs when files below one of its prefixes are installed or removed (%filetriggerin and friends), or, with Transaction set, once at the end of the transaction (%transfiletriggerin and friends).
type FileTriggerKind ¶ added in v0.4.0
type FileTriggerKind int
FileTriggerKind selects when a file trigger runs.
const ( // FileTriggerIn runs when files below a prefix were installed. FileTriggerIn FileTriggerKind = iota // FileTriggerUn runs when files below a prefix are about to be removed. FileTriggerUn // FileTriggerPostun runs when files below a prefix were removed. FileTriggerPostun )
The kinds of file triggers.
type FileType ¶
type FileType int32
FileType is the type of a file inside a RPM package.
const ( // GenericFile is just a basic file in an RPM GenericFile FileType = 1 << iota >> 1 // ConfigFile is a configuration file, and an existing file should be saved during a // package upgrade operation and not removed during a package removal operation. ConfigFile // DocFile is a file that contains documentation. DocFile // DoNotUseFile is reserved for future use; conforming packages may not use this flag. DoNotUseFile // MissingOkFile need not exist on the installed system. MissingOkFile // NoReplaceFile similar to the ConfigFile, this flag indicates that during an upgrade operation // the original file on the system should not be altered. NoReplaceFile // SpecFile is the package specification file. SpecFile // GhostFile is not actually included in the payload, but should still be considered as a part of the package. // For example, a log file generated by the application at run time. GhostFile // LicenceFile contains the license conditions. LicenceFile // ReadmeFile contains high level notes about the package. ReadmeFile // ExcludeFile is not a part of the package, and should not be installed. ExcludeFile )
https://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/pkgformat.html#AEN27560 The RPMFile.Type tag value shall identify various characteristics of the file in the payload that it describes. It shall be an INT32 value consisting of either the value GenericFile (0) or the bitwise inclusive or of one or more of the following values. Some of these combinations may make no sense
const ArtifactFile FileType = tag.RPMFILE_ARTIFACT
ArtifactFile is a file that is a build artifact, such as a build id link (%artifact).
type IndexEntry ¶
IndexEntry represents an RPM header index entry containing type, count, and data. Create it with the Entry* functions.
func EntryBytes ¶
func EntryBytes(value []byte) IndexEntry
EntryBytes creates an IndexEntry from a byte slice.
func EntryInt16 ¶
func EntryInt16(value []int16) IndexEntry
EntryInt16 creates an IndexEntry from a slice of int16 values.
func EntryInt32 ¶
func EntryInt32(value []int32) IndexEntry
EntryInt32 creates an IndexEntry from a slice of int32 values.
func EntryInt64 ¶
func EntryInt64(value []int64) IndexEntry
EntryInt64 creates an IndexEntry from a slice of int64 values (RPM INT64 type, used by RPM v6).
func EntryString ¶
func EntryString(value string) IndexEntry
EntryString creates an IndexEntry from a string value.
func EntryStringSlice ¶
func EntryStringSlice(value []string) IndexEntry
EntryStringSlice creates an IndexEntry from a slice of strings.
func EntryUint16 ¶
func EntryUint16(value []uint16) IndexEntry
EntryUint16 creates an IndexEntry from a slice of uint16 values.
func EntryUint32 ¶
func EntryUint32(value []uint32) IndexEntry
EntryUint32 creates an IndexEntry from a slice of uint32 values.
func EntryUint64 ¶
func EntryUint64(value []uint64) IndexEntry
EntryUint64 creates an IndexEntry from a slice of uint64 values (RPM INT64 type, used by RPM v6).
type RPM ¶
type RPM struct {
RPMMetaData
// contains filtered or unexported fields
}
RPM holds the state of a particular rpm file. Please use NewRPM to instantiate it.
func FromTar ¶
func FromTar(inp io.Reader, md RPMMetaData) (*RPM, error)
FromTar reads a tar file and creates an rpm struct.
The tar is treated as untrusted. Regular files, directories and symlinks are supported; PAX global headers are skipped and any other entry type is an error. Entry names are resolved against "/" with path.Join, so "../" sequences cannot escape the root of the package. Only the permission bits (including setuid, setgid and sticky) of the tar mode are used: the file type comes from the tar entry type, never from mode bits. Symlink targets are stored as they are. The content of the files is read into memory, as a tar archive is a stream that cannot be read twice; to package a large tree use RPM.AddFS instead.
func NewRPM ¶
func NewRPM(m RPMMetaData) (*RPM, error)
NewRPM creates and returns a new RPM struct.
Example ¶
A minimal package with one file. Set Format: pack.FormatV6 to write the RPM v6 format instead of v4.
package main
import (
"bytes"
"fmt"
"log"
"github.com/M0Rf30/pkgformat/rpm/pack"
)
func main() {
r, err := pack.NewRPM(pack.RPMMetaData{Name: "example", Version: "3", Release: "1"})
if err != nil {
log.Fatal(err)
}
r.AddFile(pack.RPMFile{
Name: "/usr/local/hello",
Body: []byte("content of the file"),
Mode: 0o644,
Owner: "root",
Group: "root",
})
var w bytes.Buffer // any io.Writer, for example an *os.File
if err := r.Write(&w); err != nil {
log.Fatal(err)
}
// Every rpm starts with the lead magic.
fmt.Printf("% x\n", w.Bytes()[:4])
}
Output: ed ab ee db
func (*RPM) AddCustomSig ¶
func (r *RPM) AddCustomSig(tag int, e IndexEntry)
AddCustomSig adds or overwrites a signature tag value.
func (*RPM) AddCustomTag ¶
func (r *RPM) AddCustomTag(tag int, e IndexEntry)
AddCustomTag adds or overwrites a tag value in the index.
func (*RPM) AddFS ¶ added in v0.4.0
func (r *RPM) AddFS(fsys fs.FS, opts AddFSOptions) error
AddFS adds the files below opts.Dir of fsys. The content of regular files is streamed from fsys when the package is written, so large trees do not need to fit in memory. Only regular files, directories and symlinks are supported by io/fs file systems; a symlink is added when fsys implements fs.ReadLinkFS.
Example ¶
AddFS streams the files of an fs.FS (here an in-memory one; os.DirFS works the same) into the package: their content is never held in memory, and the compressed payload is spooled to a temporary file, so packages larger than memory can be written.
package main
import (
"fmt"
"io"
"log"
"strings"
"testing/fstest"
"github.com/M0Rf30/pkgformat/rpm/pack"
)
func main() {
r, err := pack.NewRPM(pack.RPMMetaData{Name: "tree", Version: "1", Release: "1", ImplicitDirs: true})
if err != nil {
log.Fatal(err)
}
fsys := fstest.MapFS{"bin/tool": {Data: []byte("#!/bin/sh\n"), Mode: 0o755}}
if err := r.AddFS(fsys, pack.AddFSOptions{Prefix: "/opt/tree"}); err != nil {
log.Fatal(err)
}
// A file can also come from any reader of a known size, or from a path.
r.AddFile(pack.RPMFile{Name: "/opt/tree/big", Reader: strings.NewReader("streamed"), Size: 8})
if err := r.Write(io.Discard); err != nil {
log.Fatal(err)
}
fmt.Println("written")
}
Output: written
func (*RPM) AddFileTrigger ¶ added in v0.4.0
func (r *RPM) AddFileTrigger(t FileTrigger)
AddFileTrigger adds a file trigger.
func (*RPM) AddPosttrans ¶
AddPosttrans adds a posttrans scriptlet
func (*RPM) AddPostuntrans ¶ added in v0.4.0
AddPostuntrans adds a postuntrans scriptlet
func (*RPM) AddPreuntrans ¶ added in v0.4.0
AddPreuntrans adds a preuntrans scriptlet
func (*RPM) AddScriptlet ¶ added in v0.4.0
func (r *RPM) AddScriptlet(kind ScriptKind, s Scriptlet)
AddScriptlet sets the scriptlet of the given kind, replacing the previous one.
func (*RPM) AddTrigger ¶ added in v0.4.0
AddTrigger adds a trigger. Triggers keep the order they were added in.
Example ¶
Scriptlets run with an interpreter and arguments, and triggers fire on other packages or on files.
package main
import (
"fmt"
"io"
"log"
"github.com/M0Rf30/pkgformat/rpm/pack"
)
func main() {
r, err := pack.NewRPM(pack.RPMMetaData{Name: "hooks", Version: "1", Release: "1"})
if err != nil {
log.Fatal(err)
}
r.AddScriptlet(pack.ScriptPostin, pack.Scriptlet{
Script: "echo installed",
Interpreter: []string{"/bin/sh", "-e"},
Flags: pack.ScriptExpand,
})
r.AddScriptlet(pack.ScriptPretrans, pack.Scriptlet{Script: `print("hello")`, Interpreter: []string{pack.LuaInterpreter}})
dep, err := pack.NewRelation("openssl >= 3")
if err != nil {
log.Fatal(err)
}
r.AddTrigger(pack.Trigger{Kind: pack.TriggerIn, Conditions: pack.Relations{dep}, Script: pack.Scriptlet{Script: "ldconfig"}})
r.AddFileTrigger(pack.FileTrigger{Kind: pack.FileTriggerIn, Prefixes: []string{"/usr/lib64"}, Priority: 100,
Script: pack.Scriptlet{Script: "ldconfig"}})
if err := r.Write(io.Discard); err != nil {
log.Fatal(err)
}
fmt.Println("written")
}
Output: written
func (*RPM) AddVerifyScript ¶
AddVerifyScript adds a verifyscript scriptlet
func (*RPM) AllowListDirs ¶
AllowListDirs removes all directories which are not explicitly allowlisted.
func (*RPM) FullVersion ¶
FullVersion properly combines version and release fields to a version string
func (*RPM) SetFileSigning ¶ added in v0.4.0
func (r *RPM) SetFileSigning(s FileSigning)
SetFileSigning enables the IMA and fs-verity signatures of the files.
Example ¶
IMA and fs-verity signatures of the files are made while the package is written, as rpmsign --signfiles --signverity would do afterwards.
package main
import (
"crypto/rand"
"crypto/rsa"
"fmt"
"io"
"log"
"github.com/M0Rf30/pkgformat/rpm/pack"
)
func main() {
key, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
log.Fatal(err)
}
r, err := pack.NewRPM(pack.RPMMetaData{Name: "signed", Version: "1", Release: "1"})
if err != nil {
log.Fatal(err)
}
r.AddFile(pack.RPMFile{Name: "/usr/bin/tool", Body: []byte("binary"), Mode: 0o755})
r.SetFileSigning(pack.FileSigning{IMAKey: key})
if err := r.Write(io.Discard); err != nil {
log.Fatal(err)
}
fmt.Println("signed")
}
Output: signed
func (*RPM) SetPGPSigner ¶
SetPGPSigner registers a function that will read the header, or the header and the payload, and return a signature as bytes. The function should simulate what gpg does, probably by using golang.org/x/crypto/openpgp or by running a gpg process. The data is streamed, so it can be larger than the memory.
func (*RPM) Write ¶
Write closes the rpm and writes the whole rpm to an io.Writer. The payload is compressed into a temporary file while the files are read, so that packages larger than the memory can be written; only the headers are held in memory.
Example (InvalidFile) ¶
package main
import (
"bytes"
"fmt"
"log"
"github.com/M0Rf30/pkgformat/rpm/pack"
)
func main() {
r, err := pack.NewRPM(pack.RPMMetaData{Name: "example", Version: "3"})
if err != nil {
log.Fatal(err)
}
// Names must be clean absolute paths.
r.AddFile(pack.RPMFile{Name: "usr/../etc/passwd", Body: []byte("x")})
err = r.Write(&bytes.Buffer{})
fmt.Println(err)
}
Output: invalid rpm file: name "usr/../etc/passwd" is not a clean absolute path
type RPMFile ¶
type RPMFile struct {
// Name is the clean absolute path of the file in the package.
Name string
// Body is the content of a regular file, or the target of a symlink.
Body []byte
// Reader is a one-shot source of the content, which must produce exactly Size
// bytes. The content is streamed, not buffered.
Reader io.Reader
// Open opens the content, which must be exactly Size bytes. It is called at most
// once, by Write.
Open func() (io.ReadCloser, error)
// Size is the length of the content from Reader and Open. It is not used with
// the other sources.
Size int64
// Path is a file of the host that holds the content. It is opened by Write and
// its size at that time is the size of the file in the package.
Path string
// Mode holds the permission bits and the file type: a regular file when no
// type bit is set, otherwise 040000 (directory), 0120000 (symlink), ModeFifo,
// ModeSocket, ModeChar or ModeBlock.
Mode uint
Owner string
Group string
MTime uint32
Type FileType
// Hardlink names another file of the package that this file is a hard link
// to. The files then share one inode and the payload stores their content
// once, as rpm requires.
Hardlink string
// Major and Minor are the device numbers of a character or block device.
Major, Minor uint32
// VerifyExclude lists the attributes rpm --verify skips (%verify(not ...)).
VerifyExclude VerifyFlags
// Lang is the language of the file (%lang).
Lang string
// Class is the description of the file type, as file(1) reports it. It is
// stored in the class dictionary of v4 packages.
Class string
// Caps is the text form of the file capabilities (%caps), for example
// "cap_net_raw=ep".
Caps string
// Color is the ELF color of the file: 1 for 32 bit and 2 for 64 bit objects.
Color uint32
// Provides and Requires are the dependencies found in this file, which are
// also package dependencies. They are recorded in the file dependency
// tags so that rpm knows what a file brings.
Provides, Requires Relations
}
RPMFile contains a particular file's entry and data.
The content of a regular file comes from exactly one of Body, Reader, Open or Path; a file without any of them is empty. A symlink holds its target in Body. A hard link has no content of its own: set Hardlink to the name of the file it shares the content with.
Example (Hardlink) ¶
Hard links share their content, which is stored once in the payload.
package main
import (
"fmt"
"io"
"log"
"github.com/M0Rf30/pkgformat/rpm/pack"
)
func main() {
r, err := pack.NewRPM(pack.RPMMetaData{Name: "links", Version: "1", Release: "1", Format: pack.FormatV6})
if err != nil {
log.Fatal(err)
}
r.AddFile(pack.RPMFile{Name: "/usr/bin/tool", Body: []byte("binary"), Mode: 0o755})
r.AddFile(pack.RPMFile{Name: "/usr/bin/tool-alias", Hardlink: "/usr/bin/tool", Mode: 0o755})
if err := r.Write(io.Discard); err != nil {
log.Fatal(err)
}
fmt.Println("written")
}
Output: written
type RPMMetaData ¶
type RPMMetaData struct {
Name,
Summary,
Description,
Version,
Release,
Arch,
OS,
Vendor,
URL,
Packager,
Group,
Licence,
BuildHost,
Compressor string
Epoch uint32
BuildTime time.Time
// Format selects the package format: FormatV4 (the default, also selected by
// the zero value) or FormatV6 for the RPM v6 format written by rpm >= 6.0.
// NewRPM fails for any other value.
Format int
// Prefixes is used for relocatable packages, usually with a one item
// slice, e.g. `["/opt"]`.
Prefixes []string
// Distribution is the name of the distribution (e.g. "Fedora", "openSUSE").
Distribution string
// DistTag is the distribution tag of the release, e.g. ".fc43".
DistTag string
// DistURL is the URL of the distribution.
DistURL string
// BugURL is the URL for reporting bugs.
BugURL string
// VCS is the location of the source repository of the package.
VCS string
// SourceRPM is the file name of the source package. The default is
// "name-version-release.src.rpm".
SourceRPM string
// BuildArchs lists the architectures the source package builds for.
BuildArchs []string
// Platform is the platform the package was built for, e.g. "x86_64-redhat-linux".
Platform string
// OptFlags are the compiler flags of the build.
OptFlags string
// Cookie identifies the build.
Cookie string
// ModularityLabel is the "name:stream:version:context" of the module the
// package belongs to.
ModularityLabel string
// TranslationURL is the location of the translations of the package.
TranslationURL string
// Sysusers are the lines of the systemd-sysusers configuration the package
// installs. The users and groups they create are provided as user(name) and
// group(name).
Sysusers []string
// Translations holds the summary, description and group per language.
Translations map[string]Translation
// Changelog is the list of changelog entries, newest first.
Changelog []ChangelogEntry
// FileDigestAlgo selects the digest of the files: DigestSHA256 (the default,
// also selected by zero), DigestSHA512, DigestSHA3256 or DigestSHA3512.
FileDigestAlgo int
// ClampTime, when set, is the latest time recorded in the package: file
// modification times and the build time after it are set to it, which
// makes packages reproducible, as SOURCE_DATE_EPOCH does for rpmbuild.
ClampTime time.Time
// ImplicitDirs adds the missing parent directories of all files as owned
// directories (mode 0755, owned by root), so that the package owns the whole
// tree it installs.
ImplicitDirs bool
// OwnerDeps adds a requirement for user(name) and group(name) of every file
// owner other than root, as rpmbuild does.
OwnerDeps bool
// TempDir is where the compressed payload is held while the package is
// written. The default is the directory for temporary files of the system.
TempDir string
Provides,
Obsoletes,
Suggests,
Recommends,
Requires,
Conflicts,
Enhances,
Supplements,
OrderWithRequires Relations
}
RPMMetaData contains meta info about the whole package.
Example (Reproducible) ¶
A reproducible package: file times are clamped and the build time is fixed.
package main
import (
"bytes"
"fmt"
"log"
"time"
"github.com/M0Rf30/pkgformat/rpm/pack"
)
func main() {
epoch := time.Unix(1700000000, 0)
build := func() []byte {
r, err := pack.NewRPM(pack.RPMMetaData{Name: "repro", Version: "1", Release: "1", BuildTime: epoch, BuildHost: "builder", ClampTime: epoch})
if err != nil {
log.Fatal(err)
}
r.AddFile(pack.RPMFile{Name: "/f", Body: []byte("x"), MTime: uint32(time.Now().Unix())})
var b bytes.Buffer
if err := r.Write(&b); err != nil {
log.Fatal(err)
}
return b.Bytes()
}
fmt.Println(bytes.Equal(build(), build()))
}
Output: true
type Relation ¶
Relation is the structure of rpm sense relationships.
func NewRelation ¶
NewRelation parses a dependency of the form "name", "name = 1.0", "name >= 1.0" or a boolean dependency such as "(a or (b if c))". Boolean dependencies are validated with the grammar of rpm: see ValidateRich.
type Relations ¶
type Relations []*Relation
Relations is a slice of Relation pointers
func (*Relations) AddToIndex ¶
AddToIndex add the relations to the specified category on the index
type ScriptFlags ¶ added in v0.4.0
type ScriptFlags uint32
ScriptFlags are the flags of a scriptlet (RPMSCRIPT_FLAG_*).
const ( // ScriptExpand expands macros in the script when the package is installed (%post -e). ScriptExpand ScriptFlags = tag.RPMSCRIPT_FLAG_EXPAND // ScriptQFormat expands header query format tags in the script (%post -q). ScriptQFormat ScriptFlags = tag.RPMSCRIPT_FLAG_QFORMAT // ScriptCritical makes a failure of the script abort the transaction. ScriptCritical ScriptFlags = tag.RPMSCRIPT_FLAG_CRITICAL )
type ScriptKind ¶ added in v0.4.0
type ScriptKind int
ScriptKind selects the stage of a scriptlet.
const ( ScriptPretrans ScriptKind = iota ScriptPrein ScriptPostin ScriptPreun ScriptPostun ScriptPosttrans ScriptPreuntrans ScriptPostuntrans ScriptVerify )
The stages of scriptlets, in the order rpm documents them.
func (ScriptKind) String ¶ added in v0.4.0
func (k ScriptKind) String() string
String returns the name of the scriptlet as rpm calls it, e.g. "posttrans".
type Scriptlet ¶ added in v0.4.0
type Scriptlet struct {
// Script is the body of the script. It may be empty when the interpreter
// alone does the work, as for "%post -p /sbin/ldconfig".
Script string
// Interpreter is the interpreter and its arguments, for example
// {"/bin/sh", "-e"}. An empty value selects DefaultInterpreter and
// {LuaInterpreter} the Lua of rpm. Triggers and file triggers cannot
// have interpreter arguments.
Interpreter []string
// Flags are the expand, query format and critical flags.
Flags ScriptFlags
}
Scriptlet is a script with its interpreter.
type Sense ¶ added in v0.4.0
type Sense uint32
Sense is the flags word of a dependency: the version comparison and the scope the dependency applies to.
const ( SenseAny Sense = tag.RPMSENSE_ANY SenseLess Sense = tag.RPMSENSE_LESS SenseGreater Sense = tag.RPMSENSE_GREATER SenseEqual Sense = tag.RPMSENSE_EQUAL )
The comparison bits: SenseAny (0) specifies no version compare, SenseLess (2) less than the version, SenseGreater (4) greater than it and SenseEqual (8) equal to it. Combine them for "<=" and ">=".
const ( // SensePosttrans is Requires(posttrans). SensePosttrans Sense = tag.RPMSENSE_POSTTRANS // SensePrereq is the legacy PreReq. SensePrereq Sense = tag.RPMSENSE_PREREQ // SensePretrans is Requires(pretrans). SensePretrans Sense = tag.RPMSENSE_PRETRANS // SenseInterp marks the interpreter of a scriptlet; rpm sets it on the // requirements that name an interpreter. SenseInterp Sense = tag.RPMSENSE_INTERP // SenseScriptPre is Requires(pre). SenseScriptPre Sense = tag.RPMSENSE_SCRIPT_PRE // SenseScriptPost is Requires(post). SenseScriptPost Sense = tag.RPMSENSE_SCRIPT_POST // SenseScriptPreun is Requires(preun). SenseScriptPreun Sense = tag.RPMSENSE_SCRIPT_PREUN // SenseScriptPostun is Requires(postun). SenseScriptPostun Sense = tag.RPMSENSE_SCRIPT_POSTUN // SenseScriptVerify is Requires(verify). SenseScriptVerify Sense = tag.RPMSENSE_SCRIPT_VERIFY // SenseMissingOK is set on dependencies that need not be satisfiable // (Requires(hint) / "missingok"). SenseMissingOK Sense = tag.RPMSENSE_MISSINGOK // SensePreuntrans is Requires(preuntrans). SensePreuntrans Sense = tag.RPMSENSE_PREUNTRANS // SensePostuntrans is Requires(postuntrans). SensePostuntrans Sense = tag.RPMSENSE_POSTUNTRANS // SenseRPMLIB marks rpmlib(...) feature requirements. SenseRPMLIB Sense = tag.RPMSENSE_RPMLIB // SenseKeyring marks a requirement on a package that provides a keyring. SenseKeyring Sense = tag.RPMSENSE_KEYRING // SenseConfig marks the config(name) dependencies of packages with config files. SenseConfig Sense = tag.RPMSENSE_CONFIG // SenseMeta is Requires(meta): a requirement that does not order the transaction. SenseMeta Sense = tag.RPMSENSE_RICH )
The scope bits restrict a requirement to a stage of the transaction: Requires(pre) is SenseScriptPre, Requires(post) SenseScriptPost and so on. A requirement without scope bits is needed at all times.
type Translation ¶ added in v0.4.0
Translation holds the texts of a package in a language other than the default. Empty texts fall back to the default.
type Trigger ¶ added in v0.4.0
type Trigger struct {
Kind TriggerKind
// Conditions are the packages (with optional versions) that fire the
// trigger: "%triggerin -- foo, bar >= 2.0". Boolean dependencies are not
// supported as trigger conditions.
Conditions Relations
// Script is the trigger script. Its interpreter cannot have arguments.
Script Scriptlet
}
Trigger is a scriptlet that runs when other packages are installed or removed.
type TriggerKind ¶ added in v0.4.0
type TriggerKind int
TriggerKind selects when a trigger runs.
const ( // TriggerPrein runs before a package matching the condition is installed. TriggerPrein TriggerKind = iota // TriggerIn runs after a package matching the condition is installed. TriggerIn // TriggerUn runs before a package matching the condition is removed. TriggerUn // TriggerPostun runs after a package matching the condition is removed. TriggerPostun )
The kinds of triggers.
type VerifyFlags ¶ added in v0.4.0
type VerifyFlags uint32
VerifyFlags selects the attributes rpm --verify checks of a file.
const ( VerifyDigest VerifyFlags = tag.RPMVERIFY_FILEDIGEST VerifySize VerifyFlags = tag.RPMVERIFY_FILESIZE VerifyLinkTo VerifyFlags = tag.RPMVERIFY_LINKTO VerifyUser VerifyFlags = tag.RPMVERIFY_USER VerifyGroup VerifyFlags = tag.RPMVERIFY_GROUP VerifyMTime VerifyFlags = tag.RPMVERIFY_MTIME VerifyMode VerifyFlags = tag.RPMVERIFY_MODE VerifyRdev VerifyFlags = tag.RPMVERIFY_RDEV VerifyCaps VerifyFlags = tag.RPMVERIFY_CAPS VerifyContexts VerifyFlags = tag.RPMVERIFY_CONTEXTS )
The attributes of a file that rpm verifies.