diff --git a/Makefile b/Makefile index 2f6a655..5d2e725 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,10 @@ run: build ./go-deb --repo go.wit.com/apps/autotypist +vet: + @GO111MODULE=off go vet + @echo this go library package builds okay + no-gui: build ./go-deb --no-gui --repo go.wit.com/apps/autotypist diff --git a/buildPackage.go b/buildPackage.go index a75634e..b45f0d6 100644 --- a/buildPackage.go +++ b/buildPackage.go @@ -15,7 +15,7 @@ import ( "go.wit.com/log" ) -func (c *controlBox) buildPackage() error { +func (c *controlBox) buildPackage() (bool, error) { // TODO: if dirty, set GO111MODULE // also, if last tag != version /* @@ -29,12 +29,12 @@ func (c *controlBox) buildPackage() error { filename := c.Package.String() if filename == "" { - return errors.New("filename is blank") + return false, errors.New("filename is blank") } homeDir, err := os.UserHomeDir() if err != nil { - return err + return false, err } arch := c.Architecture.String() @@ -43,6 +43,11 @@ func (c *controlBox) buildPackage() error { version = "0.0.0" } debname := filename + "_" + version + "_" + arch + ".deb" + fulldebname := filepath.Join(homeDir, "incoming", debname) + if shell.Exists(fulldebname) { + return true, errors.New("debian package already built: " + fulldebname) + } + var fullfilename string if args.Release { fullfilename = filepath.Join(homeDir, "go/bin", filename) @@ -53,7 +58,7 @@ func (c *controlBox) buildPackage() error { if shell.Exists(fullfilename) { // something wrong - return errors.New("binary existed before build") + return false, errors.New("binary existed before build") } if args.Release { @@ -63,7 +68,7 @@ func (c *controlBox) buildPackage() error { if shell.Run(cmd) { log.Warn("go install worked") } else { - return errors.New("go install") + return false, errors.New("go install") } } else { // set the GO111 build var to true. pass the versions to the compiler manually @@ -73,39 +78,39 @@ func (c *controlBox) buildPackage() error { if shell.Run([]string{"go", "build", "-v", "-x", "-ldflags", vldflag, "-ldflags", gldflag}) { log.Warn("go build worked") } else { - return errors.New("go build") + return false, errors.New("go build") } } if !shell.Exists(fullfilename) { log.Warn("build failed. filename does not exist", fullfilename) - return errors.New("missing" + fullfilename) + return false, errors.New("missing" + fullfilename) } if shell.Exists("files") { if shell.Run([]string{"rm", "-rf", "files"}) { log.Warn("rm failed") - return errors.New("rm files/") + return false, errors.New("rm files/") } } if shell.Exists("files") { log.Warn("rm failed") - return errors.New("rm files/") + return false, errors.New("rm files/") } if !shell.Mkdir("files/DEBIAN") { - return errors.New("mkdir files/DEBIAN") + return false, errors.New("mkdir files/DEBIAN") } if !shell.Mkdir("files/usr/bin") { log.Warn("mkdir failed") - return errors.New("mkdir files/usr/bin") + return false, errors.New("mkdir files/usr/bin") } if !shell.Run([]string{"cp", fullfilename, "files/usr/bin"}) { log.Warn("cp failed") - return errors.New("cp " + fullfilename) + return false, errors.New("cp " + fullfilename) } if !shell.Run([]string{"strip", "files/usr/bin/" + filename}) { log.Warn("strip failed") - return errors.New("strip " + filename) + return false, errors.New("strip " + filename) } // put the README in there (if missing, generate it?) @@ -121,18 +126,20 @@ func (c *controlBox) buildPackage() error { if readme != "" { path := filepath.Join("files/usr/lib/" + filename) if !shell.Mkdir(path) { - return errors.New("no files/usr/lib") + return false, errors.New("no files/usr/lib") } if !shell.Run([]string{"cp", readme, path}) { - return errors.New("cp readme") + return false, errors.New("cp readme") } } if !c.writeFiles() { - return errors.New("write control file") + return false, errors.New("write control file") } // experiment for the toolkit package + // if the git repo has a "./build" script run it before packaging + // this way the user can put custom files in the .deb package if c.status.Exists("build") { if args.Release { os.Unsetenv("GO111MODULE") @@ -142,17 +149,23 @@ func (c *controlBox) buildPackage() error { shell.Run([]string{"./build"}) } - fulldebname := filepath.Join(homeDir, "incoming", debname) - shell.Run([]string{"dpkg-deb", "--build", "files", fulldebname}) if shell.Exists(fulldebname) { } else { log.Warn("build failed") - return errors.New("dpkg-deb --build worked") + return false, errors.New("dpkg-deb --build failed") } shell.Run([]string{"dpkg-deb", "-I", fulldebname}) shell.Run([]string{"dpkg-deb", "-c", fulldebname}) - return nil + + // cleanup files + if shell.Exists("files") { + if shell.Run([]string{"rm", "-rf", "files"}) { + log.Warn("rm failed") + return false, errors.New("rm files/") + } + } + return true, nil } func (c *controlBox) writeFiles() bool { diff --git a/main.go b/main.go index fdc214e..4259608 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,7 @@ func main() { if args.NoGui { shell.TestTerminalColor() - if err := cBox.buildPackage(); err == nil { + if ok, err := cBox.buildPackage(); ok { log.Info("build worked") } else { log.Warn("build failed:", err) diff --git a/postinst b/postinst index 1a24852..3f7ba5e 100755 --- a/postinst +++ b/postinst @@ -1 +1,3 @@ #!/bin/sh + +echo "in postinst. this is just a test" diff --git a/stateWindow.go b/stateWindow.go index cd68667..a87f415 100644 --- a/stateWindow.go +++ b/stateWindow.go @@ -36,7 +36,7 @@ func makebasicWindow() *gadgets.BasicWindow { group1.NewButton("Make .deb", func() { basicWindow.Disable() - if err := cBox.buildPackage(); err == nil { + if ok, err := cBox.buildPackage(); ok { log.Info("build worked") } else { log.Warn("build failed", err)