Skip to content

Commit

Permalink
Merge pull request #7 from dewep-online/develope
Browse files Browse the repository at this point in the history
build sub versions
  • Loading branch information
markus621 authored Feb 25, 2022
2 parents 6712a96 + ab511fe commit 0daaa1d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ tests:
ci:
bash scripts/ci.sh

deb: build
deb-builder build

install: build
@GO111MODULE=on GOOS=linux GOARCH=amd64 go build -o $(GOPATH)/bin/deb-builder ./cmd/deb-builder/
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/deweppro/go-app v1.4.2
github.com/deweppro/go-archives v1.0.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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/deweppro/go-algorithms v1.1.1 h1:FOzPuYmFuFGN6Nmcos5zC1WfD3Ya8XxUJ6Oi
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.2 h1:0kHfvhr3tD9r8QqVDSZttFPq0chaAwaXnK0atXeD5SY=
github.com/deweppro/go-archives v1.0.2/go.mod h1:GP2Or5TFSEWQAam/Q/jgFhLpcF0LroITKic654pQERk=
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=
Expand Down
31 changes: 20 additions & 11 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ func Build() console.CommandGetter {
setter.Flag(func(fs console.FlagsSetter) {
fs.StringVar("base-dir", utils.GetEnv("DEB_STORAGE_BASE_DIR", "/tmp/deb-storage"), "Deb package base storage")
fs.StringVar("tmp-dir", utils.GetEnv("DEB_BUILD_DIR", "/tmp/deb-build"), "Deb package build dir")
fs.StringVar("subver", "", "Set date for calc subversion time. Format: 2022-01-01")
})
setter.ExecFunc(func(_ []string, baseDir, tmpDir string, subver string) {
setter.ExecFunc(func(_ []string, baseDir, tmpDir string) {
conf, err := config.Detect()
console.FatalIfErr(err, "deb config not found")

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

subVersion := ""
if len(subver) > 0 {
pt, err := time.Parse("2006-01-02", subver)
console.FatalIfErr(err, "parse date for calc subversion")
subVersion = fmt.Sprintf("-%d", time.Now().Unix()-pt.Unix())
}

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

// check file version

subVersion := ""
debFileNameBuild := func() string {
return fmt.Sprintf("%s/%s_%s%s_%s.deb", storeDir, conf.Package, conf.Version, subVersion, arch)
}
debFile := debFileNameBuild()
for {
utils.FileStat(debFile, func(fi os.FileInfo) {
subVersion = fmt.Sprintf("-%d", time.Now().Unix()-fi.ModTime().Unix())
debFile = debFileNameBuild()
})

if !utils.FileExist(debFile) {
break
}
<-time.After(time.Second)
}

// package

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

// build deb

debFile := fmt.Sprintf("%s/%s_%s%s_%s.deb", storeDir, conf.Package, conf.Version, subVersion, arch)
console.FatalIfErr(os.RemoveAll(debFile), "remove old deb file")
deb, err := ar.Open(debFile, 0644)
console.FatalIfErr(err, "create %s", debFile)
console.FatalIfErr(deb.Write("debian-binary", []byte("2.0\n"), 0644), "write debian-binary to %s", debFile)
Expand Down
6 changes: 6 additions & 0 deletions pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func FileExist(filename string) bool {
return err == nil
}

func FileStat(filename string, callFunc func(fi os.FileInfo)) {
if info, err := os.Stat(filename); err == nil {
callFunc(info)
}
}

func CopyFile(dst, src string) error {
source, err := os.OpenFile(src, os.O_RDONLY, 0)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions scripts/postinst.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash
1 change: 1 addition & 0 deletions scripts/postrm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash
3 changes: 3 additions & 0 deletions scripts/preinst.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash


1 change: 1 addition & 0 deletions scripts/prerm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash

0 comments on commit 0daaa1d

Please sign in to comment.