This repository has been archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
116 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
require "fileutils" | ||
require "pathname" | ||
require "puppet/util/execution" | ||
|
||
Puppet::Type.type(:homebrew_tap).provide :default do | ||
include Puppet::Util::Execution | ||
|
||
def self.home | ||
@home ||= if boxen_home = Facter.value(:boxen_home) | ||
"#{boxen_home}/homebrew" | ||
else | ||
"/usr/local/homebrew" | ||
end | ||
end | ||
|
||
def self.taps_dir | ||
@taps_dir ||= "#{home}/Library/Taps" | ||
end | ||
|
||
def self.instances | ||
Dir.entries(taps_dir).map { |t| t.gsub('-', '/') } | ||
end | ||
|
||
def exists? | ||
File.directory? install_dir | ||
end | ||
|
||
def create | ||
execute [ "brew", "tap", @resource[:source] ], command_opts | ||
end | ||
|
||
def destroy | ||
FileUtils.rm_rf install_dir | ||
end | ||
|
||
private | ||
|
||
def install_dir | ||
@install_dir ||= "#{self.class.taps_dir}/#{hyphenated_source}" | ||
end | ||
|
||
def hyphenate(s) | ||
s.gsub('/', '-') | ||
end | ||
|
||
def hyphenated_source | ||
@hyphenated_source ||= hyphenate(@resource[:source]) | ||
end | ||
|
||
# Override default `execute` to run super method in a clean | ||
# environment without Bundler, if Bundler is present | ||
def execute(*args) | ||
if Puppet.features.bundled_environment? | ||
Bundler.with_clean_env do | ||
super | ||
end | ||
else | ||
super | ||
end | ||
end | ||
|
||
# Override default `execute` to run super method in a clean | ||
# environment without Bundler, if Bundler is present | ||
def self.execute(*args) | ||
if Puppet.features.bundled_environment? | ||
Bundler.with_clean_env do | ||
super | ||
end | ||
else | ||
super | ||
end | ||
end | ||
|
||
def default_user | ||
Facter.value(:boxen_user) || Facter.value(:id) || "root" | ||
end | ||
|
||
def command_opts | ||
@command_opts ||= { | ||
:combine => true, | ||
:custom_environment => { | ||
"HOME" => "/#{homedir_prefix}/#{default_user}", | ||
"PATH" => "#{self.class.home}/bin:/usr/bin:/usr/sbin:/bin:/sbin", | ||
"CFLAGS" => "-O2", | ||
"CPPFLAGS" => "-O2", | ||
"CXXFLAGS" => "-O2" | ||
}, | ||
:failonfail => true, | ||
:uid => default_user | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Puppet::Type.newtype(:homebrew_tap) do | ||
ensurable do | ||
newvalue :present do | ||
provider.create | ||
end | ||
|
||
newvalue :absent do | ||
provider.destroy | ||
end | ||
|
||
defaultto :present | ||
end | ||
|
||
newparam(:source) do | ||
isnamevar | ||
|
||
validate do |v| | ||
if v.nil? | ||
raise Puppet::ParseError, "Homebrew_tap requires a source parameter!" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
894bc3e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this new
ensure_resource
caused the specs to fail as they are expectingexec
resources. Not sure how to update specs to test forensure_resource
however as it is part of stdlib