summaryrefslogtreecommitdiff
path: root/doInstall.go
blob: 3269c77fbf4cc9a6989887479469b76bfaf69c8b (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

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

	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func doInstallRepo(check *gitpb.Repo) error {
	repotype := check.GetRepoType()
	if repotype == "binary" || repotype == "plugin" {
		// we only want to process things that can be compiled with 'go build'
	} else {
		// log.Info("skipping repo", check.GetGoPath(), repotype)
		return nil
	}

	if me.forge.Config.IsReadOnly(check.GetGoPath()) {
		// ignore read only stuff
		return nil
	}

	if argv.Verbose || argv.Force {
		verbose := []string{"-v", "-x"}
		if err := me.forge.Install(check, verbose); err != nil {
			log.Warn("INSTALL FAILED", check.GetGoPath(), err)
			failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
			return err
		}
	} else {
		if err := me.forge.Install(check, nil); err != nil {
			log.Warn("INSTALL FAILED", check.GetGoPath(), err)
			failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
			return err
		}
	}
	return nil
}

func doInstall() error {
	initForge() // make sure forge is init'd here

	all := me.forge.Repos.SortByFullPath()
	for all.Scan() {
		check := all.Next()

		repotype := check.GetRepoType()
		if repotype == "binary" || repotype == "plugin" {
			// we only want to process things that can be compiled with 'go build'
		} else {
			// log.Info("skipping repo", check.GetGoPath(), repotype)
			continue
		}

		if me.forge.Config.IsReadOnly(check.GetGoPath()) {
			// ignore read only stuff
			continue
		}

		// var cmd []string
		var start string
		var end string

		// add te repotype
		end += check.GetRepoType()

		manufactured := check.GetCurrentVersion()
		ver := trimNonNumericFromStart(manufactured)
		name := me.forge.Config.DebName(check.GetGoPath())
		var realver string
		if installedPackage := me.machine.FindInstalledByName(name); installedPackage != nil {
			realver = installedPackage.Version
		}
		if actualp := me.machine.FindByVersion(name, ver); actualp != nil {
			end += " (version match) " + actualp.Version + " " + ver + " "
			state[check] = "on mirrors"
		} else {
			if realver != "" {
				end += fmt.Sprintf(" (version  miss) %s vs %s ", realver, ver)
			}
			// end += "" + ver + " "
		}
		if me.machine.IsInstalled(name) {
			if actualp := me.machine.FindInstalledByName(name); actualp != nil {
				if ver != actualp.Version {
					end += "(installed " + actualp.Version + ") "
				} else {
					end += "(installed ok) "
				}
			} else {
				end += "(installed) "
			}
		}

		debname := name + "_" + ver + "_amd64.deb"
		debnames[check] = debname
		outdir := getOutdir(check)
		_, err := os.Stat(filepath.Join(outdir, debname))
		if err == nil {
			// log.Info("exists", filepath.Join(outdir, debname))
			state[check] = "in incoming"
		} else {
			// log.Info(debname, "does not exist")
		}

		if state[check] == "" {
			state[check] = "need to build"
		}
		start = fmt.Sprintf("%-15s %-20s %-50s", state[check], ver, debname)

		if state[check] == "need to build" {
			end += " (will build) "
		}

		log.Info(start, end)
		if name == "" {
			// err := fmt.Sprintf("name is blank error %+v", repo)
			log.Warn("name is blank error", check.GetGoPath())
		}

		if argv.DryRun {
			continue
		}
		if argv.TestBuild != nil {
			if argv.DryRun {
				continue
			}
			if argv.Verbose {
				verbose := []string{"-v", "-x"}
				if err := me.forge.Build(check, verbose); err != nil {
					log.Warn("BUILD FAILED", check.GetGoPath(), err)
					failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err)
				}
			} else {
				if err := me.forge.Build(check, nil); err != nil {
					log.Warn("BUILD FAILED", check.GetGoPath(), err)
					failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err)
				}
			}
			continue
		}

		log.Info("STARTING 'make install' in", check.GetGoPath())
		if argv.DryRun {
			continue
		}
		if argv.Verbose {
			verbose := []string{"-v", "-x"}
			if err := me.forge.Install(check, verbose); err != nil {
				log.Warn("INSTALL FAILED", check.GetGoPath(), err)
				failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
			}
		} else {
			if err := me.forge.Install(check, nil); err != nil {
				log.Warn("INSTALL FAILED", check.GetGoPath(), err)
				failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
			}
		}
	}
	if len(failed) != 0 {
		log.Info("")
		log.Info("something failed on:")
		for repo, cmd := range failed {
			log.Info("failed cmd  :", cmd, repo.GetGoPath())
		}
		// me.forge.CheckoutUser()
		// shell.Run([]string{"forge", "--find-private"})
		badExit(errors.New("some repos failed"))
		return errors.New("some repos failed")
	}
	return nil
}

func doInstallScan() {
	initForge() // make sure forge is init'd here

	all := me.forge.Repos.SortByFullPath()
	for all.Scan() {
		check := all.Next()

		repotype := check.GetRepoType()
		if repotype == "binary" || repotype == "plugin" {
			// we only want to process things that can be compiled with 'go build'
		} else {
			// log.Info("skipping repo", check.GetGoPath(), repotype)
			continue
		}

		if me.forge.Config.IsReadOnly(check.GetGoPath()) {
			// ignore read only stuff
			continue
		}

		// var cmd []string
		var start string
		var end string

		// add te repotype
		end += check.GetRepoType()

		manufactured := check.GetCurrentVersion()
		ver := trimNonNumericFromStart(manufactured)
		name := me.forge.Config.DebName(check.GetGoPath())
		var realver string
		if installedPackage := me.machine.FindInstalledByName(name); installedPackage != nil {
			realver = installedPackage.Version
		}
		if actualp := me.machine.FindByVersion(name, ver); actualp != nil {
			end += " (version match) " + actualp.Version + " " + ver + " "
			state[check] = "on mirrors"
		} else {
			if realver != "" {
				end += fmt.Sprintf(" (version  miss) %s vs %s ", realver, ver)
			}
			// end += "" + ver + " "
		}
		if me.machine.IsInstalled(name) {
			if actualp := me.machine.FindInstalledByName(name); actualp != nil {
				if ver != actualp.Version {
					end += "(installed " + actualp.Version + ") "
				} else {
					end += "(installed ok) "
				}
			} else {
				end += "(installed) "
			}
		}

		debname := name + "_" + ver + "_amd64.deb"
		debnames[check] = debname
		outdir := getOutdir(check)
		_, err := os.Stat(filepath.Join(outdir, debname))
		if err == nil {
			// log.Info("exists", filepath.Join(outdir, debname))
			state[check] = "in incoming"
		} else {
			// log.Info(debname, "does not exist")
		}

		if state[check] == "" {
			state[check] = "need to build"
		}
		start = fmt.Sprintf("%-15s %-20s %-50s", state[check], ver, debname)

		if state[check] == "need to build" {
			end += " (will build) "
		}

		log.Info(start, end)
		if name == "" {
			// err := fmt.Sprintf("name is blank error %+v", repo)
			log.Warn("name is blank error", check.GetGoPath())
		}
	}
}