Skip to content

Commit

Permalink
add subversion
Browse files Browse the repository at this point in the history
  • Loading branch information
markus621 committed Feb 16, 2022
1 parent 1e16404 commit a94b40e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ vendorgo test -c`
*.out
vendor/
.deb.yaml
build/bin
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ tests:
ci:
bash scripts/ci.sh

install:
install: build
@GO111MODULE=on GOOS=linux GOARCH=amd64 go build -o $(GOPATH)/bin/deb-builder ./cmd/deb-builder/
19 changes: 14 additions & 5 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/dewep-online/deb-builder/pkg/archive"
"github.com/dewep-online/deb-builder/pkg/config"
Expand All @@ -18,10 +19,11 @@ func Build() console.CommandGetter {
setter.Setup("build", "build deb package")
setter.Example("build")
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("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) {
setter.ExecFunc(func(_ []string, baseDir, tmpDir string, subver string) {
conf, err := config.Detect()
console.FatalIfErr(err, "deb config not found")

Expand All @@ -32,6 +34,13 @@ 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) {

// package
Expand Down Expand Up @@ -61,7 +70,7 @@ func Build() console.CommandGetter {
ctrl := control.NewControl(conf)
ctrl.DataSize(tg.Size())
ctrl.Arch(arch)
ctrlFile, err := ctrl.Save(buildDir)
ctrlFile, err := ctrl.Save(buildDir, subVersion)
console.FatalIfErr(err, "create control")
cpkg.AddFile(ctrlFile)

Expand All @@ -85,7 +94,7 @@ func Build() console.CommandGetter {

// build deb

debFile := fmt.Sprintf("%s/%s_%s_%s.deb", storeDir, conf.Package, conf.Version, arch)
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 := archive.NewDeb(debFile)
console.FatalIfErr(err, "create %s", debFile)
Expand Down
6 changes: 3 additions & 3 deletions pkg/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func (v *Control) Arch(arch string) {
v.arch = arch
}

func (v *Control) Save(dir string) (string, error) {
func (v *Control) Save(dir string, subver string) (string, error) {
buf := &bytes.Buffer{}
controlFile := dir + "/control"
model := modelControl{
Package: v.conf.Package,
Source: v.conf.Source,
Version: v.conf.Version,
Version: v.conf.Version + subver,
Architecture: v.arch,
Maintainer: v.conf.Maintainer,
Size: v.size,
Expand All @@ -77,7 +77,7 @@ func (v *Control) Save(dir string) (string, error) {
cur += i

if cur >= descriptionMaxLen {
buf.WriteString("\n ")
buf.WriteString("\n")
cur = 0
}
}
Expand Down

0 comments on commit a94b40e

Please sign in to comment.