mirror of https://github.com/hashicorp/packer
parent
99af93f86a
commit
d31d54366a
@ -0,0 +1,53 @@
|
||||
package virtualbox
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// A driver is able to talk to VirtualBox and perform certain
|
||||
// operations with it.
|
||||
type Driver interface {
|
||||
// SuppressMessages should do what needs to be done in order to
|
||||
// suppress any annoying popups from VirtualBox.
|
||||
SuppressMessages() error
|
||||
|
||||
// Verify checks to make sure that this driver should function
|
||||
// properly. If there is any indication the driver can't function,
|
||||
// this will return an error.
|
||||
Verify() error
|
||||
}
|
||||
|
||||
type VBox42Driver struct {
|
||||
// This is the path to the "VBoxManage" application.
|
||||
VBoxManagePath string
|
||||
}
|
||||
|
||||
func (d *VBox42Driver) SuppressMessages() error {
|
||||
extraData := map[string]string{
|
||||
"GUI/RegistrationData": "triesLeft=0",
|
||||
"GUI/SuppressMessages": "confirmInputCapture,remindAboutAutoCapture,remindAboutMouseIntegrationOff,remindAboutMouseIntegrationOn,remindAboutWrongColorDepth",
|
||||
}
|
||||
|
||||
for k, v := range extraData {
|
||||
if err := d.vboxmanage("setextradata", "global", k, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *VBox42Driver) Verify() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *VBox42Driver) vboxmanage(args ...string) error {
|
||||
log.Printf("Executing VBoxManage: %#v", args)
|
||||
cmd := exec.Command(d.VBoxManagePath, args...)
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package virtualbox
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/multistep"
|
||||
"os"
|
||||
)
|
||||
|
||||
type stepPrepareOutputDir struct{}
|
||||
|
||||
func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepAction {
|
||||
config := state["config"].(*config)
|
||||
|
||||
if err := os.MkdirAll(config.OutputDir, 0755); err != nil {
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (stepPrepareOutputDir) Cleanup(map[string]interface{}) {}
|
||||
@ -0,0 +1,27 @@
|
||||
package virtualbox
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
)
|
||||
|
||||
// This step sets some variables in VirtualBox so that annoying
|
||||
// pop-up messages don't exist.
|
||||
type stepSuppressMessages struct{}
|
||||
|
||||
func (stepSuppressMessages) Run(state map[string]interface{}) multistep.StepAction {
|
||||
driver := state["driver"].(Driver)
|
||||
ui := state["ui"].(packer.Ui)
|
||||
|
||||
log.Println("Suppressing annoying messages in VirtualBox")
|
||||
if err := driver.SuppressMessages(); err != nil {
|
||||
ui.Error(fmt.Sprintf("Error configuring VirtualBox to suppress messages: %s", err))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (stepSuppressMessages) Cleanup(map[string]interface{}) {}
|
||||
Loading…
Reference in new issue