Class: PEBuild::Cap::StageInstaller::Windows

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

Overview

Download PE installers to a Windows VM

Since:

  • 0.14.0

Class Method Summary collapse

Methods included from OnMachine

on_machine

Class Method Details

.stage_installer(machine, uri, dest_dir = '.') ⇒ void

This method returns an undefined value.

Download an installer to a remote VM

Parameters:

  • uri (URI)

    A URI containing the download source.

  • dest_dir (String) (defaults to: '.')

    The destination directory to download the installer to.

Since:

  • 0.14.0



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pe_build/cap/stage_installer/windows.rb', line 17

def self.stage_installer(machine, uri, dest_dir='.')
  filename = File.basename(uri.path)

  unless machine.communicate.test(%Q[If (Test-Path "#{dest_dir}/#{filename}) { Exit 0 } Else { Exit 1 }])
    machine.ui.info I18n.t('pebuild.cap.stage_installer.downloading_installer',
      :url => uri)

    # Setting ServerCertificateValidationCallback to always return true
    # allows us to download from HTTPS sources that present a self-signed
    # certificate. For example, a Puppet Master.
    on_machine(machine, <<-EOS)
$DestDir = (Get-Item -Path "#{dest_dir}").FullName
Write-Host "Downloading #{filename} to: ${DestDir}"

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
(New-Object System.Net.WebClient).DownloadFile("#{uri}","$DestDir/#{filename}")
EOS
  end
end