Skip to content

Commit

Permalink
fix package headers + copy forlder to package
Browse files Browse the repository at this point in the history
  • Loading branch information
markus621 committed Dec 30, 2022
1 parent 9653722 commit b6346d5
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 70 deletions.
5 changes: 1 addition & 4 deletions .deb.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package: deb-builder
source: deb-builder
version: '1:0.3.0'
version: '1:0.4.0'
architecture:
- 386
- amd64
Expand All @@ -17,12 +17,9 @@ control:
- systemd
- ca-certificates
build: scripts/build.sh
conffiles:
- /etc/fdns/config.yaml
preinst: scripts/preinst.sh
postinst: scripts/postinst.sh
prerm: scripts/prerm.sh
postrm: scripts/postrm.sh
data:
usr/bin/deb-builder: build/bin/deb-builder_%arch%
usr/log/deb-builder.log: "+Empty empty log file\n"
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SHELL=/bin/bash
GOPATH=$(shell go env GOPATH)

.PHONY: new-conf
new-conf:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ control:
data: # A list of files that will be packaged during the build, where the file in the destination package is preceded by a colon, and the source file is indicated after it. A placeholder %arch% is available indicating the architecture.
bin/demo: build/bin/demo_%arch%
etc/demo/config.yaml: configs/config.yaml
demo/file: '+write file content' # Use the `+` prefix to create a file with the specified content
demo/dir: '~/build' # Use the `~` prefix to copy the entire contents of a directory into a package
```
# build deb package
Expand Down
3 changes: 3 additions & 0 deletions cmd/deb-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func main() {
pgpCmd := console.NewCommand(func(setter console.CommandSetter) {
setter.Setup("pgp", "work with PGP")
setter.AddCommand(commands.CreatePGPCert())
setter.ExecFunc(func(_ []string) {

})
})

root.AddCommand(pgpCmd)
Expand Down
25 changes: 18 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
module github.com/dewep-online/deb-builder

go 1.16
go 1.19

require (
github.com/deweppro/go-app v1.4.2
github.com/deweppro/go-archives v1.0.3
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
gopkg.in/yaml.v2 v2.4.0
github.com/deweppro/go-app v1.6.3
github.com/deweppro/go-archives v1.0.4
github.com/deweppro/go-errors v0.0.4
github.com/stretchr/testify v1.8.1
golang.org/x/crypto v0.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deweppro/go-algorithms v1.2.0 // indirect
github.com/deweppro/go-chan-pool v1.1.2 // indirect
github.com/deweppro/go-logger v1.3.0 // indirect
github.com/deweppro/go-utils v0.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
)
55 changes: 24 additions & 31 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deweppro/go-algorithms v1.1.1 h1:FOzPuYmFuFGN6Nmcos5zC1WfD3Ya8XxUJ6OihrhFh4Q=
github.com/deweppro/go-algorithms v1.1.1/go.mod h1:h50x8PTIGbiIhOh5vH/10J39vTzi2UmG7TVLupellqY=
github.com/deweppro/go-app v1.4.2 h1:mpYjwyC2b6089CdRhJuJPMeiETu4ldaCXE9fSMQwarQ=
github.com/deweppro/go-app v1.4.2/go.mod h1:Tm4RUCOw7R/qnomzYT/rIykfqRI1zNfDArpHsaLgl/I=
github.com/deweppro/go-archives v1.0.3 h1:Vmv8/myS6Cv8buEmmmN3/EWzfDRdx24h8svMbQCsS2c=
github.com/deweppro/go-archives v1.0.3/go.mod h1:GP2Or5TFSEWQAam/Q/jgFhLpcF0LroITKic654pQERk=
github.com/deweppro/go-chan-pool v1.1.1 h1:TCoQhgXG6GP7zTJiKwOmqSeaR64651cWFpVniD5BIys=
github.com/deweppro/go-chan-pool v1.1.1/go.mod h1:lEtDI+rhCE/ES1i9q0FOtYgjMftw5PCCepit4a+9Uds=
github.com/deweppro/go-logger v1.2.3 h1:icOV4UwBGc8s9S8zcNIcDjBK00qQtcuBZzBgRmMaq24=
github.com/deweppro/go-logger v1.2.3/go.mod h1:bPDvX/7B3+i5f8nGOq4bZbhJrf4PgjYRCePqMrF5smw=
github.com/deweppro/go-algorithms v1.2.0 h1:fBS+GNQaeSDSmvFWdmkKLcKXo2DhX5M0AJaCxEqGedY=
github.com/deweppro/go-algorithms v1.2.0/go.mod h1:zYdfRdlpaXgdT36OgvdjH1qtTZFWEeBi3KUQmWltMPI=
github.com/deweppro/go-app v1.6.3 h1:IZr8Zyq+RtpOQDZxUIRCTCppN9w3c/xG+9YUX+ECPnA=
github.com/deweppro/go-app v1.6.3/go.mod h1:1Zj2Mfj/vPXe3PfrWQ5MAM9l2TSVLbp5i6OCyKD4mO4=
github.com/deweppro/go-archives v1.0.4 h1:CB5nX5ll7PyDU5s5yFmBq9Dn5xZGjSRumawZRZgMfkk=
github.com/deweppro/go-archives v1.0.4/go.mod h1:3OVhSu087B6aIsFGBzEMCE6iZzBC39bI/MB4qAOlQVI=
github.com/deweppro/go-chan-pool v1.1.2 h1:mm+gvwAFB5NijCiJDSx9RqrB2AWTembzL9Rf6XTv4BI=
github.com/deweppro/go-chan-pool v1.1.2/go.mod h1:6meJsORhraeyvJNPy4hx8xgBNjp2xx3KGB/d5Q5a/I4=
github.com/deweppro/go-errors v0.0.4 h1:TW91LRqHAkUauDJ5lzz73LziANH7mjli1tyvtwzXRCM=
github.com/deweppro/go-errors v0.0.4/go.mod h1:BLsNcxaHh1fjNl/o1TB69JwA8XueSk/Nszkvw4ZwI/I=
github.com/deweppro/go-logger v1.3.0 h1:KN6RQmb6IoNBxQ7zx7Y1AtptHeL//FRgvQyEF5PrcsE=
github.com/deweppro/go-logger v1.3.0/go.mod h1:jxBBLyHmIvJ4erGUj5qeE6ir36ztyAL1pI+9GymOHVI=
github.com/deweppro/go-utils v0.0.1 h1:yBISU0cvDqj2MjJGf/WXMft76zGT7ETCHJST52pYkSw=
github.com/deweppro/go-utils v0.0.1/go.mod h1:wH2zpJsk1kc1MOALmxxfZaVomKkRX9K6U1m5Rs2VvHA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
33 changes: 27 additions & 6 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -38,6 +39,11 @@ func Build() console.CommandGetter {

exec.Build(conf, func(arch string) {

replacer := strings.NewReplacer(
`%arch%`, arch,
`%version%`, packages.SplitVersion(conf.Version),
)

// check file version

debFile, revision, carch := packages.BuildName(storeDir, conf.Package, conf.Version, arch)
Expand All @@ -53,19 +59,34 @@ func Build() console.CommandGetter {
tg, err := archive.NewWriter(dataFile)
console.FatalIfErr(err, "create data.tar.gz")
for dst, src := range conf.Data {
src = strings.ReplaceAll(src, "%arch%", arch)
src = replacer.Replace(src)
var (
f, h string
err1 error
)
if src[0] == '+' {

switch src[0] {
case '+':
f, h, err1 = tg.WriteData(dst, []byte(src)[1:])
} else {
console.FatalIfErr(err1, "write %s to data.tar.gz", src)
md5sum.Add(f, h)
case '~':
err1 := filepath.Walk(src[1:], func(path string, info fs.FileInfo, e error) error {
if e != nil {
return e
}
if info.IsDir() {
return nil
}
ff, hh, ee := tg.WriteFile(path, strings.ReplaceAll(path, src[1:], dst))
console.FatalIfErr(ee, "write %s to data.tar.gz", src)
md5sum.Add(ff, hh)
return nil
})
console.FatalIfErr(err1, "write %s to data.tar.gz", src)
default:
f, h, err1 = tg.WriteFile(src, dst)
}
if err1 != nil {
console.FatalIfErr(err1, "write %s to data.tar.gz", src)
} else {
md5sum.Add(f, h)
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/archive/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (v *TGZWriter) WriteData(filename string, b []byte) (string, string, error)
Mode: int64(0644),
Size: int64(len(b)),
Typeflag: tar.TypeReg,
Format: tar.FormatGNU,
}
if err := v.tar.WriteHeader(hdr); err != nil {
return utils.CleanPath(dst), "", err
Expand Down Expand Up @@ -91,6 +92,7 @@ func (v *TGZWriter) WriteFile(src, dst string) (string, string, error) {
Mode: int64(stat.Mode()),
Size: stat.Size(),
Typeflag: tar.TypeReg,
Format: tar.FormatGNU,
}
if err := v.tar.WriteHeader(hdr); err != nil {
return utils.CleanPath(dst), "", err
Expand Down Expand Up @@ -122,6 +124,7 @@ func (v *TGZWriter) mkdirAll(filename string) error {
ModTime: time.Now(),
Mode: int64(0755),
Typeflag: tar.TypeDir,
Format: tar.FormatGNU,
}
if err := v.tar.WriteHeader(hdr); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"regexp"

"github.com/dewep-online/deb-builder/pkg/utils"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

const ConfigFileName = ".deb.yaml"
Expand Down
8 changes: 5 additions & 3 deletions pkg/exec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
func Build(conf *config.Config, cb func(arch string)) {
for _, v := range conf.Architecture {

out, err := Run(conf.Control.Build+" "+v, nil)
console.Warnf(out)
console.FatalIfErr(err, "Failed to build resources for %s", v)
if len(conf.Control.Build) > 0 {
out, err := Run(conf.Control.Build+" "+v, nil)
console.Warnf(out)
console.FatalIfErr(err, "Failed to build resources for %s", v)
}

cb(v)
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/packages/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ var pkgArchAlias = map[string]string{
"386": "i386",
}

func SplitVersion(v string) string {
if strings.Contains(v, ":") {
vv := strings.SplitN(v, ":", 2)
if len(vv) == 2 {
return vv[1]
}
}
return v
}

func BuildName(dir, name, version, arch string) (string, string, string) {
if v, ok := pkgArchAlias[arch]; ok {
arch = v
Expand Down
24 changes: 24 additions & 0 deletions pkg/packages/name_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package packages

import "testing"

func TestUnit_SplitVersion(t *testing.T) {
type args struct {
v string
}
tests := []struct {
name string
args args
want string
}{
{name: "Case1", args: args{v: "1:1.1.1"}, want: "1.1.1"},
{name: "Case2", args: args{v: "1.1.1.1"}, want: "1.1.1.1"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SplitVersion(tt.args.v); got != tt.want {
t.Errorf("SplitVersion() = %v, want %v", got, tt.want)
}
})
}
}
12 changes: 6 additions & 6 deletions pkg/pgp/pgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto"
"io"

"github.com/pkg/errors"
"github.com/deweppro/go-errors"
"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/armor"
"golang.org/x/crypto/openpgp/clearsign"
Expand All @@ -32,22 +32,22 @@ func NewPGP() *PGP {
func (v *PGP) LoadPrivateKey(r io.ReadSeeker, passwd string) error {
block, err := armor.Decode(r)
if err != nil {
return errors.Wrap(err, "Armor decode")
return errors.WrapMessage(err, "Armor decode")
}
if block.Type != openpgp.PrivateKeyType {
return errors.Wrap(err, "invalid key type")
return errors.WrapMessage(err, "invalid key type")
}
if _, err = r.Seek(0, 0); err != nil {
return errors.Wrap(err, "seek file")
return errors.WrapMessage(err, "seek file")
}
keys, err := openpgp.ReadArmoredKeyRing(r)
if err != nil {
return errors.Wrap(err, "read key")
return errors.WrapMessage(err, "read key")
}
v.key = keys[0]
if v.key.PrivateKey.Encrypted {
if err := v.key.PrivateKey.Decrypt([]byte(passwd)); err != nil {
return errors.Wrap(err, "invalid password")
return errors.WrapMessage(err, "invalid password")
}
}
return nil
Expand Down
Loading

0 comments on commit b6346d5

Please sign in to comment.