2013-06-11 18:45:52 -04:00
|
|
|
package virtualbox
|
|
|
|
|
|
|
|
import (
|
2013-06-11 19:48:01 -04:00
|
|
|
"bytes"
|
2013-06-11 18:52:46 -04:00
|
|
|
"fmt"
|
2013-06-11 18:45:52 -04:00
|
|
|
"log"
|
|
|
|
"os/exec"
|
2013-06-11 19:48:01 -04:00
|
|
|
"strings"
|
2013-06-11 18:52:46 -04:00
|
|
|
"time"
|
2013-06-11 18:45:52 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2013-06-11 19:12:19 -04:00
|
|
|
// VBoxManage executes the given VBoxManage command
|
|
|
|
VBoxManage(...string) error
|
|
|
|
|
2013-06-11 18:45:52 -04:00
|
|
|
// 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",
|
2013-06-11 18:52:46 -04:00
|
|
|
"GUI/UpdateDate": fmt.Sprintf("1 d, %d-01-01, stable", time.Now().Year()+1),
|
|
|
|
"GUI/UpdateCheckCount": "60",
|
2013-06-11 18:45:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range extraData {
|
2013-06-11 19:12:19 -04:00
|
|
|
if err := d.VBoxManage("setextradata", "global", k, v); err != nil {
|
2013-06-11 18:45:52 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-06-11 19:12:19 -04:00
|
|
|
func (d *VBox42Driver) VBoxManage(args ...string) error {
|
2013-06-11 19:48:01 -04:00
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
|
|
2013-06-11 18:45:52 -04:00
|
|
|
log.Printf("Executing VBoxManage: %#v", args)
|
|
|
|
cmd := exec.Command(d.VBoxManagePath, args...)
|
2013-06-11 19:48:01 -04:00
|
|
|
cmd.Stdout = &stdout
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
2013-06-11 18:45:52 -04:00
|
|
|
|
2013-06-11 19:48:01 -04:00
|
|
|
log.Printf("stdout: %s", strings.TrimSpace(stdout.String()))
|
|
|
|
log.Printf("stderr: %s", strings.TrimSpace(stderr.String()))
|
|
|
|
|
|
|
|
return err
|
2013-06-11 18:45:52 -04:00
|
|
|
}
|
2013-06-11 19:12:19 -04:00
|
|
|
|
|
|
|
func (d *VBox42Driver) Verify() error {
|
|
|
|
return nil
|
|
|
|
}
|