2019-06-13 08:29:25 -04:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2016-07-26 15:42:04 -04:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2016-09-15 16:16:21 -04:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2016-07-26 15:42:04 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
2019-06-13 08:29:25 -04:00
|
|
|
// A floppy can be made available for your build. This is most useful for
|
|
|
|
// unattended Windows installs, which look for an Autounattend.xml file on
|
|
|
|
// removable media. By default, no floppy will be attached. All files listed in
|
|
|
|
// this setting get placed into the root directory of the floppy and the floppy
|
|
|
|
// is attached as the first floppy device. The summary size of the listed files
|
|
|
|
// must not exceed 1.44 MB. The supported ways to move large files into the OS
|
|
|
|
// are using `http_directory` or [the file
|
|
|
|
// provisioner](https://www.packer.io/docs/provisioners/file.html).
|
2014-04-06 13:21:22 -04:00
|
|
|
type FloppyConfig struct {
|
2019-06-13 08:29:25 -04:00
|
|
|
// A list of files to place onto a floppy disk that is attached when the VM
|
|
|
|
// is booted. Currently, no support exists for creating sub-directories on
|
|
|
|
// the floppy. Wildcard characters (\*, ?, and \[\]) are allowed. Directory
|
|
|
|
// names are also allowed, which will add all the files found in the
|
|
|
|
// directory to the floppy.
|
|
|
|
FloppyFiles []string `mapstructure:"floppy_files"`
|
|
|
|
// A list of directories to place onto the floppy disk recursively. This is
|
|
|
|
// similar to the `floppy_files` option except that the directory structure
|
|
|
|
// is preserved. This is useful for when your floppy disk includes drivers
|
|
|
|
// or if you just want to organize it's contents as a hierarchy. Wildcard
|
|
|
|
// characters (\*, ?, and \[\]) are allowed. The maximum summary size of
|
|
|
|
// all files in the listed directories are the same as in `floppy_files`.
|
2016-09-28 00:31:42 -04:00
|
|
|
FloppyDirectories []string `mapstructure:"floppy_dirs"`
|
2019-09-12 08:25:22 -04:00
|
|
|
FloppyLabel string `mapstructure:"floppy_label"`
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
|
2015-05-27 16:49:31 -04:00
|
|
|
func (c *FloppyConfig) Prepare(ctx *interpolate.Context) []error {
|
2016-07-26 15:42:04 -04:00
|
|
|
var errs []error
|
2016-09-15 16:16:21 -04:00
|
|
|
var err error
|
2016-07-26 15:42:04 -04:00
|
|
|
|
2014-04-06 13:21:22 -04:00
|
|
|
if c.FloppyFiles == nil {
|
|
|
|
c.FloppyFiles = make([]string, 0)
|
|
|
|
}
|
|
|
|
|
2016-07-26 15:42:04 -04:00
|
|
|
for _, path := range c.FloppyFiles {
|
2017-03-28 21:29:55 -04:00
|
|
|
if strings.ContainsAny(path, "*?[") {
|
2016-09-15 16:16:21 -04:00
|
|
|
_, err = filepath.Glob(path)
|
|
|
|
} else {
|
|
|
|
_, err = os.Stat(path)
|
|
|
|
}
|
|
|
|
if err != nil {
|
2016-07-26 15:42:04 -04:00
|
|
|
errs = append(errs, fmt.Errorf("Bad Floppy disk file '%s': %s", path, err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-28 00:31:42 -04:00
|
|
|
if c.FloppyDirectories == nil {
|
|
|
|
c.FloppyDirectories = make([]string, 0)
|
2016-03-05 02:40:16 -05:00
|
|
|
}
|
|
|
|
|
2016-09-28 00:31:42 -04:00
|
|
|
for _, path := range c.FloppyDirectories {
|
2017-03-28 21:29:55 -04:00
|
|
|
if strings.ContainsAny(path, "*?[") {
|
2016-09-15 16:16:21 -04:00
|
|
|
_, err = filepath.Glob(path)
|
|
|
|
} else {
|
|
|
|
_, err = os.Stat(path)
|
|
|
|
}
|
|
|
|
if err != nil {
|
2016-03-05 02:40:16 -05:00
|
|
|
errs = append(errs, fmt.Errorf("Bad Floppy disk directory '%s': %s", path, err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-26 15:42:04 -04:00
|
|
|
return errs
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|