Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest brew install needs extended sudo rights #109

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 )
33 changes: 28 additions & 5 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,34 @@
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