diff options
author | Tim Smith <tsmith@chef.io> | 2018-03-08 16:10:26 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-03-20 10:24:17 -0700 |
commit | 7136bc0638e76c97bbbdcd2af3772def2a8dd2a1 (patch) | |
tree | bba0ca1acb5e893fecfa690048728c889d4a7ca2 /lib/chef/resource/homebrew_tap.rb | |
parent | a1c333d0b260088029b681d296e47ea7376d402e (diff) | |
download | chef-7136bc0638e76c97bbbdcd2af3772def2a8dd2a1.tar.gz |
Update to the code from the homebrew 9.0 cookbook
This converts the Chef resources to shell_out and adds new properties for dealing with edge case installations. It also adds validation messaging / testing and lazy evals the stuff that uses the mixin.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef/resource/homebrew_tap.rb')
-rw-r--r-- | lib/chef/resource/homebrew_tap.rb | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/lib/chef/resource/homebrew_tap.rb b/lib/chef/resource/homebrew_tap.rb index ad58f73dd3..8ce72e0861 100644 --- a/lib/chef/resource/homebrew_tap.rb +++ b/lib/chef/resource/homebrew_tap.rb @@ -24,49 +24,62 @@ class Chef class Resource class HomebrewTap < Chef::Resource resource_name :homebrew_tap - provides :homebrew_tap - description "" + description "Use the homebrew_tap resource to add additional formula repositories to the Homebrew package manager." introduced "14.0" include Chef::Mixin::HomebrewUser - property :name, String, + property :tap_name, String, + description: "Optional tap name to override the resource name", + validation_message: "Homebrew tap names must be in the form REPO/TAP", regex: %r{^[\w-]+(?:\/[\w-]+)+$}, name_property: true - property :url, String + property :url, String, + description: "URL to the tap." property :full, [TrueClass, FalseClass], + description: "Perform a full clone rather than a shallow clone on the tap.", default: false + property :homebrew_path, String, + description: "The path to the homebrew binary.", + default: "/usr/local/bin/brew" + + property :owner, String, + description: "The owner of the homebrew installation", + default: lazy { Chef::Mixin::HomebrewUser.find_homebrew_username } + action :tap do + description "Add a Homebrew tap." + unless tapped?(new_resource.name) - declare_resource(:execute, "tapping #{new_resource.name}") do - command "/usr/local/bin/brew tap #{new_resource.full ? '--full' : ''} #{new_resource.name} #{new_resource.url || ''}" - environment lazy { { "HOME" => ::Dir.home(find_homebrew_uid), "USER" => find_homebrew_uid } } - not_if "/usr/local/bin/brew tap | grep #{new_resource.name}" - user find_homebrew_uid + converge_by("tap #{new_resource.name}") do + shell_out!("#{new_resource.homebrew_path} tap #{new_resource.full ? '--full' : ''} #{new_resource.name} #{new_resource.url || ''}", + user: new_resource.owner, + env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner }, + cwd: ::Dir.home(new_resource.owner)) end end end action :untap do + description "Remove a Homebrew tap." + if tapped?(new_resource.name) - declare_resource(:execute, "untapping #{new_resource.name}") do - command "/usr/local/bin/brew untap #{new_resource.name}" - environment lazy { { "HOME" => ::Dir.home(find_homebrew_uid), "USER" => find_homebrew_uid } } - only_if "/usr/local/bin/brew tap | grep #{new_resource.name}" - user find_homebrew_uid + converge_by("untap #{new_resource.name}") do + shell_out!("#{new_resource.homebrew_path} untap #{new_resource.name}", + user: new_resource.owner, + env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner }, + cwd: ::Dir.home(new_resource.owner)) end end end - action_class do - def tapped?(name) - tap_dir = name.gsub("/", "/homebrew-") - ::File.directory?("/usr/local/Homebrew/Library/Taps/#{tap_dir}") - end + def tapped?(name) + tap_dir = name.gsub("/", "/homebrew-") + ::File.directory?("/usr/local/Homebrew/Library/Taps/#{tap_dir}") end end end |