mirror of https://github.com/docker/docs.git
Detect the location of VBoxManage.exe - it is often not in the PATH
Signed-off-by: Sven Dowideit <SvenDowideit@docker.com>
This commit is contained in:
parent
f1abee624f
commit
467fc9a2ef
|
@ -6,7 +6,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
@ -23,9 +25,35 @@ var (
|
||||||
ErrMachineExist = errors.New("machine already exists")
|
ErrMachineExist = errors.New("machine already exists")
|
||||||
ErrMachineNotExist = errors.New("machine does not exist")
|
ErrMachineNotExist = errors.New("machine does not exist")
|
||||||
ErrVBMNotFound = errors.New("VBoxManage not found")
|
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 {
|
func vbm(args ...string) error {
|
||||||
cmd := exec.Command(vboxManageCmd, args...)
|
cmd := exec.Command(vboxManageCmd, args...)
|
||||||
if os.Getenv("DEBUG") != "" {
|
if os.Getenv("DEBUG") != "" {
|
||||||
|
|
Loading…
Reference in New Issue