Class: PEBuild::Cap::RunInstall::Windows

Inherits:
Object
  • Object
show all
Extended by:
OnMachine
Defined in:
lib/pe_build/cap/run_install/windows.rb

Class Method Summary collapse

Methods included from OnMachine

on_machine

Class Method Details

.run_install(machine, installer_path, answers, **options) ⇒ void

This method returns an undefined value.

Run the PE installer on Windows systems

Parameters:

  • machine (Vagrant::Machine)

    The Vagrant machine on which to run the installation.

  • installer_dir (String)

    A path to the PE installer.

  • answers (Hash[String => String})

    A hash of options that will be passed to msiexec as key=value pairs.

  • options (Hash)

    Additional options that influence installer behavior.



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/pe_build/cap/run_install/windows.rb', line 17

def self.run_install(machine, installer_path, answers, **options)
  install_options = answers.map{|e| e.join('=')}.join(' ')
  # Lots of PowerShell commands can handle UNIX-style paths. msiexec can't.
  installer_path = installer_path.gsub('/', '\\')

  cmd = <<-EOS
$WorkingDirectory = (Get-Item -Path "#{installer_path}" -ErrorVariable InstallerMissing).Directory.FullName
If ($InstallerMissing) { Exit 1 }

$Package = (Get-Item -Path "#{installer_path}").FullName
$LogFile = "${WorkingDirectory}\\puppet-enterprise-installer.log"

$params = @(
"/qn",
"/i `"${Package}`"",
"/l*v `"${LogFile}`"",
"#{install_options}"
)

Write-Host "Running msiexec to install: ${Package}"

$Result = (Start-Process -FilePath "msiexec.exe" -ArgumentList $params -Wait -Passthru).ExitCode

If ($Result -ne 0) {
$HOST.UI.WriteErrorLine("msiexec failed with exitcode: ${Result}")
$HOST.UI.WriteErrorLine("Contents of ${LogFile}:")
Get-Content "${LogFile}" | ForEach-Object { $HOST.UI.WriteErrorLine($_) }
} Else {
Write-Host "msiexec completed with exitcode: ${Result}"
}

Exit $Result
EOS

  on_machine(machine, cmd)
end