2024-02-11 01:00:05 -06:00
|
|
|
// This window, when it's hidden, still exists to the application
|
|
|
|
// so it can be treated as if it really exists
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-11 03:51:37 -06:00
|
|
|
"fmt"
|
2024-02-11 01:00:05 -06:00
|
|
|
"os"
|
2024-02-11 03:51:37 -06:00
|
|
|
"strings"
|
2024-02-11 01:00:05 -06:00
|
|
|
|
|
|
|
"go.wit.com/gui"
|
|
|
|
"go.wit.com/lib/gadgets"
|
2024-02-11 02:16:51 -06:00
|
|
|
"go.wit.com/lib/gui/shell"
|
2024-02-11 01:00:05 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var apple *gui.Node
|
|
|
|
|
|
|
|
// This initializes the first window, a group and a button
|
|
|
|
func makebasicWindow() *gadgets.BasicWindow {
|
|
|
|
log.Warn("init basicWindow state")
|
|
|
|
basicWindow = gadgets.NewBasicWindow(myGui, "Create .deb files for GO applications")
|
|
|
|
basicWindow.Make()
|
|
|
|
basicWindow.Custom = func() {
|
|
|
|
log.Info("got to close")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
box1 := basicWindow.Box()
|
2024-02-11 02:16:51 -06:00
|
|
|
control := newControl(box1)
|
2024-02-11 01:00:05 -06:00
|
|
|
|
|
|
|
vbox := box1.Box().Horizontal()
|
|
|
|
group1 := vbox.NewGroup("controls").Horizontal() // Vertical()
|
2024-02-11 02:16:51 -06:00
|
|
|
|
2024-02-11 01:00:05 -06:00
|
|
|
group1.NewButton("go build", func() {
|
2024-02-11 02:16:51 -06:00
|
|
|
shell.Run([]string{"go", "build", "-v", "-x"})
|
|
|
|
})
|
|
|
|
|
|
|
|
group1.NewButton("read control file", func() {
|
|
|
|
control.readControlFile()
|
2024-02-11 01:00:05 -06:00
|
|
|
})
|
2024-02-11 02:16:51 -06:00
|
|
|
|
2024-02-11 01:00:05 -06:00
|
|
|
group1.NewButton("Make .deb", func() {
|
2024-02-11 03:11:41 -06:00
|
|
|
basicWindow.Disable()
|
|
|
|
if control.buildPackage() {
|
|
|
|
log.Info("build worked")
|
|
|
|
} else {
|
|
|
|
log.Warn("build failed")
|
|
|
|
}
|
|
|
|
basicWindow.Enable()
|
2024-02-11 01:00:05 -06:00
|
|
|
})
|
2024-02-11 02:16:51 -06:00
|
|
|
|
2024-02-11 01:00:05 -06:00
|
|
|
group1.NewButton("open repo", func() {
|
|
|
|
})
|
|
|
|
/*
|
|
|
|
group1.NewButton("show apple", func() {
|
|
|
|
apple.Show()
|
|
|
|
})
|
|
|
|
apple = group1.NewButton("apple", func() {
|
|
|
|
log.Info("is not a pear")
|
|
|
|
})
|
|
|
|
*/
|
|
|
|
|
|
|
|
return basicWindow
|
|
|
|
}
|
2024-02-11 03:11:41 -06:00
|
|
|
|
|
|
|
func (c *controlFile) buildPackage() bool {
|
|
|
|
if c.readControlFile() == nil {
|
|
|
|
log.Warn("scan worked")
|
|
|
|
} else {
|
|
|
|
log.Warn("scan failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if shell.Run([]string{"go", "build", "-v", "-x"}) {
|
|
|
|
log.Warn("build worked")
|
|
|
|
} else {
|
|
|
|
log.Warn("build failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
filename := c.Package.String()
|
|
|
|
if filename == "" {
|
|
|
|
log.Warn("build failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !shell.Exists(filename) {
|
|
|
|
log.Warn("build failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
arch := c.Architecture.String()
|
2024-02-11 03:51:37 -06:00
|
|
|
version := "0.0.0"
|
|
|
|
c.Version.SetText(version)
|
2024-02-11 03:11:41 -06:00
|
|
|
|
|
|
|
debname := filename + "_" + version + "_" + arch + ".deb"
|
|
|
|
|
2024-02-11 03:51:37 -06:00
|
|
|
if !shell.Mkdir("files/usr/bin") {
|
|
|
|
log.Warn("mkdir failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !shell.Mkdir("files/usr/lib/" + filename) {
|
|
|
|
log.Warn("mkdir failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if shell.Exists("files/DEBIAN") {
|
|
|
|
if !shell.Run([]string{"rm", "-rf", "files/DEBIAN"}) {
|
|
|
|
log.Warn("rm failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if shell.Exists("files/DEBIAN") {
|
|
|
|
log.Warn("rm failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !shell.Mkdir("files/DEBIAN") {
|
|
|
|
log.Warn("mkdir failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !shell.Run([]string{"cp", filename, "files/usr/bin"}) {
|
|
|
|
log.Warn("cp failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !shell.Run([]string{"strip", "files/usr/bin/" + filename}) {
|
|
|
|
log.Warn("strip failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !shell.Run([]string{"cp", "README.md", "files/usr/lib/" + filename}) {
|
|
|
|
log.Warn("cp failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !c.writeFiles() {
|
|
|
|
log.Warn("write control file failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-02-11 03:11:41 -06:00
|
|
|
shell.Run([]string{"dpkg-deb", "--build", "files", debname})
|
|
|
|
if shell.Exists(debname) {
|
|
|
|
log.Warn("build worked")
|
|
|
|
} else {
|
|
|
|
log.Warn("build failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2024-02-11 03:51:37 -06:00
|
|
|
|
|
|
|
func (c *controlFile) writeFiles() bool {
|
|
|
|
cf, err := os.OpenFile("files/DEBIAN/control", os.O_RDWR|os.O_CREATE, 0644)
|
|
|
|
if err != nil {
|
|
|
|
log.Info("open control file failed", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
fmt.Fprintln(cf, "Package:", c.Package.String())
|
|
|
|
fmt.Fprintln(cf, "Source:", c.Source.String())
|
|
|
|
fmt.Fprintln(cf, "Version:", c.Version.String())
|
|
|
|
fmt.Fprintln(cf, "Architecture:", c.Architecture.String())
|
|
|
|
fmt.Fprintln(cf, "Depends:", c.Depends.String())
|
|
|
|
fmt.Fprintln(cf, "Build-Depends:", c.BuildDepends.String())
|
|
|
|
fmt.Fprintln(cf, "Maintainer:", c.Maintainer.String())
|
|
|
|
desc := c.Description.String()
|
|
|
|
parts := strings.Split(desc, "\n")
|
|
|
|
fmt.Fprintln(cf, "Description:", strings.Join(parts, " \n"))
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|