summaryrefslogtreecommitdiff
path: root/control.write.go
diff options
context:
space:
mode:
Diffstat (limited to 'control.write.go')
-rw-r--r--control.write.go106
1 files changed, 106 insertions, 0 deletions
diff --git a/control.write.go b/control.write.go
new file mode 100644
index 0000000..b2c31ba
--- /dev/null
+++ b/control.write.go
@@ -0,0 +1,106 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "strconv"
+ "strings"
+ "time"
+
+ "github.com/go-cmd/cmd"
+ "go.wit.com/lib/protobuf/gitpb"
+ "go.wit.com/log"
+)
+
+func writeDebianControlFile(repo *gitpb.Repo) bool {
+ filename := "files/DEBIAN/control"
+ cf, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
+ if err != nil {
+ log.Info("open control file failed", err)
+ return false
+ }
+ fmt.Fprintln(cf, "Package:", repo.Control["Package"]) // c.Package.String())
+ fmt.Fprintln(cf, "Source:", repo.Control["Source"]) // c.Source.String())
+ fmt.Fprintln(cf, "Version:", repo.Control["Version"])
+ if repo.Control["Architecture"] == "" {
+ repo.Control["Architecture"] = "amd64"
+ }
+ fmt.Fprintln(cf, "Architecture:", repo.Control["Architecture"]) // c.Architecture.String())
+
+ writeControlVar(cf, repo, "Depends")
+ writeControlVar(cf, repo, "Build-Depends")
+ writeControlVar(cf, repo, "Maintainer")
+ writeControlVar(cf, repo, "Packager")
+ writeControlVar(cf, repo, "GoPath")
+ writeControlVar(cf, repo, "URL")
+ writeControlVar(cf, repo, "Conflicts")
+
+ stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC")
+ // update to now now despite what the GUI is showing
+ fmt.Fprintln(cf, "Package-Build-Date:", stamp)
+ fmt.Fprintln(cf, "Git-Tag-Date:", "todo: get from repo")
+
+ desc, _ := repo.Control["Description"] // c.Description.String()
+ parts := strings.Split(desc, "\n")
+ fmt.Fprintln(cf, "Description:", strings.Join(parts, "\n "))
+
+ log.Info("file written as:", filename)
+ return true
+}
+
+func writeControlVar(f *os.File, repo *gitpb.Repo, varname string) {
+ val, _ := repo.Control[varname]
+ if val == "" {
+ return
+ }
+ fmt.Fprintln(f, varname+":", val)
+}
+
+// try to guess or figure out the config file values
+// if there is not a control file
+func computeControlValues(repo *gitpb.Repo) bool {
+ if repo.Control["Package"] == "" {
+ // get the package name from the repo name
+ path := repo.Control["pathL"] // c.pathL.String()
+ parts := strings.Split(path, "/")
+ name := parts[len(parts)-1]
+ repo.Control["Package"] = name
+ }
+ if repo.Control["Source"] == "" {
+ repo.Control["Source"] = repo.Control["Package"]
+ }
+ if repo.Control["Build-Depends"] == "" {
+ repo.Control["Build-Depends"] = repo.Control["golang"]
+ }
+ if repo.Control["Recommends"] == "" {
+ repo.Control["Recommends"] = repo.Control["go-gui-toolkits"]
+ }
+ if repo.Control["Maintainer"] == "" {
+ repo.Control["Maintainer"] = "todo: get from ENV"
+ }
+ if repo.Control["Description"] == "" {
+ repo.Control["Description"] = "todo: put URL here"
+ }
+ return true
+}
+
+// stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC")
+
+func getDateStamp(tag string) string {
+ var r cmd.Status
+ r = me.repo.Run([]string{"git", "log", "-1", "--format=%at", tag})
+
+ out := strings.Join(r.Stdout, "\n")
+ out = strings.TrimSpace(out)
+
+ // Convert the string to an integer
+ gitTagTimestampInt, err := strconv.ParseInt(out, 10, 64)
+ if err != nil {
+ fmt.Println("Error converting timestamp:", err)
+ return "git tag " + tag + " unknown"
+ }
+
+ // Parse the Unix timestamp into a time.Time object
+ gitTagDate := time.Unix(gitTagTimestampInt, 0)
+ return gitTagDate.UTC().Format("2006-01-02_15:04:05_UTC") // close to RFC3339
+}