summaryrefslogtreecommitdiff
path: root/main.go
blob: e2a8967f01db95f23f52f19f7c849657749bc3ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main

import (
	"embed"
	"os"
	"path/filepath"
	"time"

	"go.wit.com/lib/debian"
	"go.wit.com/lib/gui/prep"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/lib/protobuf/zoopb"
	"go.wit.com/log"
)

// sent from -ldflags
var VERSION string
var BUILDTIME string

//go:embed resources/*
var resources embed.FS

var ARGNAME string = "go-deb"
var argv args

func main() {
	me = new(mainType)
	me.sh = prep.Autocomplete(&argv) // adds shell auto complete to go-args
	me.pb = new(zoopb.Package)

	wd, err := os.Getwd()
	if err != nil {
		me.sh.BadExit("your current directory does not exist err=", err)
	}

	if argv.Arch == "" {
		// looking forward to the day when this default is "riscv64"
		argv.Arch = "amd64"
	}

	me.repo, err = gitpb.NewRepo(wd)
	if err != nil {
		me.sh.BadExit("is this really a .git directory? err=", err)
	}

	data, err := os.ReadFile("control")
	if err != nil {
		me.sh.BadExit("you don't have a 'control' file", err)
	}

	log.Info("INITIAL PARSE:")
	log.Info(string(data))
	debian.ParseDpkgOutputIntoPB(me.pb, string(data))
	if argv.Arch == "" {
		me.pb.Architecture = "amd64"
	} else {
		me.pb.Architecture = argv.Arch
	}
	me.pb.Version = trimNonNumericPrefix(me.repo.GetCurrentVersion())
	me.pb.DebInfo.URL = me.repo.URL
	me.pb.DebInfo.Homepage = me.repo.URL // deprecate this usage (?)
	log.Info("INITIAL PARSE RESULT:")
	controlfile := debian.MakeControlFile(me.pb)
	log.Info(controlfile)
	log.Info("INITIAL PARSE END")
	// me.sh.GoodExit("rewriting this app")

	// build()
	if argv.Show != nil {
		log.Info("todo: show", me.repo.Namespace)
		okExit("")
	}
	if argv.Namespace != "" {
		me.repo.Namespace = argv.Namespace
	}
	log.Info("Namespace:", me.repo.GetNamespace(), "Fullpath:", me.repo.GetFullPath())

	// figure out where we are working from
	// os.Chdir to that directory
	var debpath string
	if me.repo == nil {
		os.Setenv("GO_DEB_CUSTOM", "true")
		debpath, _ = os.Getwd()
	} else {
		debpath = me.repo.GetFullPath()
	}
	_, basename := filepath.Split(debpath)
	me.repo.Namespace = basename
	os.Chdir(debpath)

	// look for a 'config' file in the repo
	if readControlFile(me.repo) == nil {
		log.Warn("scan worked")
	} else {
		log.Warn("scan failed")
	}
	// computeControlValues(me.repo)

	if argv.Dump != nil {
		for v := range me.repo.Control {
			log.Infof("CONTROL: %s: %s\n", v, me.repo.Control[v])
		}
		okExit("")
	}

	if argv.Gui != nil {
		// only load teh toolkit if you get this far
		me.myGui.Start() // loads the GUI toolkit
		doGui()
		debug()
	}

	log.Info("go-deb: attempting to build package")
	if ok, err := buildPackage(me.repo); ok {
		log.Info("build worked")
	} else {
		log.Warn("build failed:", err)
		os.Exit(-1)
	}
	os.Exit(0)
}

func debug() {
	time.Sleep(2 * time.Second)
	for {
		log.Info("idle loop() todo: could check for things here")
		time.Sleep(90 * time.Second)
	}
}