diff --git a/builder/parallels/common/driver.go b/builder/parallels/common/driver.go index ab9693461..0a276a6a1 100644 --- a/builder/parallels/common/driver.go +++ b/builder/parallels/common/driver.go @@ -27,6 +27,9 @@ type Driver interface { // Prlctl executes the given Prlctl command Prlctl(...string) error + // Get the path to the Parallels Tools ISO for the given flavor. + ToolsIsoPath(string) (string, 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. diff --git a/builder/parallels/common/driver_9.go b/builder/parallels/common/driver_9.go index 54e93a4bf..3bc608520 100644 --- a/builder/parallels/common/driver_9.go +++ b/builder/parallels/common/driver_9.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/exec" + "path/filepath" "regexp" "strings" "time" @@ -73,16 +74,21 @@ func getConfigValueFromXpath(path, xpath string) (string, error) { // Finds an application bundle by identifier (for "darwin" platform only) func getAppPath(bundleId string) (string, error) { + var stdout bytes.Buffer + cmd := exec.Command("mdfind", "kMDItemCFBundleIdentifier ==", bundleId) - out, err := cmd.Output() - if err != nil { + cmd.Stdout = &stdout + if err := cmd.Run(); err != nil { return "", err } - if string(out) == "" { + + pathOutput := strings.TrimSpace(stdout.String()) + if pathOutput == "" { return "", fmt.Errorf( "Could not detect Parallels Desktop! Make sure it is properly installed.") } - return string(out), nil + + return pathOutput, nil } func (d *Parallels9Driver) IsRunning(name string) (bool, error) { @@ -251,3 +257,14 @@ func (d *Parallels9Driver) IpAddress(mac string) (string, error) { log.Printf("Found IP lease: %s for MAC address %s\n", ip, mac) return ip, nil } + +func (d *Parallels9Driver) ToolsIsoPath(k string) (string, error) { + appPath, err := getAppPath("com.parallels.desktop.console") + if err != nil { + return "", err + } + + toolsPath := filepath.Join(appPath, "Contents", "Resources", "Tools", "prl-tools-"+k+".iso") + log.Printf("Parallels Tools path: '%s'", toolsPath) + return toolsPath, nil +} diff --git a/builder/parallels/common/driver_mock.go b/builder/parallels/common/driver_mock.go index e54c5cd5a..acb3f9533 100644 --- a/builder/parallels/common/driver_mock.go +++ b/builder/parallels/common/driver_mock.go @@ -31,6 +31,11 @@ type DriverMock struct { SendKeyScanCodesCalls [][]string SendKeyScanCodesErrs []error + ToolsIsoPathCalled bool + ToolsIsoPathFlavor string + ToolsIsoPathResult string + ToolsIsoPathErr error + MacName string MacReturn string MacError error @@ -98,3 +103,9 @@ func (d *DriverMock) IpAddress(mac string) (string, error) { d.IpAddressMac = mac return d.IpAddressReturn, d.IpAddressError } + +func (d *DriverMock) ToolsIsoPath(flavor string) (string, error) { + d.ToolsIsoPathCalled = true + d.ToolsIsoPathFlavor = flavor + return d.ToolsIsoPathResult, d.ToolsIsoPathErr +}