debpkg

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: MIT Imports: 22 Imported by: 4

README

debpkg

License Godoc ReportCard Build BuildAppVeyor Coverage

debpkg is a pure Go library to create Debian Linux packages. The package can be directly imported in your go project or run a debpkg cli tool with a custom debpkg YAML specfile (just like a single RPM spec file). It has zero dependencies outside go modules, to and doesn't use exec wrappers. Therefor it is able to generate packages from non Linux systems like Mac OS X, *BSD and Windows without the Perl dependency (as with official debbuild). The "problem" with the Debian package build system is it universal and flexable nature, which can be a pro or con. Packaging just a small bunch of files with simple configuration the Debian build system is a fairly complex beast to understand. And you must dig deep into the workings of the Debian package management documentation. Debpkg is not able to resolve all the advanced packaging requirements theirfor one must use the official debbuild and debhelper. It is created for the simple case to convert a directory structure to be installable and maintained via the standard debian way.

Features

The feature list below describes the usability state of the project:

  • Create debian packages from files and folders
  • Create package from debpkg.yml specfile
  • Add custom control files (preinst, postinst, prerm, postrm etcetera)

It is currently not possible to use the debpkg as a framework to manipulate and introspect individual Debian package objects (see issue #26). As it is only capable of creating packages.

Why this package was created

This package was created due to the lack to debianize from other platforms (windows/mac/*bsd). Because the whole debian package management system is glued together with Perl scripts and uses a bunch of Perl modules. Which isn't easy to use in a CI/CD pipeline for Go projects.

Converting a simple directory structure with files into a debian package is a difficult without knowing the deb-file internals.

This package is heavily inspired by godeb and CPackDeb. It is very royal licensed.

Installation

go get -u github.com/xor-gate/debpkg/cmd/debpkg

Status

The package is currently in production state. The API is still unstable (v0) most rough edges are already polished but a wider audience is necessary.

debpkg.yml specfile

The specfile is written in the YAML markup format. It controls the package information and data.

A simple example is listed below:

# debpkg.yml specfile
name: foobar
version: 7.6.5
architecture: all
maintainer: Foo Bar
maintainer_email: foo@bar.com
homepage: https://github.com/xor-gate/debpkg
description:
  short: This package is just a test
  long: >
    This package tests the working of debpkg.
    And can wrap multiple
    lines.

    And multiple paragraphs.

Mentions

This project originate from an in-company implementation sponsored by @dualinventive in 2016-2017, with help from collegue @rikvdh.

I would like to mention some other noticable projects for debian package management:

Other packaging tools in golang:

Debugging

When debugging on a Debian system the following commands are usefull:

  • Print package info: dpkg --info <debfile>
  • Extract data.tar.gz: dpkg --extract <debfile> data
  • Verbose extract data.tar.gz: dpkg --vextract <debfile> data
  • Extract control.tar.gz: dpkg --control <debfile> control

Further documentation

More information can be gathered from the Debian and Ubuntu documentation:

License

MIT

Documentation

Overview

Package debpkg implements creation of (gpg signed) debian packages

Overview

The most basic debian package is created as follows (without error checking):

deb := debpkg.New()

deb.SetName("foobar")
deb.SetVersion("1.2.3")
deb.SetArchitecture("amd64")
deb.SetMaintainer("Foo Bar")
deb.SetMaintainerEmail("foo@bar.com")
deb.SetHomepage("http://foobar.com")

deb.SetShortDescription("Minimal foo bar package")
deb.SetDescription("Foo bar package doesn't do anything")

deb.AddFile("/tmp/foobar")

deb.Write("foobar.deb")
deb.Close()

Index

Examples

Constants

View Source
const (
	DefaultInstallPrefix = "/usr"  // Default install Prefix
	DefaultBinDir        = "bin"   // Default binary directory
	DefaultSbinDir       = "sbin"  // Default sbin directory
	DefaultSysConfDir    = "etc"   // Default configuration directory
	DefaultDataRootDir   = "share" // Default data root directory
)

Default installation variables

Variables

View Source
var ErrClosed = errors.New("debpkg: Closed")

ErrClosed when the file I/O is requested and it is already closed

View Source
var ErrIO = errors.New("debpkg: I/O failed")

ErrIO is returned when any file I/O failed

Functions

func ExpandVar

func ExpandVar(msg string) (string, error)

ExpandVar expands a string with variables

func GetArchitecture

func GetArchitecture() string

GetArchitecture gets the current build.Default.GOARCH in debian-form

func GetVar

func GetVar(v string) string

GetVar gets a variable

func GetVarWithPrefix

func GetVarWithPrefix(v string) string

GetVarWithPrefix gets a variable and appends INSTALLPREFIX when the value doesn't start with "/"

func SetVar

func SetVar(key, val string)

SetVar sets a variable for use with config file

Types

type DebPkg

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

DebPkg holds data for a single debian package

func New

func New(tempDir ...string) *DebPkg

New creates new debian package, optionally provide an tempdir to write

intermediate files, otherwise os.TempDir is used. A provided tempdir must exist
in order for it to work.

func (*DebPkg) AddControlExtra

func (deb *DebPkg) AddControlExtra(name, filename string) error

AddControlExtra allows the advanced user to add custom script to the control.tar.gz Typical usage is

for preinst, postinst, postrm, prerm: https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html

And: https://www.debian.org/doc/manuals/maint-guide/dother.en.html#maintscripts the files have possible DOS line-endings replaced by UNIX line-endings

func (*DebPkg) AddControlExtraString

func (deb *DebPkg) AddControlExtraString(name, s string) error

AddControlExtraString is the same as AddControlExtra except it uses a string input. the files have possible DOS line-endings replaced by UNIX line-endings

func (*DebPkg) AddDirectory

func (deb *DebPkg) AddDirectory(dir string) error

AddDirectory adds a directory recursive to the package

func (*DebPkg) AddEmptyDirectory

func (deb *DebPkg) AddEmptyDirectory(dir string) error

AddEmptyDirectory adds a empty directory to the package

func (*DebPkg) AddFile

func (deb *DebPkg) AddFile(filename string, dest ...string) error

AddFile adds a file by filename to the package

func (*DebPkg) AddFileString

func (deb *DebPkg) AddFileString(contents, dest string) error

AddFileString adds a file to the package with the provided content

func (*DebPkg) Close

func (deb *DebPkg) Close() error

Close closes the File (and removes the intermediate files), rendering it unusable for I/O. It returns an error, if any.

func (*DebPkg) Config

func (deb *DebPkg) Config(filename string) error

Config loads settings from a depkg.yml specfile

func (*DebPkg) GetFilename

func (deb *DebPkg) GetFilename() string

GetFilename calculates the filename based on name, version and architecture SetName("foo") SetVersion("1.33.7") SetArchitecture("amd64") Generates filename "foo-1.33.7_amd64.deb"

func (*DebPkg) MarkConfigFile

func (deb *DebPkg) MarkConfigFile(dest string) error

MarkConfigFile marks configuration files in the debian package

func (*DebPkg) SetArchitecture

func (deb *DebPkg) SetArchitecture(arch string)

SetArchitecture sets the architecture of the package where it can be installed.

E.g "i386, amd64, arm, any, all". See `dpkg-architecture -L` for all supported.

Architecture: any

The generated binary package is an architecture dependent one usually in a compiled language.

Architecture: all

The generated binary package is an architecture independent one usually consisting of text,
images, or scripts in an interpreted language.

See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Architecture And: http://man7.org/linux/man-pages/man1/dpkg-architecture.1.html

func (*DebPkg) SetBuiltUsing

func (deb *DebPkg) SetBuiltUsing(info string)

SetBuiltUsing incorporate parts of other packages when built but do not have to depend on those packages. A package using the source code from the gcc-4.6-source binary package built from the gcc-4.6 source package would have this field in its control file:

Built-Using: gcc-4.6 (= 4.6.0-11)

A package including binaries from grub2 and loadlin would have this field in its control file:

Built-Using: grub2 (= 1.99-9), loadlin (= 1.6e-1)

See: https://www.debian.org/doc/debian-policy/ch-relationships.html#s-built-using

func (*DebPkg) SetConflicts

func (deb *DebPkg) SetConflicts(conflicts string)

SetConflicts sets one or more conflicting packages. E.g: "nano" See: https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts

func (*DebPkg) SetDepends

func (deb *DebPkg) SetDepends(depends string)

SetDepends sets the package dependencies. E.g: "lsb-release" See: https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps

func (*DebPkg) SetDescription

func (deb *DebPkg) SetDescription(descr string)

SetDescription sets the extended description over several lines. E.g: "This tool will calculation the most efficient way to world domination" NOTE: The debian control file has a special formatting of the long description

this function replaces newlines with a newline and a space.

func (*DebPkg) SetHomepage

func (deb *DebPkg) SetHomepage(url string)

SetHomepage sets the homepage URL of the package. E.g: "https://github.com/foo/bar"

func (*DebPkg) SetMaintainer

func (deb *DebPkg) SetMaintainer(maintainer string)

SetMaintainer (mandatory), sets the package maintainers name and surname. E.g: "Foo Bar" See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Maintainer

func (*DebPkg) SetMaintainerEmail

func (deb *DebPkg) SetMaintainerEmail(email string)

SetMaintainerEmail sets the package maintainers email address. E.g: "foo@bar.com" See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Maintainer

func (*DebPkg) SetName

func (deb *DebPkg) SetName(name string)

SetName sets the name of the binary package (mandatory) See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Package

func (*DebPkg) SetPriority

func (deb *DebPkg) SetPriority(priority Priority)

SetPriority (recommended). Default set to debpkg.PriorityUnset See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Priority And: https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities

func (*DebPkg) SetProvides

func (deb *DebPkg) SetProvides(provides string)

SetProvides sets the type which the package provides. E.g: "editor" See: https://www.debian.org/doc/debian-policy/ch-relationships.html#s-virtual

func (*DebPkg) SetRecommends

func (deb *DebPkg) SetRecommends(recommends string)

SetRecommends sets the package recommendations. E.g: "aptitude" See: https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps

func (*DebPkg) SetReplaces

func (deb *DebPkg) SetReplaces(replaces string)

SetReplaces sets the names of packages which will be replaced. E.g: "pico" See: https://www.debian.org/doc/debian-policy/ch-relationships.html

func (*DebPkg) SetShortDescription

func (deb *DebPkg) SetShortDescription(descr string)

SetShortDescription sets the single line synopsis. E.g: "My awesome foo bar baz tool"

func (*DebPkg) SetSuggests

func (deb *DebPkg) SetSuggests(suggests string)

SetSuggests sets the package suggestions. E.g: "aptitude" See: https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps

func (*DebPkg) SetVcsBrowser

func (deb *DebPkg) SetVcsBrowser(url string)

SetVcsBrowser sets the version control system (Vcs) browsable source-tree URL for the source package. See: https://www.debian.org/doc/manuals/developers-reference/best-pkging-practices.html#s6.2.5.2

func (*DebPkg) SetVcsType

func (deb *DebPkg) SetVcsType(vcs VcsType)

SetVcsType sets the version control system (Vcs) type for the source package. See: https://www.debian.org/doc/manuals/developers-reference/best-pkging-practices.html#s6.2.5.2

func (*DebPkg) SetVcsURL

func (deb *DebPkg) SetVcsURL(url string)

SetVcsURL sets the version control system (Vcs) URL for the source package. See: https://www.debian.org/doc/manuals/developers-reference/best-pkging-practices.html#s6.2.5.2

func (*DebPkg) SetVersion

func (deb *DebPkg) SetVersion(version string)

SetVersion sets the full version string (mandatory), or use SetVersion* functions for "major.minor.patch" The upstream_version may contain only alphanumerics ( A-Za-z0-9 ) and the characters . + - : ~

(full stop, plus, hyphen, colon, tilde) and should start with a digit.

NOTE: When the full string is set the other SetVersion* function calls are ignored See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

func (*DebPkg) SetVersionMajor

func (deb *DebPkg) SetVersionMajor(major uint)

SetVersionMajor sets the version major number See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

func (*DebPkg) SetVersionMinor

func (deb *DebPkg) SetVersionMinor(minor uint)

SetVersionMinor sets the version minor number See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

func (*DebPkg) SetVersionPatch

func (deb *DebPkg) SetVersionPatch(patch uint)

SetVersionPatch sets the version patch level See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

func (*DebPkg) Write

func (deb *DebPkg) Write(filename string) error

Write the debian package to the filename

Example

ExampleDebPkgWrite demonstrates generating a simple package

tempfile := os.TempDir() + "/foobar.deb"

deb := New()
defer deb.Close()

deb.SetName("foobar")
deb.SetVersion("1.2.3")
deb.SetArchitecture("amd64")
deb.SetMaintainer("Foo Bar")
deb.SetMaintainerEmail("foo@bar.com")
deb.SetHomepage("http://foobar.com")

deb.SetShortDescription("Minimal foo bar package")
deb.SetDescription("Foo bar package doesn't do anything")

deb.AddFile("debpkg.go")
fmt.Println(deb.Write(tempfile))

// Do something with tempfile other than removing it...
Output:

func (*DebPkg) WriteSigned

func (deb *DebPkg) WriteSigned(filename string, entity *openpgp.Entity) error

WriteSigned package with GPG entity

type Priority

type Priority string

Priority for Debian package

const (
	PriorityUnset     Priority = ""          // Priority field is skipped
	PriorityRequired  Priority = "required"  // Packages which are necessary for the proper functioning of the system
	PriorityImportant Priority = "important" // Important programs, including those which one would expect to find on any Unix-like system
	PriorityStandard  Priority = "standard"  // These packages provide a reasonably small but not too limited character-mode system
	PriorityOptional  Priority = "optional"  // This is all the software that you might reasonably want to install if you didn't know what it was and don't have specialized requirements
)

Package Priority

type VcsType

type VcsType string

VcsType for Debian package supported version control system (Vcs) types

const (
	VcsTypeUnset      VcsType = ""      // VcsType field is skipped
	VcsTypeArch       VcsType = "Arch"  // Arch
	VcsTypeBazaar     VcsType = "Bzr"   // Bazaar
	VcsTypeDarcs      VcsType = "Darcs" // Darcs
	VcsTypeGit        VcsType = "Git"   // Git
	VcsTypeMercurial  VcsType = "Hg"    // Mercurial
	VcsTypeMonotone   VcsType = "Mtn"   // Monotone
	VcsTypeSubversion VcsType = "Svn"   // Subversion
)

Package VcsType

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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