Skip to content

Commit

Permalink
Latest brew install needs extended sudo rights
Browse files Browse the repository at this point in the history
Signed-off-by: Antek S. Baranski <[email protected]>
  • Loading branch information
Sauraus committed Jan 20, 2017
1 parent c417c5a commit 288cb95
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ platforms:

suites:
- name: default
run_list: test::default
run_list: test::default
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
AllCops:
Exclude:
- .kitchen/*
- vendor/**/*

LineLength:
Max: 120
3 changes: 3 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@
default['homebrew']['installer']['url'] = 'https://raw.githubusercontent.com/Homebrew/install/master/install'
default['homebrew']['installer']['checksum'] = nil
default['homebrew']['enable-analytics'] = true
default['homebrew']['sudo']['commands'] =
%w( /bin/chmod /usr/sbin/chown /bin/mkdir /usr/bin/chgrp /usr/bin/touch
/usr/sbin/softwareupdate /bin/rm /usr/bin/xcode-select )
38 changes: 33 additions & 5 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,39 @@
not_if { ::File.exist? '/usr/local/bin/brew' }
end

execute 'install homebrew' do
command homebrew_go
environment lazy { { 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner } }
user homebrew_owner
not_if { ::File.exist? '/usr/local/bin/brew' }
directory '/etc/sudoers.d' do
mode '00644'
owner 'root'
group 'wheel'
action :create
end

begin
template '/etc/sudoers.d/homebrew' do
source 'homebrew_sudo.erb'
variables (
lazy {
{ :user => homebrew_owner, :hostname => node['hostname'],
:commands => node['homebrew']['sudo']['commands'] }
}
)
action :create
mode '00644'
user 'root'
group 'wheel'
not_if { (::File.exist? '/usr/local/bin/brew') || node['homebrew']['sudo']['commands'].empty? }
end

execute 'install homebrew' do
command "#{homebrew_go} < /dev/null"
environment lazy { { 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner } }
user homebrew_owner
not_if { ::File.exist? '/usr/local/bin/brew' }
end
ensure
file '/etc/sudoers.d/homebrew' do
action :delete
end
end

execute 'set analytics' do
Expand Down
3 changes: 3 additions & 0 deletions templates/default/homebrew_sudo.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @commands.each do |command| %>
<%= @user %> <%= @hostname %>=(root) NOPASSWD: <%= command %>
<% end %>
4 changes: 4 additions & 0 deletions test/cookbooks/test/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
include_recipe 'homebrew::install_formulas'
include_recipe 'homebrew::install_casks'
include_recipe 'homebrew::install_taps'

package 'cmake' do
action :install
end

0 comments on commit 288cb95

Please sign in to comment.