Skip to content

Commit 893bacb

Browse files
author
志宇
committed
Added ability to use local base image for skyimager.
1 parent 8f81aae commit 893bacb

File tree

9 files changed

+141
-150
lines changed

9 files changed

+141
-150
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ test: ## Run tests
4343

4444
integration: build-skyconf ## runs integration tests.
4545
./integration/run.sh
46+
sudo rm -rf ./integration/mnt
4647

4748
build-skyconf: ## builds skyconf.
4849
${OPTS} go install ./cmd/skyconf

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/SkycoinProject/skywire-mainnet v0.1.2
1111
github.com/google/go-github v17.0.0+incompatible
1212
github.com/google/go-querystring v1.0.0 // indirect
13-
github.com/lucor/fyne-cross v1.4.0 // indirect
1413
github.com/mholt/archiver v3.1.1+incompatible
1514
github.com/rakyll/statik v0.1.7
1615
github.com/sirupsen/logrus v1.5.0

go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2-
fyne.io/fyne v1.2.2/go.mod h1:Ab+3DIB/FVteW0y4DXfmZv4N3JdnCBh2lHkINI02BOU=
32
fyne.io/fyne v1.2.3 h1:5xwtSBNjxxmg+GF/lYvvf4xPzyjgWQoJVrzb+bt5gaA=
43
fyne.io/fyne v1.2.3/go.mod h1:JhDdBrPP/Kdr1H5ZT3HW8E/6zlz+GkOldWqSirGBDnY=
54
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
@@ -141,8 +140,6 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
141140
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
142141
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
143142
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
144-
github.com/lucor/fyne-cross v1.4.0 h1:AEY8ayoxskmzQF1XBLcnK8IK5/Ejmiaz2IeThM/yOms=
145-
github.com/lucor/fyne-cross v1.4.0/go.mod h1:lVIalVfFMFxYEbKuaKTskX9NKh07kT5bnoEEqeKGY2U=
146143
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
147144
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
148145
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=

pkg/imager/fyne.go

Lines changed: 88 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net"
99
"net/http"
10+
"os"
1011
"path/filepath"
1112
"time"
1213

@@ -34,15 +35,19 @@ type FyneUI struct {
3435
app fyne.App
3536
w fyne.Window
3637

37-
releases []Release
38-
wkDir string
39-
baseImg string
40-
gwIP net.IP
41-
socksPC string
42-
visors int
43-
hvImg bool
44-
hvPKs []cipher.PubKey
45-
bps []boot.Params
38+
releases []Release
39+
locations []string
40+
41+
wkDir string
42+
imgLoc string
43+
remImg string
44+
fsImg string
45+
gwIP net.IP
46+
socksPC string
47+
visors int
48+
hvImg bool
49+
hvPKs []cipher.PubKey
50+
bps []boot.Params
4651
}
4752

4853
// NewFyneUI creates a new Fyne UI.
@@ -51,6 +56,10 @@ func NewFyneUI(log logrus.FieldLogger, assets http.FileSystem) *FyneUI {
5156
fg.log = log
5257
fg.assets = assets
5358

59+
fg.locations = []string{
60+
"From remote server.",
61+
"From local filesystem.",
62+
}
5463
fg.resetPage2Values()
5564

5665
fa := app.New()
@@ -123,7 +132,7 @@ func (fg *FyneUI) generateBPS() (string, error) {
123132
func (fg *FyneUI) build() {
124133
bpsSlice := fg.bps
125134

126-
baseURL, err := releaseURL(fg.releases, fg.baseImg)
135+
baseURL, err := releaseURL(fg.releases, fg.remImg)
127136
if err != nil {
128137
err = fmt.Errorf("failed to find download URL for base image: %v", err)
129138
dialog.ShowError(err, fg.w)
@@ -137,53 +146,81 @@ func (fg *FyneUI) build() {
137146
return
138147
}
139148

140-
// Download section.
141-
dlTitle := "Downloading Base Image"
142-
dlMsg := fg.baseImg + "\n" + baseURL
143-
dlDialog := dialog.NewProgress(dlTitle, dlMsg, fg.w)
144-
dlDialog.Show()
145-
dlDone := make(chan struct{})
146-
go func() {
147-
t := time.NewTicker(time.Second)
148-
for {
149-
select {
150-
case <-t.C:
151-
dlC, dlT := float64(builder.DownloadCurrent()), float64(builder.DownloadTotal())
152-
if pc := dlC / dlT; pc > 0 && pc <= 1 {
153-
dlDialog.SetValue(pc)
149+
// Final images to obtain.
150+
var imgs []string
151+
152+
switch fg.imgLoc {
153+
case fg.locations[0]:
154+
155+
// Download section.
156+
dlTitle := "Downloading Base Image"
157+
dlMsg := fg.remImg + "\n" + baseURL
158+
dlDialog := dialog.NewProgress(dlTitle, dlMsg, fg.w)
159+
dlDialog.Show()
160+
dlDone := make(chan struct{})
161+
go func() {
162+
t := time.NewTicker(time.Second)
163+
for {
164+
select {
165+
case <-t.C:
166+
dlC, dlT := float64(builder.DownloadCurrent()), float64(builder.DownloadTotal())
167+
if pc := dlC / dlT; pc > 0 && pc <= 1 {
168+
dlDialog.SetValue(pc)
169+
}
170+
case <-dlDone:
171+
t.Stop()
172+
return
154173
}
155-
case <-dlDone:
156-
t.Stop()
157-
return
158174
}
175+
}()
176+
err = builder.Download(baseURL)
177+
close(dlDone)
178+
dlDialog.Hide()
179+
if err != nil {
180+
dialog.ShowError(err, fg.w)
181+
return
159182
}
160-
}()
161-
err = builder.Download(baseURL)
162-
close(dlDone)
163-
dlDialog.Hide()
164-
if err != nil {
165-
dialog.ShowError(err, fg.w)
166-
return
167-
}
168183

169-
// Extract section.
170-
extDialog := dialog.NewProgressInfinite("Extracting Archive", builder.DownloadPath(), fg.w)
171-
extDialog.Show()
172-
err = builder.ExtractArchive()
173-
extDialog.Hide()
174-
if err != nil {
175-
dialog.ShowError(err, fg.w)
176-
return
177-
}
184+
// Extract section.
185+
extDialog := dialog.NewProgressInfinite("Extracting Archive", builder.DownloadPath(), fg.w)
186+
extDialog.Show()
187+
err = builder.ExtractArchive()
188+
extDialog.Hide()
189+
if err != nil {
190+
dialog.ShowError(err, fg.w)
191+
return
192+
}
178193

179-
imgs := builder.Images()
180-
fg.log.
181-
WithField("n", len(imgs)).
182-
WithField("imgs", imgs).
183-
Info("Obtained base images.")
194+
imgs = builder.Images()
195+
fg.log.
196+
WithField("n", len(imgs)).
197+
WithField("imgs", imgs).
198+
Info("Obtained base images.")
184199

185-
if len(imgs) == 0 {
186-
dialog.ShowError(errors.New("no valid images in archive"), fg.w)
200+
if len(imgs) == 0 {
201+
dialog.ShowError(errors.New("no valid images in archive"), fg.w)
202+
return
203+
}
204+
205+
case fg.locations[1]:
206+
// TODO(evanlinjin): The following is very hacky. Please fix.
207+
f, err := os.Open(fg.fsImg)
208+
if err != nil {
209+
dialog.ShowError(fmt.Errorf("failed to open base image: %v", err), fg.w)
210+
return
211+
}
212+
imgs = append(imgs, fg.fsImg)
213+
builder.bImgs[fg.fsImg] = BaseImage{
214+
File: f,
215+
MD5: nil,
216+
SHA1: nil,
217+
ExpectedMD5: [16]byte{},
218+
ExpectedSHA1: [20]byte{},
219+
}
220+
221+
default:
222+
err := errors.New("no base image selected")
223+
dialog.ShowError(err, fg.w)
187224
return
188225
}
189226

pkg/imager/fyne_pages.go

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,42 @@ func (fg *FyneUI) Page1() fyne.CanvasObject {
4343
func (fg *FyneUI) Page2() fyne.CanvasObject {
4444
wkDir := newLinkedEntry(&fg.wkDir)
4545

46-
baseImgs, latestImg := fg.listBaseImgs()
47-
baseImg := widget.NewSelect(baseImgs, func(s string) {
48-
fg.baseImg = s
49-
fg.log.Debugf("Set: fg.baseImg = %v", s)
46+
remImgs, latestImg := fg.listBaseImgs()
47+
remImg := widget.NewSelect(remImgs, func(s string) {
48+
fg.remImg = s
49+
fg.log.Debugf("Set: fg.remImg = %v", s)
5050
})
51-
if baseImg.Selected = fg.baseImg; baseImg.Selected == "" && len(baseImg.Options) > 0 {
52-
baseImg.SetSelected(latestImg)
51+
if remImg.Selected = fg.remImg; remImg.Selected == "" && len(remImg.Options) > 0 {
52+
remImg.SetSelected(latestImg)
5353
}
54+
remImg.Hide()
5455

56+
fsImg := widget.NewEntry()
57+
fsImg.SetPlaceHolder("path to .img file")
58+
fsImg.OnChanged = func(s string) {
59+
fg.fsImg = s
60+
fg.log.Debugf("Set: fg.fsImg = %v", s)
61+
}
62+
fsImg.SetText(fg.fsImg)
63+
fsImg.Hide()
64+
65+
imgLoc := widget.NewRadio(fg.locations, func(s string) {
66+
switch fg.imgLoc = s; s {
67+
case fg.locations[0]:
68+
remImg.Show()
69+
fsImg.Hide()
70+
case fg.locations[1]:
71+
remImg.Hide()
72+
fsImg.Show()
73+
default:
74+
remImg.Hide()
75+
fsImg.Hide()
76+
}
77+
})
78+
imgLoc.SetSelected(fg.imgLoc)
79+
imgLoc.OnChanged(fg.imgLoc)
80+
81+
// Gateway IP:
5582
gwIP := newEntry(fg.gwIP.String(), func(s string) {
5683
fg.gwIP = net.ParseIP(s)
5784
fg.log.Debugf("Set: fg.gwIP = %v", s)
@@ -147,7 +174,7 @@ func (fg *FyneUI) Page2() fyne.CanvasObject {
147174
}
148175
return makePage(conf,
149176
widget.NewLabel("Work Directory:"), wkDir,
150-
widget.NewLabel("Base Image:"), baseImg,
177+
widget.NewLabel("Base Image:"), imgLoc, remImg, fsImg,
151178
widget.NewLabel("Gateway IP:"), gwIP,
152179
widget.NewLabel("Skysocks Passcode:"), socksPC,
153180
widget.NewLabel("Number of Visor Images:"), visors,
@@ -156,7 +183,7 @@ func (fg *FyneUI) Page2() fyne.CanvasObject {
156183

157184
func (fg *FyneUI) resetPage2Values() {
158185
fg.wkDir = DefaultRootDir()
159-
fg.baseImg = ""
186+
fg.remImg = ""
160187
fg.gwIP = net.ParseIP(boot.DefaultGatewayIP)
161188
fg.socksPC = ""
162189
fg.visors = DefaultVisors
@@ -168,9 +195,22 @@ func checkPage2Inputs(fg *FyneUI, visorsText string) bool {
168195
if _, err := filepath.Abs(fg.wkDir); err != nil {
169196
return showErr(fg, fmt.Errorf("invalid Work Directory: %v", err))
170197
}
171-
if strings.TrimSpace(fg.baseImg) == "" {
172-
return showErr(fg, errors.New("invalid Base Image URL: cannot be empty"))
198+
switch fg.imgLoc {
199+
case fg.locations[0]:
200+
if strings.TrimSpace(fg.remImg) == "" {
201+
return showErr(fg, errors.New("invalid Base Image URL: cannot be empty"))
202+
}
203+
case fg.locations[1]:
204+
if !strings.HasSuffix(fg.fsImg, ".img") {
205+
return showErr(fg, errors.New("invalid Base Image Path: file needs to have .img extension"))
206+
}
207+
if _, err := os.Stat(fg.fsImg); err != nil {
208+
return showErr(fg, fmt.Errorf("cannot access Base Image: %v", err))
209+
}
210+
default:
211+
return showErr(fg, errors.New("no base image selected"))
173212
}
213+
174214
if fg.gwIP == nil {
175215
return showErr(fg, fmt.Errorf("invalid Gateway IP"))
176216
}
@@ -218,15 +258,15 @@ func (fg *FyneUI) Page3(bpsStr string) fyne.CanvasObject {
218258
}
219259
bps.SetText(bpsStr)
220260
},
221-
NextText: "Download and Build",
261+
NextText: "Build",
222262
Next: func() {
223263
// Decode bps entry text to ensure changes are recorded.
224264
dec := json.NewDecoder(strings.NewReader(bps.Text))
225265
if err := dec.Decode(&fg.bps); err != nil {
226266
dialog.ShowError(fmt.Errorf("invalid boot paramters: %v", err), fg.w)
227267
return
228268
}
229-
dialog.ShowConfirm("Confirmation", "Start download and build?", func(b bool) {
269+
dialog.ShowConfirm("Confirmation", "Start build?", func(b bool) {
230270
if b {
231271
fg.build()
232272
}

vendor/github.com/SkycoinProject/dmsg/cmdutil/catch.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

vendor/github.com/SkycoinProject/dmsg/cmdutil/cmd_name.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)