Class: VagrantPlugins::Parallels::GuestWindowsCap::InstallParallelsTools

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-parallels/guest_cap/windows/install_parallels_tools.rb

Class Method Summary collapse

Class Method Details

.install_parallels_tools(machine) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vagrant-parallels/guest_cap/windows/install_parallels_tools.rb', line 5

def self.install_parallels_tools(machine)
  machine.communicate.tap do |comm|
    # Get the host arch. This is safe even if an older x86-only Vagrant version is used.
    arch = `arch -64 uname -m`.chomp

    pti_agent_path = File.expand_path(
      machine.provider.driver.read_guest_tools_iso_path('windows', arch),
      machine.env.root_path
    )

    # Older versions of Parallels provided an executable file instead of an ISO image.
    agent_path_is_exe = pti_agent_path.end_with?('.exe')

    remote_file = "C:\\Windows\\Temp\\parallels-tools-win.#{agent_path_is_exe ? 'exe' : 'iso'}"
    comm.upload(pti_agent_path, remote_file)

    install_script = <<-EOH
    $MountedISOs=Mount-DiskImage -PassThru #{remote_file}
    $Volume=$MountedISOs | Get-Volume
    $DriveLetter=$Volume.DriveLetter

    Start-Process -FilePath ($DriveLetter + ":/PTAgent.exe") `
      -ArgumentList "/install_silent" `
      -Verb RunAs `
      -Wait
    EOH

    cleanup_script = <<-EOH
    If (Test-Path #{remote_file}){
      Remove-Item #{remote_file}
    }
    EOH

    if agent_path_is_exe
      install_script = <<-EOH
      Start-Process -FilePath #{remote_file} `
        -ArgumentList "/install_silent" `
        -Verb RunAs `
        -Wait
      EOH
    else
      cleanup_script = "Dismount-DiskImage -ImagePath #{remote_file}\n" + cleanup_script
    end

    comm.execute(install_script)
    comm.execute(cleanup_script)
  end
end