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 e65c5ad
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
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
4 changes: 4 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
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
)
31 changes: 26 additions & 5 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,32 @@
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' }
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 %>

0 comments on commit e65c5ad

Please sign in to comment.