@@ -59,12 +59,16 @@ var (
59
59
// Wrapped errors for testing.
60
60
errCache = errors .New ("missing cache" )
61
61
errConfig = errors .New ("invalid config" )
62
+ errConfName = errors .New ("missing configuration file name" )
63
+ errConfPath = errors .New ("missing configuration file path" )
62
64
errConnect = errors .New ("connect error" )
63
65
errDownload = errors .New ("download error" )
64
66
errDevice = errors .New ("device error" )
65
67
errElevation = errors .New ("elevation is required for this operation" )
66
68
errEmpty = errors .New ("iso is empty" )
67
69
errEmptyUser = errors .New ("could not determine username" )
70
+ errSFUManifest = errors .New ("missing sfu manifest" )
71
+ errSFUPath = errors .New ("sfu path empty" )
68
72
errFile = errors .New ("file error" )
69
73
errFinalize = errors .New ("finalize error" )
70
74
errFormat = errors .New ("format error" )
87
91
errUnsupported = errors .New ("unsupported" )
88
92
errUser = errors .New ("user detection error" )
89
93
errWipe = errors .New ("device wipe error" )
94
+ errYAML = errors .New ("yaml retrieval error" )
90
95
91
96
// ErrLabel is made public to that callers can warn on mismatches.
92
97
ErrLabel = errors .New (`label error` )
@@ -112,14 +117,16 @@ type Configuration interface {
112
117
ImageFile () string
113
118
Elevated () bool
114
119
FFU () bool
115
- FFUDest () string
116
- FFUManifest () string
117
- FFUPath () string
120
+ SFUManifest () string
121
+ SFUPath () string
118
122
PowerOff () bool
119
123
SeedDest () string
120
124
SeedFile () string
121
125
SeedServer () string
126
+ SFUDest () string
122
127
UpdateOnly () bool
128
+ FileName () string
129
+ Path () string
123
130
}
124
131
125
132
// Device represents storage.Device.
@@ -269,20 +276,34 @@ func (i *Installer) Retrieve() (err error) {
269
276
return i .retrieveFile (i .config .ImageFile (), i .config .Image ())
270
277
}
271
278
272
- // Check FFU Path configuration
273
- if i .config .FFUPath () == "" {
274
- return fmt . Errorf ( "missing FFU path: %w" , errConfig )
279
+ // Check FFU Path configuration.
280
+ if i .config .SFUPath () == "" {
281
+ return errSFUPath
275
282
}
276
283
277
- // Check FFU Manifest configuration
278
- if i .config .FFUManifest () == "" {
279
- return fmt .Errorf ("missing FFU manifest: %w" , errConfig )
284
+ // Check FFU Manifest configuration.
285
+ if i .config .SFUManifest () == "" {
286
+ return errSFUManifest
287
+ }
288
+
289
+ // Check for missing conf file name.
290
+ if i .config .FileName () == "" {
291
+ return errConfName
292
+ }
293
+
294
+ // Check conf path configuration.
295
+ if i .config .Path () == "" {
296
+ return errConfPath
297
+ }
298
+
299
+ if err := i .retrieveFile (i .config .FileName (), i .config .Path ()); err != nil {
300
+ return fmt .Errorf ("%w: %v" , errYAML , err )
280
301
}
281
302
282
303
if err := i .retrieveFile (i .config .ImageFile (), i .config .Image ()); err != nil {
283
304
return fmt .Errorf ("%w: %v" , errImage , err )
284
305
}
285
- return i .retrieveFile (i .config .FFUManifest (), fmt .Sprintf ("%s/%s" , i .config .FFUPath (), i .config .FFUManifest ()))
306
+ return i .retrieveFile (i .config .SFUManifest (), fmt .Sprintf ("%s/%s" , i .config .SFUPath (), i .config .SFUManifest ()))
286
307
}
287
308
288
309
// download obtains the installer using the provided client and writes it
@@ -450,7 +471,7 @@ func (i *Installer) DownloadSFU() error {
450
471
if i .cache == "" {
451
472
return fmt .Errorf ("missing cache location: %w" , errCache )
452
473
}
453
- sfus , err := getManifest (filepath .Join (i .cache , i .config .FFUManifest ()))
474
+ sfus , err := getManifest (filepath .Join (i .cache , i .config .SFUManifest ()))
454
475
if err != nil {
455
476
return fmt .Errorf ("readManifest() %w: %v" , errManifest , err )
456
477
}
@@ -463,63 +484,71 @@ func (i *Installer) DownloadSFU() error {
463
484
path := filepath .Join (i .cache , sfu .Filename )
464
485
f , err := os .Create (path )
465
486
if err != nil {
466
- return fmt .Errorf ("ioutil.TempFile(%q, %q) returned %w: %v" , i .cache , i .config .FFUManifest (), errFile , err )
487
+ return fmt .Errorf ("ioutil.TempFile(%q, %q) returned %w: %v" , i .cache , i .config .SFUManifest (), errFile , err )
467
488
}
468
489
defer f .Close ()
469
490
470
- if err := downloadFile (client , fmt .Sprintf (`%s/%s` , i .config .FFUPath (), sfu .Filename ), f ); err != nil {
491
+ if err := downloadFile (client , fmt .Sprintf (`%s/%s` , i .config .SFUPath (), sfu .Filename ), f ); err != nil {
471
492
return fmt .Errorf ("DownloadSFU() returned %w: %v" , errDownload , err )
472
493
}
473
494
474
495
}
475
496
return nil
476
497
}
477
498
478
- // PlaceSFU copies SFU files onto provisioned media from the local cache.
499
+ // PlaceSFU copies SFU files and config files onto provisioned media
500
+ // from the local cache.
479
501
func (i * Installer ) PlaceSFU (d Device ) error {
480
502
// Find a compatible partition to write the FFU to.
481
503
logger .V (2 ).Infof ("Searching for FFU %q for a %q partition larger than %v." , d .FriendlyName (), humanize .Bytes (minSFUPartSize ), storage .FAT32 )
482
504
p , err := selectPart (d , minSFUPartSize , storage .FAT32 )
483
505
if err != nil {
484
506
return fmt .Errorf ("SelectPartition(%q, %q, %q) returned %w: %v" , d .FriendlyName (), humanize .Bytes (minSFUPartSize ), storage .FAT32 , errPartition , err )
485
507
}
486
- sfus , err := getManifest (filepath .Join (i .cache , i .config .FFUManifest ()))
508
+ sfus , err := getManifest (filepath .Join (i .cache , i .config .SFUManifest ()))
487
509
if err != nil {
488
510
return fmt .Errorf ("getManifest() returned: %w: %v" , errManifest , err )
489
511
}
512
+ // Copy SFU files.
490
513
for ind , sfu := range sfus {
491
- // This is done as a separate function call to handle closing
492
- // the files through the defer at the end of each iteration
493
- // of the loop instead of waiting until the end of the function.
494
- func () error {
495
- path := filepath .Join (i .cache , sfu .Filename )
496
- newPath := filepath .Join (p .MountPoint (), i .config .FFUDest (), sfu .Filename )
497
- // Add colon for windows paths if its a drive root.
498
- if runtime .GOOS == "windows" && len (p .MountPoint ()) < 2 {
499
- newPath = filepath .Join (fmt .Sprintf ("%s:" , p .MountPoint ()), i .config .FFUDest (), sfu .Filename )
500
- }
501
- console .Printf ("Copying SFU %d of %d..." , ind + 1 , len (sfus ))
502
- if err := os .MkdirAll (filepath .Dir (newPath ), 0644 ); err != nil {
503
- return fmt .Errorf ("failed to create path: %v" , err )
504
- }
505
- source , err := os .Open (path )
506
- if err != nil {
507
- return fmt .Errorf ("%w: couldn't open file(%s) from cache: %v" , errPath , path , err )
508
- }
509
- defer source .Close ()
510
- destination , err := os .Create (newPath )
511
- if err != nil {
512
- return fmt .Errorf ("%w: couldn't create target file(%s): %v" , errFile , path , err )
513
- }
514
- defer destination .Close ()
515
- cBytes , err := io .Copy (destination , source )
516
- if err != nil {
517
- return fmt .Errorf ("failed to copy file to %s: %v" , newPath , err )
518
- }
519
- console .Printf ("Copied %d bytes" , cBytes )
520
- return nil
521
- }()
514
+ console .Printf ("Copying SFU %d of %d..." , ind + 1 , len (sfus ))
515
+ if err := fileCopy (sfu .Filename , i .config .SFUDest (), i .cache , p ); err != nil {
516
+ return fmt .Errorf ("fileCopy() failed for %s to %s: %v" , sfu .Filename , i .config .SFUDest (), err )
517
+ }
518
+ }
519
+ // Copy config.
520
+ console .Printf ("Copying %s" , i .config .FileName ())
521
+ if err := fileCopy (i .config .FileName (), i .config .SFUDest (), i .cache , p ); err != nil {
522
+ return fmt .Errorf ("fileCopy() failed for %s to %s: %v" , i .config .FileName (), i .config .SFUDest (), err )
523
+ }
524
+ return nil
525
+ }
526
+
527
+ func fileCopy (srcFile , dest , cache string , p partition ) error {
528
+ path := filepath .Join (cache , srcFile )
529
+ newPath := filepath .Join (p .MountPoint (), dest , srcFile )
530
+ // Add colon for windows paths if its a drive root.
531
+ if runtime .GOOS == "windows" && len (p .MountPoint ()) < 2 {
532
+ newPath = filepath .Join (fmt .Sprintf ("%s:" , p .MountPoint ()), dest , srcFile )
533
+ }
534
+ if err := os .MkdirAll (filepath .Dir (newPath ), 0744 ); err != nil {
535
+ return fmt .Errorf ("failed to create path: %v" , err )
536
+ }
537
+ source , err := os .Open (path )
538
+ if err != nil {
539
+ return fmt .Errorf ("%w: couldn't open file(%s) from cache: %v" , errPath , path , err )
540
+ }
541
+ defer source .Close ()
542
+ destination , err := os .Create (newPath )
543
+ if err != nil {
544
+ return fmt .Errorf ("%w: couldn't create target file(%s): %v" , errFile , path , err )
545
+ }
546
+ defer destination .Close ()
547
+ cBytes , err := io .Copy (destination , source )
548
+ if err != nil {
549
+ return fmt .Errorf ("failed to copy file to %s: %v" , newPath , err )
522
550
}
551
+ console .Printf ("Copied %d bytes" , cBytes )
523
552
return nil
524
553
}
525
554
0 commit comments