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 = "    $MountedISOs=Mount-DiskImage -PassThru \#{remote_file}\n    $Volume=$MountedISOs | Get-Volume\n    $DriveLetter=$Volume.DriveLetter\n\n    Start-Process -FilePath ($DriveLetter + \":/PTAgent.exe\") `\n      -ArgumentList \"/install_silent\" `\n      -Verb RunAs `\n      -Wait\n    EOH\n\n    cleanup_script = <<-EOH\n    If (Test-Path \#{remote_file}){\n      Remove-Item \#{remote_file}\n    }\n    EOH\n\n    if agent_path_is_exe\n      install_script = <<-EOH\n      Start-Process -FilePath \#{remote_file} `\n        -ArgumentList \"/install_silent\" `\n        -Verb RunAs `\n        -Wait\n      EOH\n    else\n      cleanup_script = \"Dismount-DiskImage -ImagePath \#{remote_file}\\n\" + cleanup_script\n    end\n\n    comm.execute(install_script)\n    comm.execute(cleanup_script)\n  end\nend\n"