Skip to content

Commit 0daaa1d

Browse files
authored
Merge pull request #7 from dewep-online/develope
build sub versions
2 parents 6712a96 + ab511fe commit 0daaa1d

File tree

9 files changed

+38
-14
lines changed

9 files changed

+38
-14
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ tests:
2020
ci:
2121
bash scripts/ci.sh
2222

23+
deb: build
24+
deb-builder build
25+
2326
install: build
2427
@GO111MODULE=on GOOS=linux GOARCH=amd64 go build -o $(GOPATH)/bin/deb-builder ./cmd/deb-builder/

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.16
44

55
require (
66
github.com/deweppro/go-app v1.4.2
7-
github.com/deweppro/go-archives v1.0.2
7+
github.com/deweppro/go-archives v1.0.3
88
github.com/pkg/errors v0.9.1
99
github.com/stretchr/testify v1.7.0
1010
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ github.com/deweppro/go-algorithms v1.1.1 h1:FOzPuYmFuFGN6Nmcos5zC1WfD3Ya8XxUJ6Oi
55
github.com/deweppro/go-algorithms v1.1.1/go.mod h1:h50x8PTIGbiIhOh5vH/10J39vTzi2UmG7TVLupellqY=
66
github.com/deweppro/go-app v1.4.2 h1:mpYjwyC2b6089CdRhJuJPMeiETu4ldaCXE9fSMQwarQ=
77
github.com/deweppro/go-app v1.4.2/go.mod h1:Tm4RUCOw7R/qnomzYT/rIykfqRI1zNfDArpHsaLgl/I=
8-
github.com/deweppro/go-archives v1.0.2 h1:0kHfvhr3tD9r8QqVDSZttFPq0chaAwaXnK0atXeD5SY=
9-
github.com/deweppro/go-archives v1.0.2/go.mod h1:GP2Or5TFSEWQAam/Q/jgFhLpcF0LroITKic654pQERk=
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=
1010
github.com/deweppro/go-chan-pool v1.1.1 h1:TCoQhgXG6GP7zTJiKwOmqSeaR64651cWFpVniD5BIys=
1111
github.com/deweppro/go-chan-pool v1.1.1/go.mod h1:lEtDI+rhCE/ES1i9q0FOtYgjMftw5PCCepit4a+9Uds=
1212
github.com/deweppro/go-logger v1.2.3 h1:icOV4UwBGc8s9S8zcNIcDjBK00qQtcuBZzBgRmMaq24=

internal/commands/build.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ func Build() console.CommandGetter {
2222
setter.Flag(func(fs console.FlagsSetter) {
2323
fs.StringVar("base-dir", utils.GetEnv("DEB_STORAGE_BASE_DIR", "/tmp/deb-storage"), "Deb package base storage")
2424
fs.StringVar("tmp-dir", utils.GetEnv("DEB_BUILD_DIR", "/tmp/deb-build"), "Deb package build dir")
25-
fs.StringVar("subver", "", "Set date for calc subversion time. Format: 2022-01-01")
2625
})
27-
setter.ExecFunc(func(_ []string, baseDir, tmpDir string, subver string) {
26+
setter.ExecFunc(func(_ []string, baseDir, tmpDir string) {
2827
conf, err := config.Detect()
2928
console.FatalIfErr(err, "deb config not found")
3029

@@ -35,15 +34,27 @@ func Build() console.CommandGetter {
3534
storeDir := fmt.Sprintf("%s/%s/%s", baseDir, conf.Package[0:1], conf.Package)
3635
console.FatalIfErr(os.MkdirAll(storeDir, 0755), "creating storage directory")
3736

38-
subVersion := ""
39-
if len(subver) > 0 {
40-
pt, err := time.Parse("2006-01-02", subver)
41-
console.FatalIfErr(err, "parse date for calc subversion")
42-
subVersion = fmt.Sprintf("-%d", time.Now().Unix()-pt.Unix())
43-
}
44-
4537
exec.Build(conf, func(arch string) {
4638

39+
// check file version
40+
41+
subVersion := ""
42+
debFileNameBuild := func() string {
43+
return fmt.Sprintf("%s/%s_%s%s_%s.deb", storeDir, conf.Package, conf.Version, subVersion, arch)
44+
}
45+
debFile := debFileNameBuild()
46+
for {
47+
utils.FileStat(debFile, func(fi os.FileInfo) {
48+
subVersion = fmt.Sprintf("-%d", time.Now().Unix()-fi.ModTime().Unix())
49+
debFile = debFileNameBuild()
50+
})
51+
52+
if !utils.FileExist(debFile) {
53+
break
54+
}
55+
<-time.After(time.Second)
56+
}
57+
4758
// package
4859

4960
cpkg := control.NewControlPkg(conf)
@@ -95,8 +106,6 @@ func Build() console.CommandGetter {
95106

96107
// build deb
97108

98-
debFile := fmt.Sprintf("%s/%s_%s%s_%s.deb", storeDir, conf.Package, conf.Version, subVersion, arch)
99-
console.FatalIfErr(os.RemoveAll(debFile), "remove old deb file")
100109
deb, err := ar.Open(debFile, 0644)
101110
console.FatalIfErr(err, "create %s", debFile)
102111
console.FatalIfErr(deb.Write("debian-binary", []byte("2.0\n"), 0644), "write debian-binary to %s", debFile)

pkg/utils/common.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ func FileExist(filename string) bool {
3737
return err == nil
3838
}
3939

40+
func FileStat(filename string, callFunc func(fi os.FileInfo)) {
41+
if info, err := os.Stat(filename); err == nil {
42+
callFunc(info)
43+
}
44+
}
45+
4046
func CopyFile(dst, src string) error {
4147
source, err := os.OpenFile(src, os.O_RDONLY, 0)
4248
if err != nil {

scripts/postinst.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/bin/bash

scripts/postrm.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/bin/bash

scripts/preinst.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+

scripts/prerm.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/bin/bash

0 commit comments

Comments
 (0)