compute control file if it doesn't exist

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-11 21:49:39 -06:00
parent 98293e4bf9
commit b3eea67983
6 changed files with 71 additions and 19 deletions

View File

@ -1,10 +1,10 @@
.PHONY: debian
run: build
./go-deb --repo go.wit.com/apps/control-panel-dns
./go-deb --repo go.wit.com/apps/autotypist
no-gui: build
./go-deb --no-gui --repo go.wit.com/apps/control-panel-dns
./go-deb --no-gui --repo go.wit.com/apps/autotypist
build:
-cp ~/go/src/go.wit.com/toolkits/*.so resources/

View File

@ -1,4 +1,3 @@
// This is a simple example
package main
import (

View File

@ -80,6 +80,3 @@ func newControl(parent *gui.Node) *controlBox {
return c
}
func scanConfigFile() {
}

11
main.go
View File

@ -42,8 +42,17 @@ func main() {
filepath := filepath.Join("/home/jcarr/go/src", args.Repo)
os.Chdir(filepath)
// scan the repo
cBox.addRepo(args.Repo)
cBox.readControlFile()
// look for a 'config' file in the repo
if cBox.readControlFile() == nil {
log.Warn("scan worked")
} else {
log.Warn("scan failed")
}
cBox.computeControlValues()
// verify the values for the package
if args.NoGui {
if cBox.buildPackage() {
log.Info("build worked")

View File

@ -2,6 +2,7 @@ package main
import (
"bufio"
"errors"
"os"
"strings"
@ -13,6 +14,7 @@ func (c *controlBox) readControlFile() error {
file, err := os.Open("control")
if err != nil {
log.Warn("readControlFile() could not find the file")
return errors.New("'control': file not found")
}
defer file.Close()

View File

@ -56,11 +56,10 @@ func makebasicWindow() *gadgets.BasicWindow {
}
func (c *controlBox) buildPackage() bool {
if c.readControlFile() == nil {
log.Warn("scan worked")
} else {
log.Warn("scan failed")
return false
// TODO: if dirty, set GO111MODULE
// also, if last tag != version
if c.status.CheckDirty() {
os.Setenv("GO111MODULE", "off")
}
if shell.Run([]string{"go", "build", "-v", "-x"}) {
log.Warn("build worked")
@ -91,10 +90,6 @@ func (c *controlBox) buildPackage() bool {
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")
@ -117,10 +112,29 @@ func (c *controlBox) buildPackage() bool {
log.Warn("strip failed")
return false
}
if !shell.Run([]string{"cp", "README.md", "files/usr/lib/" + filename}) {
log.Warn("cp failed")
return false
// put the README in there (if missing, generate it?)
var readme string = ""
if shell.Exists("README.md") {
readme = "README.md"
}
if shell.Exists("README") {
readme = "README"
}
if readme != "" {
path := filepath.Join("files/usr/lib/" + filename)
if !shell.Mkdir(path) {
log.Warn("mkdir failed")
return false
}
if !shell.Run([]string{"cp", readme, path}) {
log.Warn("cp failed")
return false
}
}
if !c.writeFiles() {
log.Warn("write control file failed")
return false
@ -164,3 +178,34 @@ func (c *controlBox) writeFiles() bool {
return true
}
// try to guess or figure out the config file values
// if there is not a control file
func (c *controlBox) computeControlValues() bool {
if c.Package.String() == "" {
// get the package name from the repo name
path := c.pathL.String()
parts := strings.Split(path, "/")
name := parts[len(parts) - 1]
c.Package.SetText(name)
}
if c.Source.String() == "" {
c.Source.SetText(c.Package.String())
}
if c.BuildDepends.String() == "" {
c.BuildDepends.SetText("golang")
}
if c.Recommends.String() == "" {
c.Recommends.SetText("go-gui-toolkits")
}
// TODO: get this from the git log
if c.Maintainer.String() == "" {
c.Maintainer.SetText("Jeff Carr <jcarr@wit.com>")
}
// TODO: get this from gitea (or gitlab or github, etc)
// or from the README.md ?
if c.Description.String() == "" {
c.Description.SetText("no control file")
}
return true
}