cleanup files/ after packaging

This commit is contained in:
Jeff Carr 2024-03-02 15:58:56 -06:00
parent dc4924306d
commit 6fd6559203
5 changed files with 41 additions and 22 deletions

View File

@ -3,6 +3,10 @@
run: build run: build
./go-deb --repo go.wit.com/apps/autotypist ./go-deb --repo go.wit.com/apps/autotypist
vet:
@GO111MODULE=off go vet
@echo this go library package builds okay
no-gui: build no-gui: build
./go-deb --no-gui --repo go.wit.com/apps/autotypist ./go-deb --no-gui --repo go.wit.com/apps/autotypist

View File

@ -15,7 +15,7 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
func (c *controlBox) buildPackage() error { func (c *controlBox) buildPackage() (bool, error) {
// TODO: if dirty, set GO111MODULE // TODO: if dirty, set GO111MODULE
// also, if last tag != version // also, if last tag != version
/* /*
@ -29,12 +29,12 @@ func (c *controlBox) buildPackage() error {
filename := c.Package.String() filename := c.Package.String()
if filename == "" { if filename == "" {
return errors.New("filename is blank") return false, errors.New("filename is blank")
} }
homeDir, err := os.UserHomeDir() homeDir, err := os.UserHomeDir()
if err != nil { if err != nil {
return err return false, err
} }
arch := c.Architecture.String() arch := c.Architecture.String()
@ -43,6 +43,11 @@ func (c *controlBox) buildPackage() error {
version = "0.0.0" version = "0.0.0"
} }
debname := filename + "_" + version + "_" + arch + ".deb" 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 var fullfilename string
if args.Release { if args.Release {
fullfilename = filepath.Join(homeDir, "go/bin", filename) fullfilename = filepath.Join(homeDir, "go/bin", filename)
@ -53,7 +58,7 @@ func (c *controlBox) buildPackage() error {
if shell.Exists(fullfilename) { if shell.Exists(fullfilename) {
// something wrong // something wrong
return errors.New("binary existed before build") return false, errors.New("binary existed before build")
} }
if args.Release { if args.Release {
@ -63,7 +68,7 @@ func (c *controlBox) buildPackage() error {
if shell.Run(cmd) { if shell.Run(cmd) {
log.Warn("go install worked") log.Warn("go install worked")
} else { } else {
return errors.New("go install") return false, errors.New("go install")
} }
} else { } else {
// set the GO111 build var to true. pass the versions to the compiler manually // 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}) { if shell.Run([]string{"go", "build", "-v", "-x", "-ldflags", vldflag, "-ldflags", gldflag}) {
log.Warn("go build worked") log.Warn("go build worked")
} else { } else {
return errors.New("go build") return false, errors.New("go build")
} }
} }
if !shell.Exists(fullfilename) { if !shell.Exists(fullfilename) {
log.Warn("build failed. filename does not exist", 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.Exists("files") {
if shell.Run([]string{"rm", "-rf", "files"}) { if shell.Run([]string{"rm", "-rf", "files"}) {
log.Warn("rm failed") log.Warn("rm failed")
return errors.New("rm files/") return false, errors.New("rm files/")
} }
} }
if shell.Exists("files") { if shell.Exists("files") {
log.Warn("rm failed") log.Warn("rm failed")
return errors.New("rm files/") return false, errors.New("rm files/")
} }
if !shell.Mkdir("files/DEBIAN") { if !shell.Mkdir("files/DEBIAN") {
return errors.New("mkdir files/DEBIAN") return false, errors.New("mkdir files/DEBIAN")
} }
if !shell.Mkdir("files/usr/bin") { if !shell.Mkdir("files/usr/bin") {
log.Warn("mkdir failed") 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"}) { if !shell.Run([]string{"cp", fullfilename, "files/usr/bin"}) {
log.Warn("cp failed") log.Warn("cp failed")
return errors.New("cp " + fullfilename) return false, errors.New("cp " + fullfilename)
} }
if !shell.Run([]string{"strip", "files/usr/bin/" + filename}) { if !shell.Run([]string{"strip", "files/usr/bin/" + filename}) {
log.Warn("strip failed") log.Warn("strip failed")
return errors.New("strip " + filename) return false, errors.New("strip " + filename)
} }
// put the README in there (if missing, generate it?) // put the README in there (if missing, generate it?)
@ -121,18 +126,20 @@ func (c *controlBox) buildPackage() error {
if readme != "" { if readme != "" {
path := filepath.Join("files/usr/lib/" + filename) path := filepath.Join("files/usr/lib/" + filename)
if !shell.Mkdir(path) { 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}) { if !shell.Run([]string{"cp", readme, path}) {
return errors.New("cp readme") return false, errors.New("cp readme")
} }
} }
if !c.writeFiles() { if !c.writeFiles() {
return errors.New("write control file") return false, errors.New("write control file")
} }
// experiment for the toolkit package // 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 c.status.Exists("build") {
if args.Release { if args.Release {
os.Unsetenv("GO111MODULE") os.Unsetenv("GO111MODULE")
@ -142,17 +149,23 @@ func (c *controlBox) buildPackage() error {
shell.Run([]string{"./build"}) shell.Run([]string{"./build"})
} }
fulldebname := filepath.Join(homeDir, "incoming", debname)
shell.Run([]string{"dpkg-deb", "--build", "files", fulldebname}) shell.Run([]string{"dpkg-deb", "--build", "files", fulldebname})
if shell.Exists(fulldebname) { if shell.Exists(fulldebname) {
} else { } else {
log.Warn("build failed") 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", "-I", fulldebname})
shell.Run([]string{"dpkg-deb", "-c", 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 { func (c *controlBox) writeFiles() bool {

View File

@ -49,7 +49,7 @@ func main() {
if args.NoGui { if args.NoGui {
shell.TestTerminalColor() shell.TestTerminalColor()
if err := cBox.buildPackage(); err == nil { if ok, err := cBox.buildPackage(); ok {
log.Info("build worked") log.Info("build worked")
} else { } else {
log.Warn("build failed:", err) log.Warn("build failed:", err)

View File

@ -1 +1,3 @@
#!/bin/sh #!/bin/sh
echo "in postinst. this is just a test"

View File

@ -36,7 +36,7 @@ func makebasicWindow() *gadgets.BasicWindow {
group1.NewButton("Make .deb", func() { group1.NewButton("Make .deb", func() {
basicWindow.Disable() basicWindow.Disable()
if err := cBox.buildPackage(); err == nil { if ok, err := cBox.buildPackage(); ok {
log.Info("build worked") log.Info("build worked")
} else { } else {
log.Warn("build failed", err) log.Warn("build failed", err)