Documentation ¶
Overview ¶
Package deb provides the building blocks for reading and writing deb files.
For a template-based system for generating deb files, see the `debgen` package in this repository ¶
**Warning: debgo [is being renamed to 'debber'](https://github.com/debber), Please note that the this version should still be used until debber-v0.3 becomes stable. It will not receive updates after that point. Ta**
Example (BuildBinaryDeb) ¶
package main import ( "log" "os" "path/filepath" "github.com/mwpcheung/debgo/deb" ) func main() { pkg := deb.NewPackage("testpkg", "0.0.2", "me", "lovely package\n") pkg.Description = "hiya" exesMap := map[string][]string{ "amd64": []string{filepath.Join(deb.TempDirDefault, "/a.amd64")}, "i386": []string{filepath.Join(deb.TempDirDefault, "/a.i386")}, "armhf": []string{filepath.Join(deb.TempDirDefault, "/a.armhf")}} err := createExes(exesMap) if err != nil { log.Fatalf("%v", err) } artifacts, err := deb.NewDebWriters(pkg) if err != nil { log.Fatalf("Error building binary: %v", err) } artifacts[deb.ArchAmd64].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.amd64")} artifacts[deb.ArchI386].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.i386")} artifacts[deb.ArchArmhf].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.armhf")} buildDeb := func(art *deb.DebWriter) error { //generate artifact here ... return nil } for arch, artifact := range artifacts { //build binary deb here ... err = buildDeb(artifact) if err != nil { log.Fatalf("Error building for '%s': %v", arch, err) } } } func createExes(exesMap map[string][]string) error { for _, exes := range exesMap { for _, exe := range exes { err := os.MkdirAll(filepath.Dir(exe), 0777) if err != nil { return err } fi, err := os.Create(exe) if err != nil { return err } _, err = fi.Write([]byte("echo 1")) if err != nil { return err } err = fi.Close() if err != nil { return err } } } return nil }
Output:
Example (BuildDevPackage) ¶
package main import ( "log" "github.com/mwpcheung/debgo/deb" ) func main() { pkg := deb.NewPackage("testpkg", "0.0.2", "me", "A package\ntestpkg is a lovel package with many wow") buildFunc := func(dpkg *deb.Package) error { // Generate files here. return nil } dpkg := deb.NewDevPackage(pkg) err := buildFunc(dpkg) if err != nil { log.Fatalf("%v", err) } }
Output:
Example (BuildSourceDeb) ¶
package main import ( "io/ioutil" "log" "path/filepath" "github.com/mwpcheung/debgo/deb" "github.com/mwpcheung/debgo/targz" ) func main() { pkg := deb.NewPackage("testpkg", "0.0.2", "me <me@b.c>", "Nice of all the package\n") pkg.Description = "hiya" spkg := deb.NewSourcePackage(pkg) err := buildOrigArchive(spkg) // it's up to you how to build this if err != nil { log.Fatalf("Error building source package: %v", err) } err = buildDebianArchive(spkg) // again - do it yourself if err != nil { log.Fatalf("Error building source package: %v", err) } err = buildDscFile(spkg) // yep, same again if err != nil { log.Fatalf("Error building source package: %v", err) } } func buildOrigArchive(spkg *deb.SourcePackage) error { origFilePath := filepath.Join(deb.DistDirDefault, spkg.OrigFileName) tgzw, err := targz.NewWriterFromFile(origFilePath) if err != nil { return err } err = tgzw.Close() if err != nil { return err } return nil } func buildDebianArchive(spkg *deb.SourcePackage) error { tgzw, err := targz.NewWriterFromFile(filepath.Join(deb.DistDirDefault, spkg.DebianFileName)) if err != nil { return err } err = tgzw.Close() if err != nil { return err } return nil } func buildDscFile(spkg *deb.SourcePackage) error { dscData := []byte{} dscFilePath := filepath.Join(deb.DistDirDefault, spkg.DscFileName) err := ioutil.WriteFile(dscFilePath, dscData, 0644) if err != nil { return err } return nil }
Output:
Index ¶
- Constants
- Variables
- func DebExtractFileL2(rdr io.Reader, topLevelFilename string, secondLevelFilename string, ...) error
- func DebGetContents(rdr io.Reader, topLevelFilename string) ([]string, error)
- func NewDebWriters(pkg *Package) (map[Architecture]*DebWriter, error)
- func ParseVersion(packageVersion string) (string, string, string, error)
- func SetDefaults(pkg *Package)
- func ValidateArchitecture(archString string) error
- func ValidateName(packageName string) error
- func ValidatePackage(pkg *Package) error
- func ValidateVersion(packageVersion string) error
- type Architecture
- type Checksum
- type Checksums
- type DebReader
- type DebWriter
- type DscReader
- type Package
- type SourcePackage
Examples ¶
Constants ¶
const ( DebianBinaryVersionDefault = "2.0" // This is the current version as specified in .deb archives (filename debian-binary) DebianCompatDefault = "9" // compatibility. Current version FormatDefault = "3.0 (quilt)" // Format as in a .dsc file StatusDefault = "unreleased" // Status is unreleased by default. Change this once you're happy with it. SectionDefault = "devel" //TODO: correct to use this? PriorityDefault = "extra" //Most packages should be 'extra' DependsDefault = "" //No dependencies BuildDependsDefault = "debhelper (>= 9.1.0), golang-go" //Default build dependencies for Go packages StandardsVersionDefault = "3.9.4" //Current standards version ArchitectureDefault = "any" //Any is the default architecture for packages TemplateDirDefault = "templates" ResourcesDirDefault = "resources" WorkingDirDefault = "." ExeDirDefault = "/usr/bin" //default directory for exes within the control archive BinaryDataArchiveNameDefault = "data.tar.gz" BinaryControlArchiveNameDefault = "control.tar.gz" )
Variables ¶
Functions ¶
func DebExtractFileL2 ¶
func NewDebWriters ¶
func NewDebWriters(pkg *Package) (map[Architecture]*DebWriter, error)
NewDebWriters gets and returns an artifact for each architecture. Returns an error if the package's architecture is un-parseable
func ParseVersion ¶
ParseVersion parses a debian version string into its [up to] 3 parts. Briefly, the format is: [epoch:]upstream_version[-debian_revision]
See http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
func SetDefaults ¶
func SetDefaults(pkg *Package)
Sets fields which can be initialised appropriately
func ValidateArchitecture ¶
ValidateArchitecture checks the architecture string by parsing it. Returns an error on failure. Only supported architectures are considered valid. (e.g. armel is not supported, and non-linux OSes are also not supported yet)
See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Architecture
func ValidateName ¶
ValidateName validates a package name for both 'Source:' and 'Package:' names
See http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source
func ValidatePackage ¶
ValidatePackage checks required fields and certain restricted values.
This can be considered a work-in-progress.
func ValidateVersion ¶
ValidateVersion checks a version string against the policy manual definition.
See ParseVersion
Example ¶
package main import ( "log" "github.com/mwpcheung/debgo/deb" ) func main() { v := "1.0.1-git123" err := deb.ValidateVersion(v) if err != nil { log.Fatalf("Version validation broken for %v", v) } }
Output:
Types ¶
type Architecture ¶
type Architecture string
Architecture - processor architecture (ARM/x86/AMD64) - as named by Debian. At this stage: i386, armhf, amd64 and 'all'. Note that 'any' is not valid for a binary package, and resolves to [i386, armhf, amd64] TODO: armel (Note that armhf = ARMv7 and armel = ARMv5. In Go terms, this is is is governed by the environment variable GOARM, and 7 is the default)
const ( ArchI386 Architecture = "i386" // x86 ArchArmhf Architecture = "armhf" //ARMv7 TODO: armel ArchAmd64 Architecture = "amd64" //For 64-bit machines ArchAll Architecture = "all" //for binary packages )
type Checksums ¶
type Checksums struct { ChecksumsMd5 []Checksum ChecksumsSha1 []Checksum ChecksumsSha256 []Checksum }
Checksums stores the 3 required checksums for a list of files
type DebWriter ¶
type DebWriter struct { Package *Package Architecture Architecture Filename string DebianBinaryVersion string ControlArchive string DataArchive string MappedFiles map[string]string }
DebWriter is an architecture-specific deb
func NewDebWriter ¶
func NewDebWriter(pkg *Package, architecture Architecture) *DebWriter
Factory of platform build information
func (*DebWriter) SetDefaults ¶
func (bdeb *DebWriter) SetDefaults()
SetDefaults sets some default properties
type DscReader ¶
DscReader reads a control file.
func NewDscReader ¶
NewDscReader is a factory for reading Dsc files.
type Package ¶
type Package struct { Name string // Package name Version string // Package version Description string // Description Maintainer string // Maintainer AdditionalControlData map[string]string // Other key/values to go into the Control file. Architecture string // Supported values: "all", "x386", "amd64", "armhf". TODO: armel Depends string // Depends Recommends string Suggests string Enhances string PreDepends string Conflicts string Breaks string Provides string Replaces string BuildDepends string // BuildDepends is only required for "sourcedebs". BuildDependsIndep string ConflictsIndep string BuiltUsing string Priority string StandardsVersion string Section string Format string Status string Other string Source string ExtraData map[string]interface{} // Optional for templates }
Package is the base unit for this library. A *Package contains metadata.
func DebParseMetadata ¶
ParseDebMetadata reads an artifact's contents.
func NewDevPackage ¶
NewDevPackage is a factory for creating '-dev' packages from packages. It just does a copy, appends "-dev" to the name, and sets the
func NewPackage ¶
NewPackage is a factory for a Package. Name, Version, Maintainer and Description are mandatory.
func (*Package) GetArches ¶
func (pkg *Package) GetArches() ([]Architecture, error)
GetArches resolves architecture(s) and return as a slice
type SourcePackage ¶
type SourcePackage struct { Package *Package DscFileName string OrigFileName string DebianFileName string DebianFiles []string }
SourcePackage is a cross-platform package with a .dsc file.
func NewSourcePackage ¶
func NewSourcePackage(pkg *Package) *SourcePackage
NewSourcePackage is a factory for SourcePackage. Sets up default paths.. Initialises default filenames, using .tar.gz as the archive type