Skip to content

Commit b4ee15f

Browse files
authored
Merge pull request #22 from dewep-online/develop
fix package headers + copy forlder to package
2 parents 9653722 + b6346d5 commit b4ee15f

File tree

15 files changed

+137
-70
lines changed

15 files changed

+137
-70
lines changed

.deb.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package: deb-builder
22
source: deb-builder
3-
version: '1:0.3.0'
3+
version: '1:0.4.0'
44
architecture:
55
- 386
66
- amd64
@@ -17,12 +17,9 @@ control:
1717
- systemd
1818
- ca-certificates
1919
build: scripts/build.sh
20-
conffiles:
21-
- /etc/fdns/config.yaml
2220
preinst: scripts/preinst.sh
2321
postinst: scripts/postinst.sh
2422
prerm: scripts/prerm.sh
2523
postrm: scripts/postrm.sh
2624
data:
2725
usr/bin/deb-builder: build/bin/deb-builder_%arch%
28-
usr/log/deb-builder.log: "+Empty empty log file\n"

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
SHELL=/bin/bash
2+
GOPATH=$(shell go env GOPATH)
23

34
.PHONY: new-conf
45
new-conf:

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ control:
5050
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.
5151
bin/demo: build/bin/demo_%arch%
5252
etc/demo/config.yaml: configs/config.yaml
53+
demo/file: '+write file content' # Use the `+` prefix to create a file with the specified content
54+
demo/dir: '~/build' # Use the `~` prefix to copy the entire contents of a directory into a package
5355
```
5456
5557
# build deb package

cmd/deb-builder/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ func main() {
1515
pgpCmd := console.NewCommand(func(setter console.CommandSetter) {
1616
setter.Setup("pgp", "work with PGP")
1717
setter.AddCommand(commands.CreatePGPCert())
18+
setter.ExecFunc(func(_ []string) {
19+
20+
})
1821
})
1922

2023
root.AddCommand(pgpCmd)

go.mod

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
module github.com/dewep-online/deb-builder
22

3-
go 1.16
3+
go 1.19
44

55
require (
6-
github.com/deweppro/go-app v1.4.2
7-
github.com/deweppro/go-archives v1.0.3
8-
github.com/pkg/errors v0.9.1
9-
github.com/stretchr/testify v1.7.0
10-
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
11-
gopkg.in/yaml.v2 v2.4.0
6+
github.com/deweppro/go-app v1.6.3
7+
github.com/deweppro/go-archives v1.0.4
8+
github.com/deweppro/go-errors v0.0.4
9+
github.com/stretchr/testify v1.8.1
10+
golang.org/x/crypto v0.4.0
11+
gopkg.in/yaml.v3 v3.0.1
12+
)
13+
14+
require (
15+
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/deweppro/go-algorithms v1.2.0 // indirect
17+
github.com/deweppro/go-chan-pool v1.1.2 // indirect
18+
github.com/deweppro/go-logger v1.3.0 // indirect
19+
github.com/deweppro/go-utils v0.0.1 // indirect
20+
github.com/josharian/intern v1.0.0 // indirect
21+
github.com/mailru/easyjson v0.7.7 // indirect
22+
github.com/pmezard/go-difflib v1.0.0 // indirect
1223
)

go.sum

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

internal/commands/build.go

+27-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commands
22

33
import (
44
"fmt"
5+
"io/fs"
56
"os"
67
"path/filepath"
78
"strings"
@@ -38,6 +39,11 @@ func Build() console.CommandGetter {
3839

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

42+
replacer := strings.NewReplacer(
43+
`%arch%`, arch,
44+
`%version%`, packages.SplitVersion(conf.Version),
45+
)
46+
4147
// check file version
4248

4349
debFile, revision, carch := packages.BuildName(storeDir, conf.Package, conf.Version, arch)
@@ -53,19 +59,34 @@ func Build() console.CommandGetter {
5359
tg, err := archive.NewWriter(dataFile)
5460
console.FatalIfErr(err, "create data.tar.gz")
5561
for dst, src := range conf.Data {
56-
src = strings.ReplaceAll(src, "%arch%", arch)
62+
src = replacer.Replace(src)
5763
var (
5864
f, h string
5965
err1 error
6066
)
61-
if src[0] == '+' {
67+
68+
switch src[0] {
69+
case '+':
6270
f, h, err1 = tg.WriteData(dst, []byte(src)[1:])
63-
} else {
71+
console.FatalIfErr(err1, "write %s to data.tar.gz", src)
72+
md5sum.Add(f, h)
73+
case '~':
74+
err1 := filepath.Walk(src[1:], func(path string, info fs.FileInfo, e error) error {
75+
if e != nil {
76+
return e
77+
}
78+
if info.IsDir() {
79+
return nil
80+
}
81+
ff, hh, ee := tg.WriteFile(path, strings.ReplaceAll(path, src[1:], dst))
82+
console.FatalIfErr(ee, "write %s to data.tar.gz", src)
83+
md5sum.Add(ff, hh)
84+
return nil
85+
})
86+
console.FatalIfErr(err1, "write %s to data.tar.gz", src)
87+
default:
6488
f, h, err1 = tg.WriteFile(src, dst)
65-
}
66-
if err1 != nil {
6789
console.FatalIfErr(err1, "write %s to data.tar.gz", src)
68-
} else {
6990
md5sum.Add(f, h)
7091
}
7192
}

pkg/archive/writer.go

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (v *TGZWriter) WriteData(filename string, b []byte) (string, string, error)
5959
Mode: int64(0644),
6060
Size: int64(len(b)),
6161
Typeflag: tar.TypeReg,
62+
Format: tar.FormatGNU,
6263
}
6364
if err := v.tar.WriteHeader(hdr); err != nil {
6465
return utils.CleanPath(dst), "", err
@@ -91,6 +92,7 @@ func (v *TGZWriter) WriteFile(src, dst string) (string, string, error) {
9192
Mode: int64(stat.Mode()),
9293
Size: stat.Size(),
9394
Typeflag: tar.TypeReg,
95+
Format: tar.FormatGNU,
9496
}
9597
if err := v.tar.WriteHeader(hdr); err != nil {
9698
return utils.CleanPath(dst), "", err
@@ -122,6 +124,7 @@ func (v *TGZWriter) mkdirAll(filename string) error {
122124
ModTime: time.Now(),
123125
Mode: int64(0755),
124126
Typeflag: tar.TypeDir,
127+
Format: tar.FormatGNU,
125128
}
126129
if err := v.tar.WriteHeader(hdr); err != nil {
127130
return err

pkg/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"regexp"
88

99
"github.com/dewep-online/deb-builder/pkg/utils"
10-
"gopkg.in/yaml.v2"
10+
"gopkg.in/yaml.v3"
1111
)
1212

1313
const ConfigFileName = ".deb.yaml"

pkg/exec/common.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import (
1212
func Build(conf *config.Config, cb func(arch string)) {
1313
for _, v := range conf.Architecture {
1414

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

1921
cb(v)
2022
}

pkg/packages/name.go

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ var pkgArchAlias = map[string]string{
1212
"386": "i386",
1313
}
1414

15+
func SplitVersion(v string) string {
16+
if strings.Contains(v, ":") {
17+
vv := strings.SplitN(v, ":", 2)
18+
if len(vv) == 2 {
19+
return vv[1]
20+
}
21+
}
22+
return v
23+
}
24+
1525
func BuildName(dir, name, version, arch string) (string, string, string) {
1626
if v, ok := pkgArchAlias[arch]; ok {
1727
arch = v

pkg/packages/name_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package packages
2+
3+
import "testing"
4+
5+
func TestUnit_SplitVersion(t *testing.T) {
6+
type args struct {
7+
v string
8+
}
9+
tests := []struct {
10+
name string
11+
args args
12+
want string
13+
}{
14+
{name: "Case1", args: args{v: "1:1.1.1"}, want: "1.1.1"},
15+
{name: "Case2", args: args{v: "1.1.1.1"}, want: "1.1.1.1"},
16+
}
17+
for _, tt := range tests {
18+
t.Run(tt.name, func(t *testing.T) {
19+
if got := SplitVersion(tt.args.v); got != tt.want {
20+
t.Errorf("SplitVersion() = %v, want %v", got, tt.want)
21+
}
22+
})
23+
}
24+
}

pkg/pgp/pgp.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"crypto"
66
"io"
77

8-
"github.com/pkg/errors"
8+
"github.com/deweppro/go-errors"
99
"golang.org/x/crypto/openpgp"
1010
"golang.org/x/crypto/openpgp/armor"
1111
"golang.org/x/crypto/openpgp/clearsign"
@@ -32,22 +32,22 @@ func NewPGP() *PGP {
3232
func (v *PGP) LoadPrivateKey(r io.ReadSeeker, passwd string) error {
3333
block, err := armor.Decode(r)
3434
if err != nil {
35-
return errors.Wrap(err, "Armor decode")
35+
return errors.WrapMessage(err, "Armor decode")
3636
}
3737
if block.Type != openpgp.PrivateKeyType {
38-
return errors.Wrap(err, "invalid key type")
38+
return errors.WrapMessage(err, "invalid key type")
3939
}
4040
if _, err = r.Seek(0, 0); err != nil {
41-
return errors.Wrap(err, "seek file")
41+
return errors.WrapMessage(err, "seek file")
4242
}
4343
keys, err := openpgp.ReadArmoredKeyRing(r)
4444
if err != nil {
45-
return errors.Wrap(err, "read key")
45+
return errors.WrapMessage(err, "read key")
4646
}
4747
v.key = keys[0]
4848
if v.key.PrivateKey.Encrypted {
4949
if err := v.key.PrivateKey.Decrypt([]byte(passwd)); err != nil {
50-
return errors.Wrap(err, "invalid password")
50+
return errors.WrapMessage(err, "invalid password")
5151
}
5252
}
5353
return nil

0 commit comments

Comments
 (0)