From 467fc9a2ef29a97a43bbdf94a8da0d18063b14a6 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Wed, 11 Feb 2015 20:16:14 +1000 Subject: [PATCH] Detect the location of VBoxManage.exe - it is often not in the PATH Signed-off-by: Sven Dowideit --- drivers/virtualbox/vbm.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/virtualbox/vbm.go b/drivers/virtualbox/vbm.go index 1e86096229..2d0a8ad328 100644 --- a/drivers/virtualbox/vbm.go +++ b/drivers/virtualbox/vbm.go @@ -6,7 +6,9 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "regexp" + "runtime" "strings" log "github.com/Sirupsen/logrus" @@ -23,9 +25,35 @@ var ( ErrMachineExist = errors.New("machine already exists") ErrMachineNotExist = errors.New("machine does not exist") ErrVBMNotFound = errors.New("VBoxManage not found") - vboxManageCmd = "VBoxManage" + vboxManageCmd = setVBoxManageCmd() ) +// detect the VBoxManage cmd's path if needed +func setVBoxManageCmd() string { + cmd := "VBoxManage" + if path, err := exec.LookPath(cmd); err == nil { + return path + } + if runtime.GOOS == "windows" { + if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" { + if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil { + return path + } + } + if p := os.Getenv("VBOX_MSI_INSTALL_PATH"); p != "" { + if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil { + return path + } + } + // look at HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\VirtualBox\InstallDir + p := "C:\\Program Files\\Oracle\\VirtualBox" + if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil { + return path + } + } + return cmd +} + func vbm(args ...string) error { cmd := exec.Command(vboxManageCmd, args...) if os.Getenv("DEBUG") != "" {