summaryrefslogtreecommitdiff
path: root/main.go
blob: fc14458a16a3234412a7aff8bdcc9f1a74eb9d47 (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
package main

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

	"go.wit.com/lib/gui/prep"
	"go.wit.com/lib/gui/shell"
	"go.wit.com/lib/protobuf/zoopb"
)

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

// used for shell auto completion
var ARGNAME string = "mirrors" // todo: get this from $0 ?

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

func main() {
	me = new(mainType)
	me.sh = prep.Bash3(&argv) // add support for bash autocomplete with go-arg

	// read in protobuf file
	me.pb = zoopb.NewPackages()
	me.pb.Filename = "/home/mirrors/wit/mirrors.wit.com.pb"
	if err := me.pb.Load(); err != nil {
		if argv.Create {
			me.pb.BaseDir = "/home/mirrors/wit"
			me.pb.Save()
			me.sh.GoodExit("created new pb file: " + me.pb.Filename)
		} else {
			me.sh.BadExit("no config found. use --create to create one", err)
		}
	}

	if me.pb.BaseDir == "" {
		me.pb.BaseDir = "/home/mirrors/wit"
		me.pb.Save()
		me.sh.BadExit("pb.BaseDir is bank", nil)
	}

	if err := os.Chdir(me.pb.BaseDir); err != nil {
		me.sh.BadExit("no '"+me.pb.BaseDir+"' directory", err)
	}

	if !shell.IsDir("pool/") {
		me.sh.BadExit("no "+filepath.Join(me.pb.BaseDir, "pool")+" directory", errors.New("mount -a ? missing wit/pool/"))
	}

	if me.sh.Cmd == "" {
		// STANDARD START
		// walk for new .deb files
		s, err := doWalk()
		if err != nil {
			me.sh.BadExit(s, err)
		}

		// move files from inccoming into pooo/
		s, err = doIncoming(me.pb)
		if err != nil {
			me.sh.BadExit(s, err)
		}

		me.sh.GoodExit(s)
		// STANDARD START END
	}

	//// start standard argv subcommand processing here ////
	var s string
	var err error

	// handling of argv subcommands
	if argv.Incoming != nil {
		s, err = doIncoming(me.pb)
	}

	if argv.Walk != nil {
		s, err = doWalk()
	}

	if argv.Newest != nil {
		all := doGetNewest("amd64")
		s = "newest .deb files table: " + all.PrintTable()
	}

	if argv.List != nil {
		s, err = doList()
	}

	if argv.Verify != nil {
		s, err = doVerify()
	}

	if argv.Update != nil {
		err = doDistro()
	}

	if argv.MakeDists != nil {
		s, err = doMakeDists()
	}

	if argv.Everything != nil {
		s, err = doEverything()
	}

	if err != nil {
		me.sh.BadExit(s, err)
	}
	me.sh.GoodExit(s)
}