Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Add brew-boxen-cask-install #57

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
53 changes: 39 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.6)
addressable (2.3.8)
ansi (1.5.0)
boxen (2.9.0)
boxen (3.1.3)
ansi (~> 1.4)
hiera (~> 1.0)
highline (~> 1.6.0)
json_pure (>= 1.7.7, < 2.0)
librarian-puppet (~> 1.0.0)
librarian-puppet (~> 2.2)
octokit (~> 2.7, >= 2.7.1)
puppet (~> 3.7)
cardboard (2.1.0)
boxen (~> 2.1)
cardboard (2.1.1)
boxen (~> 3.1)
puppet-lint (~> 0.3)
puppetlabs_spec_helper (~> 0.4)
rspec-puppet (~> 1.0)
diff-lcs (1.3)
facter (2.5.1)
facter (2.5.1-universal-darwin)
CFPropertyList (~> 2.2)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
fast_gettext (1.1.2)
gettext (3.2.6)
locale (>= 2.0.5)
text (>= 1.3.0)
gettext-setup (0.30)
fast_gettext (~> 1.1.0)
gettext (>= 3.0.2)
locale
hiera (1.3.4)
json_pure
highline (1.6.21)
json (2.1.0)
json_pure (1.8.6)
librarian (0.1.2)
highline
librarian-puppet (2.2.3)
librarianp (>= 0.6.3)
puppet_forge (~> 2.1)
rsync
librarianp (0.6.4)
thor (~> 0.15)
librarian-puppet (1.0.9)
json
librarian (>= 0.1.2)
locale (2.1.2)
metaclass (0.0.4)
minitar (0.6.1)
mocha (1.3.0)
metaclass (~> 0.0.1)
multipart-post (2.0.0)
Expand All @@ -44,18 +58,24 @@ GEM
puppet-lint (0.3.2)
puppet-syntax (2.4.1)
rake
puppet_forge (2.2.9)
faraday (>= 0.9.0, < 0.14.0)
faraday_middleware (>= 0.9.0, < 0.13.0)
gettext-setup (~> 0.11)
minitar
semantic_puppet (~> 1.0)
puppetlabs_spec_helper (0.10.3)
mocha
puppet-lint
puppet-syntax
rake
rspec-puppet
rake (12.2.1)
rake (12.3.0)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
Expand All @@ -65,17 +85,22 @@ GEM
rspec-support (~> 3.7.0)
rspec-puppet (1.0.1)
rspec
rspec-support (3.7.0)
rspec-support (3.7.1)
rsync (1.0.9)
sawyer (0.5.5)
addressable (~> 2.3.5)
faraday (~> 0.8, < 0.10)
semantic_puppet (1.0.1)
gettext-setup (>= 0.3)
text (1.3.1)
thor (0.20.0)

PLATFORMS
ruby
x86_64-darwin-16

DEPENDENCIES
cardboard (~> 2.1)

BUNDLED WITH
1.16.0
1.16.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package { 'firefox': provider => 'brewcask' }

## Required Puppet Modules

- `homebrew`, >= 1.10.0
* `homebrew`, >= 1.10

## Work in progress

Expand Down
4 changes: 4 additions & 0 deletions files/brew-boxen-cask-install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$LOAD_PATH.unshift("#{HOMEBREW_LIBRARY_PATH}/cask/lib")
require "hbc"

Hbc::CLI::Install.new(ARGV).run
29 changes: 17 additions & 12 deletions lib/puppet/provider/package/brewcask.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "puppet/provider/package"
require "puppet/util/execution"
require 'puppet/provider/package'
require 'puppet/util/execution'

Puppet::Type.type(:package).provide :brewcask, :parent => Puppet::Provider::Package do
include Puppet::Util::Execution
Expand Down Expand Up @@ -45,15 +45,20 @@ def query
end

def install
install_cmd = ['brew']
if install_options.any?
execute ["brew", "install", "Caskroom/cask/#{resource[:name]}", *install_options].flatten, command_opts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was only looking at why Canary wasn't installing for me last week and completely overlooked this.

install_cmd << 'cask install'
install_cmd << install_options
else
execute ["brew", "boxen-install", "Caskroom/cask/#{resource[:name]}"], command_opts
install_cmd << 'boxen-cask-install'
end
install_cmd << resource[:name]

execute install_cmd.flatten, command_opts
end

def uninstall
execute ["brew", "cask", "uninstall", "--force", resource[:name]]
execute ['brew', 'cask', 'uninstall', '--force', resource[:name]]
end

def install_options
Expand Down Expand Up @@ -86,18 +91,18 @@ def self.execute(*args)
end

def default_user
Facter.value(:boxen_user) || Facter.value(:id) || "root"
Facter.value(:boxen_user) || Facter.value(:id) || 'root'
end

def command_opts
opts = {
:combine => true,
:custom_environment => {
"HOME" => "/Users/#{default_user}",
"PATH" => "#{self.class.home}/bin:/usr/bin:/usr/sbin:/bin:/sbin",
"HOMEBREW_NO_EMOJI" => "Yes",
:combine => true,
:custom_environment => {
'HOME' => "/Users/#{default_user}",
'PATH' => "#{self.class.home}/bin:/usr/bin:/usr/sbin:/bin:/sbin",
'HOMEBREW_NO_EMOJI' => 'Yes',
},
:failonfail => true,
:failonfail => true,
}
# Only try to run as another user if Puppet is run as root.
opts[:uid] = default_user if Process.uid == 0
Expand Down
9 changes: 8 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
require homebrew

file { "${boxen::config::envdir}/10_brewcask.sh":
ensure => 'absent'
ensure => 'absent',
}

file { "${homebrew::config::brewsdir}/cmd/brew-boxen-cask-install.rb":
source => 'puppet:///modules/brewcask/brew-boxen-cask-install.rb',
mode => '0755',
}

homebrew::tap { 'caskroom/cask': }
}
12 changes: 12 additions & 0 deletions spec/classes/brewcask_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@

describe 'brewcask' do
let(:facts) { default_test_facts }

it do
should contain_class('boxen::config')
should contain_class('homebrew')

should contain_file('/test/boxen/env.d/10_brewcask.sh').
with_ensure('absent')

should contain_file('/test/boxen/homebrew/Library/Taps/boxen-brews/cmd/brew-boxen-cask-install.rb').
with_source('puppet:///modules/brewcask/brew-boxen-cask-install.rb').
with_mode('0755')
end
end
14 changes: 7 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require "rspec-puppet"
require 'rspec-puppet'

fixture_path = File.expand_path File.join(__FILE__, "..", "fixtures")
fixture_path = File.expand_path File.join(__FILE__, '..', 'fixtures')

RSpec.configure do |c|
c.manifest_dir = File.join(fixture_path, "manifests")
c.module_path = File.join(fixture_path, "modules")
c.manifest_dir = File.join(fixture_path, 'manifests')
c.module_path = File.join(fixture_path, 'modules')
end

def default_test_facts
{
:boxen_home => "/test/boxen",
:boxen_srcdir => "/test/boxen/src",
:boxen_user => "testuser",
:boxen_home => '/test/boxen',
:boxen_srcdir => '/test/boxen/src',
:boxen_user => 'testuser',
}
end
76 changes: 76 additions & 0 deletions spec/unit/provider/package/brewcask_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require 'spec_helper'

provider = Puppet::Type.type(:package).provider(:brewcask)

describe provider do
it 'should have an install method' do
is_expected.to respond_to(:install)
end

it 'should have a uninstall method' do
is_expected.to respond_to(:uninstall)
end

it 'should not have a latst method' do
is_expected.not_to respond_to(:latest)
end

it 'should not have a update method' do
is_expected.not_to respond_to(:update)
end

describe 'when installing' do
context 'installing cask without install options' do
before do
@resource = Puppet::Type.type(:package).new(
:name => 'mycask',
:ensure => :present,
:provider => :brewcask,
)
@provider = provider.new(@resource)
end

it 'should return install command' do
expect{ @provider.install }.to raise_error(Puppet::ExecutionFailure,
/brew boxen-cask-install mycask/)
end

it 'should return nil query' do
expect(@provider.query).to eq(nil)
end
end

context 'installing cask with install options' do
before do
@resource = Puppet::Type.type(:package).new(
:name => 'mycask',
:ensure => :present,
:provider => :brewcask,
:install_options => '--foo',
)
@provider = provider.new(@resource)
end

it 'should return install command with install options' do
expect { @provider.install }.to raise_error(Puppet::ExecutionFailure,
/brew cask install --foo mycask/)
end
end
end

describe 'when uninstalling' do
before do
@resource = Puppet::Type.type(:package).new(
:name => 'mycask',
:ensure => :present,
:provider => :brewcask,
)
@provider = provider.new(@resource)
end

it 'should return uninstall command' do
expect { @provider.uninstall }.to raise_error(Puppet::ExecutionFailure,
/brew cask uninstall --force mycask/)
end
end
end