Skip to content

Commit

Permalink
Merge fab6cc0 into bbfb9f6
Browse files Browse the repository at this point in the history
  • Loading branch information
xor-gate committed Sep 19, 2018
2 parents bbfb9f6 + fab6cc0 commit c8868c2
Show file tree
Hide file tree
Showing 69 changed files with 5,147 additions and 1,211 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ go:
# TODO: We only test for go 1.8 or later because testing.Name() is not supported.
# There must be a way to check if non-test builds work for go before 1.8
- 1.8
- 1.9
- '1.10'
- tip

before_install:
Expand Down
62 changes: 0 additions & 62 deletions Godeps/Godeps.json

This file was deleted.

5 changes: 0 additions & 5 deletions Godeps/Readme

This file was deleted.

57 changes: 57 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.2"

[[constraint]]
branch = "master"
name = "github.com/xor-gate/ar"

[[constraint]]
branch = "master"
name = "golang.org/x/crypto"

[[constraint]]
name = "gopkg.in/yaml.v2"
version = "2.2.1"

[prune]
go-tests = true
unused-packages = true
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ It is currently not possible to use the `debpkg` as a framework to manipulate an

## 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.
This package was created due to the lack to debianize from other platforms (windows/mac/*bsd).
As the whole debian package creation is a bunch of Perl modules and scripts. Which isn't easy to integrate in a CI/CD pipeline running on non-debian systems. It was created to package and distribute Go applications in an easy way. But can be used to package other applications as wel.

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](https://github.com/niemeyer/godeb) and
The package is heavily inspired by [godeb](https://github.com/niemeyer/godeb) and
[CPackDeb](https://cmake.org/cmake/help/v3.5/module/CPackDeb.html). It is very royal [licensed](LICENSE).

## Installation
Expand All @@ -38,7 +37,7 @@ This package is heavily inspired by [godeb](https://github.com/niemeyer/godeb) a
## 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.
but a wider audience is necessary and API breaks can occur.

# debpkg.yml specfile

Expand Down
4 changes: 2 additions & 2 deletions ar.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func addArFile(now time.Time, w *ar.Writer, dstname, filename string) error {
return err
}

func (deb *DebPkg) createDebAr(filename string) error {
func (deb *Package) createDebAr(filename string) error {
removeDeb := true
fd, err := os.Create(filename)
if err != nil {
Expand All @@ -80,7 +80,7 @@ func (deb *DebPkg) createDebAr(filename string) error {
if err := w.WriteGlobalHeader(); err != nil {
return fmt.Errorf("cannot write ar header to deb file: %v", err)
}
if err := addArFileFromBuffer(now, w, "debian-binary", []byte(deb.debianBinary)); err != nil {
if err := addArFileFromBuffer(now, w, "debian-binary", []byte(debianBinaryVersion)); err != nil {
return fmt.Errorf("cannot pack debian-binary: %v", err)
}
if err := addArFile(now, w, "control.tar.gz", deb.control.tgz.Name()); err != nil {
Expand Down
64 changes: 32 additions & 32 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
)

// Config loads settings from a depkg.yml specfile
func (deb *DebPkg) Config(filename string) error {
func (pkg *Package) Config(filename string) error {
data, err := ioutil.ReadFile(filename)
if err != nil {
return fmt.Errorf("problem reading config file: %v", err)
}

dataExpanded, err := ExpandVar(string(data))
dataExpanded, err := pkg.Variables.ExpandVar(string(data))
if err != nil {
return err
}
Expand All @@ -29,83 +29,83 @@ func (deb *DebPkg) Config(filename string) error {
return err
}

deb.SetSection(cfg.Section)
deb.SetPriority(Priority(cfg.Priority))
deb.SetName(cfg.Name)
deb.SetVersion(cfg.Version)
deb.SetArchitecture(cfg.Architecture)
deb.SetMaintainer(cfg.Maintainer)
deb.SetMaintainerEmail(cfg.MaintainerEmail)
deb.SetHomepage(cfg.Homepage)
deb.SetShortDescription(cfg.Description.Short)
deb.SetDescription(cfg.Description.Long)
deb.SetBuiltUsing(cfg.BuiltUsing)
deb.SetDepends(cfg.Depends)
deb.SetRecommends(cfg.Recommends)
deb.SetSuggests(cfg.Suggests)
deb.SetConflicts(cfg.Conflicts)
deb.SetProvides(cfg.Provides)
deb.SetReplaces(cfg.Replaces)
pkg.SetSection(cfg.Section)
pkg.SetPriority(Priority(cfg.Priority))
pkg.SetName(cfg.Name)
pkg.SetVersion(cfg.Version)
pkg.SetArchitecture(cfg.Architecture)
pkg.SetMaintainer(cfg.Maintainer)
pkg.SetMaintainerEmail(cfg.MaintainerEmail)
pkg.SetHomepage(cfg.Homepage)
pkg.SetShortDescription(cfg.Description.Short)
pkg.SetDescription(cfg.Description.Long)
pkg.SetBuiltUsing(cfg.BuiltUsing)
pkg.SetDepends(cfg.Depends)
pkg.SetRecommends(cfg.Recommends)
pkg.SetSuggests(cfg.Suggests)
pkg.SetConflicts(cfg.Conflicts)
pkg.SetProvides(cfg.Provides)
pkg.SetReplaces(cfg.Replaces)

for _, file := range cfg.Files {
if len(file.File) > 0 {
if err := deb.AddFile(file.File, file.Dest); err != nil {
if err := pkg.AddFile(file.File, file.Dest); err != nil {
return fmt.Errorf("error adding file %s: %v", file.File, err)
}
} else if len(file.Content) > 0 {
if err := deb.AddFileString(file.Content, file.Dest); err != nil {
if err := pkg.AddFileString(file.Content, file.Dest); err != nil {
return fmt.Errorf("error adding file by string: %v", err)
}
} else {
return fmt.Errorf("need either 'content' or a 'src' to add a file")
}
if file.ConfigFile {
deb.MarkConfigFile(file.Dest)
pkg.MarkConfigFile(file.Dest)
}
}

for _, dir := range cfg.Directories {
if err := deb.AddDirectory(dir); err != nil {
if err := pkg.AddDirectory(dir); err != nil {
return fmt.Errorf("error adding directory %s: %v", dir, err)
}
}

for _, dir := range cfg.EmptyDirectories {
err := deb.AddEmptyDirectory(dir)
err := pkg.AddEmptyDirectory(dir)
if err != nil {
return fmt.Errorf("error adding directory %s: %v", dir, err)
}
}

if len(cfg.ControlExtra.Preinst) > 0 {
if strings.ContainsAny(cfg.ControlExtra.Preinst, "\n") {
deb.AddControlExtraString("preinst", cfg.ControlExtra.Preinst)
pkg.AddControlExtraString("preinst", cfg.ControlExtra.Preinst)
} else {
deb.AddControlExtra("preinst", cfg.ControlExtra.Preinst)
pkg.AddControlExtra("preinst", cfg.ControlExtra.Preinst)
}
}

if len(cfg.ControlExtra.Postinst) > 0 {
if strings.ContainsAny(cfg.ControlExtra.Postinst, "\n") {
deb.AddControlExtraString("postinst", cfg.ControlExtra.Postinst)
pkg.AddControlExtraString("postinst", cfg.ControlExtra.Postinst)
} else {
deb.AddControlExtra("postinst", cfg.ControlExtra.Postinst)
pkg.AddControlExtra("postinst", cfg.ControlExtra.Postinst)
}
}

if len(cfg.ControlExtra.Prerm) > 0 {
if strings.ContainsAny(cfg.ControlExtra.Prerm, "\n") {
deb.AddControlExtraString("prerm", cfg.ControlExtra.Prerm)
pkg.AddControlExtraString("prerm", cfg.ControlExtra.Prerm)
} else {
deb.AddControlExtra("prerm", cfg.ControlExtra.Prerm)
pkg.AddControlExtra("prerm", cfg.ControlExtra.Prerm)
}
}

if len(cfg.ControlExtra.Postrm) > 0 {
if strings.ContainsAny(cfg.ControlExtra.Postrm, "\n") {
deb.AddControlExtraString("postrm", cfg.ControlExtra.Postrm)
pkg.AddControlExtraString("postrm", cfg.ControlExtra.Postrm)
} else {
deb.AddControlExtra("postrm", cfg.ControlExtra.Postrm)
pkg.AddControlExtra("postrm", cfg.ControlExtra.Postrm)
}
}
return nil
Expand Down

0 comments on commit c8868c2

Please sign in to comment.