Class: PuppetX::Chocolatey::ChocolateyInstall

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/chocolatey/chocolatey_install.rb

Overview

Class for installation of Chocolatey

Class Method Summary collapse

Class Method Details

.install_pathObject

Retrieves the path to the folder containing the Chocolatey instllation



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
# File 'lib/puppet_x/chocolatey/chocolatey_install.rb', line 12

def self.install_path
  value = nil

  if Puppet::Util::Platform.windows?
    require 'win32/registry'

    begin
      hive = Win32::Registry::HKEY_LOCAL_MACHINE
      hive.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_READ | 0x100) do |reg|
        value = reg['ChocolateyInstall']
      end
    rescue Win32::Registry::Error
      value = nil
    end
  end

  # If machine level is not set, use process or user as the intended
  # location where Chocolatey would be installed.
  # Since it is technically possible that Chocolatey could exist on
  # non-Windows installations, we don't want to confine this
  # to just Windows.
  if value.nil?
    value = ENV['ChocolateyInstall']
  end

  value
end

.temp_dirString

Retrieves the path to the temporary folder on the system

Returns:

  • (String)

    Path to temp folder



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/puppet_x/chocolatey/chocolatey_install.rb', line 43

def self.temp_dir
  return unless Puppet::Util::Platform.windows?
  require 'win32/registry'

  value = nil
  begin
    # looking at current user may likely fail because it's likely going to be LocalSystem
    hive = Win32::Registry::HKEY_CURRENT_USER
    hive.open('Environment', Win32::Registry::KEY_READ | 0x100) do |reg|
      value = reg['TEMP']
    end
  rescue Win32::Registry::Error
    value = nil
  end

  if value.nil?
    begin
      hive = Win32::Registry::HKEY_LOCAL_MACHINE
      hive.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_READ | 0x100) do |reg|
        value = reg['TEMP']
      end
    rescue Win32::Registry::Error
      value = nil
    end
  end

  value
end