Skip to content

Commit

Permalink
Merge pull request #87 from rismoney/envs
Browse files Browse the repository at this point in the history
(GH-86) add environment variable on exec
  • Loading branch information
ferventcoder committed Sep 30, 2015
2 parents f93e34b + e44d0ef commit e9816c9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
20 changes: 4 additions & 16 deletions lib/facter/choco_install_path.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
require 'pathname'
require Pathname.new(__FILE__).dirname + '../' + 'puppet_x/chocolatey/chocolatey_install'

Facter.add('choco_install_path') do
setcode do

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

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['ChocolateyInstall']
end
rescue Win32::Registry::Error => e
value = nil
end
end

value || 'C:\ProgramData\chocolatey'
PuppetX::Chocolatey::ChocolateyInstall.install_path
end
end
13 changes: 11 additions & 2 deletions lib/puppet/provider/package/chocolatey.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'puppet/provider/package'
require 'pathname'
require Pathname.new(__FILE__).dirname + '../../../' + 'puppet_x/chocolatey/chocolatey_install'

Puppet::Type.type(:package).provide(:chocolatey, :parent => Puppet::Provider::Package) do

Expand Down Expand Up @@ -86,6 +88,10 @@ def self.choco_ver_cmd
[command(:chocolatey), *args]
end

def self.set_env_chocolateyinstall
ENV['ChocolateyInstall'] = PuppetX::Chocolatey::ChocolateyInstall.install_path
end

def choco_exe?
self.class.choco_exe?
end
Expand All @@ -97,6 +103,7 @@ def print()
end

def install
self.class.set_env_chocolateyinstall
args = []
# also will need to address -sidebyside or -m in the install args to allow
# multiple versions to be installed.
Expand Down Expand Up @@ -129,6 +136,7 @@ def install
end

def uninstall
self.class.set_env_chocolateyinstall
args = 'uninstall', @resource[:name][/\A\S*/]

if choco_exe?
Expand All @@ -147,6 +155,7 @@ def uninstall
end

def update
self.class.set_env_chocolateyinstall
if choco_exe?
args = 'upgrade', @resource[:name][/\A\S*/], '-dvy'
else
Expand Down Expand Up @@ -195,7 +204,7 @@ def self.listcmd

def self.instances
packages = []

set_env_chocolateyinstall
begin
execpipe(listcmd) do |process|
process.each_line do |line|
Expand Down Expand Up @@ -236,7 +245,7 @@ def latestcmd

def latest
package_ver = ''

self.class.set_env_chocolateyinstall
begin
execpipe(latestcmd) do |process|
process.each_line do |line|
Expand Down
25 changes: 25 additions & 0 deletions lib/puppet_x/chocolatey/chocolatey_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module PuppetX
module Chocolatey
class ChocolateyInstall

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

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['ChocolateyInstall']
end
rescue Win32::Registry::Error => e
value = nil
end
end

value || 'C:\ProgramData\chocolatey'
end

end
end
end
11 changes: 6 additions & 5 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
}

exec { 'install_chocolatey_official':
command => template('chocolatey/InstallChocolatey.ps1.erb'),
creates => "${::chocolatey::choco_install_location}\\bin\\choco.exe",
provider => powershell,
timeout => $::chocolatey::choco_install_timeout_seconds,
logoutput => $::chocolatey::log_output,
command => template('chocolatey/InstallChocolatey.ps1.erb'),
creates => "${::chocolatey::choco_install_location}\\bin\\choco.exe",
provider => powershell,
timeout => $::chocolatey::choco_install_timeout_seconds,
logoutput => $::chocolatey::log_output,
environment => ["ChocolateyInstall=${::chocolatey::choco_install_location}"]
}
}

0 comments on commit e9816c9

Please sign in to comment.