Initial Chef repository
This commit is contained in:
140
cookbooks/homebrew/CHANGELOG.md
Normal file
140
cookbooks/homebrew/CHANGELOG.md
Normal file
@@ -0,0 +1,140 @@
|
||||
homebrew Cookbook CHANGELOG
|
||||
===========================
|
||||
This file is used to list changes made in each version of the homebrew cookbook.
|
||||
|
||||
v1.12.0 (2015-01-29)
|
||||
--------------------
|
||||
|
||||
- #67 Add attribute and recipe for installing homebrew taps
|
||||
|
||||
v1.11.0 (2015-01-12)
|
||||
--------------------
|
||||
|
||||
- #59 Update Homebrew Cask if auto-update attribute is true
|
||||
- #52 Manage Homebrew Cask's install directories
|
||||
- #56 Fix check for existing casks
|
||||
- #61 Fix owner class for Chef 12
|
||||
- Depend on build-essential cookbook 2.1.2+ to support OS X 10.10
|
||||
- #64, #66 add and fix ChefSpec tests for default recipe
|
||||
|
||||
v1.10.0 (2014-12-09)
|
||||
--------------------
|
||||
|
||||
- #55 This cookbook no longer sets its `homebrew_package` as the
|
||||
`package` provider for OS X when running under Chef 12
|
||||
- List CHEF as the maintainer instead of Opscode.
|
||||
|
||||
v1.9.2 (2014-10-09)
|
||||
-------------------
|
||||
|
||||
Bug Fixes:
|
||||
|
||||
- #57 Update url per homebrew error: Upstream, the homebrew project
|
||||
has changed the URL for the installation script. All users of this
|
||||
cookbook are advised to update to this version.
|
||||
|
||||
v1.9.0 (2014-07-29)
|
||||
-------------------
|
||||
|
||||
Improvements:
|
||||
|
||||
- #35 Modernize the cask provider (use why run mode, inline resources)
|
||||
- #43 Use `brew cask list` to determine if casks are installed
|
||||
- #45 Add `default_action` and print warning messages on earlier
|
||||
versions of Chef (10.10)
|
||||
|
||||
New Features:
|
||||
|
||||
- #44 Add `:install` and `:uninstall` actions and alias previous `:cask`,
|
||||
`:uncask` actions to them
|
||||
|
||||
Bug Fixes:
|
||||
|
||||
- #27 Fix name for taps adding the `/homebrew` prefix
|
||||
- #28 Set `RUBYOPT` to `nil` so Chef can execute in a bundle (bundler
|
||||
sets `RUBYOPT` and this can cause issues when running the
|
||||
underlying `brew` commands)
|
||||
- #40 Fix regex for cask to match current homebrew conventions
|
||||
- #42 Fix attribute for list of formulas to match the README and
|
||||
maintain backward compat for 6 day old version
|
||||
|
||||
v1.8.0 (2014-07-23)
|
||||
-------------------
|
||||
- Add recipes to install an array of formulas/casks
|
||||
|
||||
v1.7.2 (2014-06-26)
|
||||
-------------------
|
||||
- Implement attribute to control auto-update
|
||||
|
||||
|
||||
v1.7.0 (2014-06-26)
|
||||
-------------------
|
||||
#38 - Add homebrew::cask recipe
|
||||
|
||||
|
||||
v1.6.6 (2014-05-29)
|
||||
-------------------
|
||||
- [COOK-3283] Use homebrew_owner for cask and tap
|
||||
- [COOK-4670] homebrew_tap provider is not idempotent
|
||||
- [COOK-4671] Syntax Error in README
|
||||
|
||||
|
||||
v1.6.4 (2014-05-08)
|
||||
-------------------
|
||||
- Fixing cask provider correctly this time. "brew cask list"
|
||||
|
||||
|
||||
v1.6.2 (2014-05-08)
|
||||
-------------------
|
||||
- Fixing typo in cask provider: 's/brew brew/brew/'
|
||||
|
||||
|
||||
v1.6.0 (2014-04-23)
|
||||
-------------------
|
||||
- [COOK-3960] Added LWRP for brew cask
|
||||
- [COOK-4508] Add ChefSpec matchers for homebrew_tap
|
||||
- [COOK-4566] Guard against "HEAD only" formulae
|
||||
|
||||
|
||||
v1.5.4
|
||||
------
|
||||
- [COOK-4023] Fix installer script's URL.
|
||||
- Fixing up style for rubocop
|
||||
|
||||
|
||||
v1.5.2
|
||||
------
|
||||
- [COOK-3825] setting $HOME on homebrew_package
|
||||
|
||||
|
||||
v1.5.0
|
||||
------
|
||||
### Bug
|
||||
- **[COOK-3589](https://tickets.opscode.com/browse/COOK-3589)** - Add homebrew as the default package manager on OS X Server
|
||||
|
||||
v1.4.0
|
||||
------
|
||||
### Bug
|
||||
- **[COOK-3283](https://tickets.opscode.com/browse/COOK-3283)** - Support running homebrew cookbook as root user, with sudo, or a non-privileged user
|
||||
|
||||
v1.3.2
|
||||
------
|
||||
- [COOK-1793] - use homebrew "go" script to install homebrew
|
||||
- [COOK-1821] - Discovered version using Homebrew Formula factory fails check that verifies that version is a String
|
||||
- [COOK-1843] - Homebrew README.md contains non-ASCII characters, triggering same issue as COOK-522
|
||||
|
||||
v1.3.0
|
||||
------
|
||||
- [COOK-1425] - use new json output format for formula
|
||||
- [COOK-1578] - Use shell_out! instead of popen4
|
||||
|
||||
v1.2.0
|
||||
------
|
||||
Opscode has taken maintenance of this cookbook as the original author has other commitments. This is the initial release with Opscode as maintainer.
|
||||
|
||||
Changes in this release:
|
||||
|
||||
- [pull/2] - support for option passing to brew
|
||||
- [pull/3] - add brew upgrade and control return value from command
|
||||
- [pull/9] - added LWRP for "brew tap"
|
||||
- README is now markdown, not rdoc.
|
||||
167
cookbooks/homebrew/README.md
Normal file
167
cookbooks/homebrew/README.md
Normal file
@@ -0,0 +1,167 @@
|
||||
# Homebrew Cookbook
|
||||
|
||||
This cookbook installs [Homebrew](http://mxcl.github.com/homebrew/) and under Chef 11 and earlier versions, its package provider replaces MacPorts as the *default package provider* for the package resource on OS X systems.
|
||||
|
||||
This cookbook is maintained by CHEF. The original author, maintainer and copyright holder is Graeme Mathieson. The cookbook remains licensed under the Apache License version 2.
|
||||
|
||||
[Original blog post by Graeme](http://woss.name/2011/01/23/converging-your-home-directory-with-chef/)
|
||||
|
||||
# Requirements
|
||||
|
||||
Chef 12: The package provider is not necessary on Chef 12, as the default [OS X package provider](https://github.com/opscode/chef-rfc/blob/master/rfc016-homebrew-osx-package-provider.md) is homebrew.
|
||||
|
||||
Chef <= 11: The package provider will be set as the default provider for OS X.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
In order for this recipe to work, your userid must own `/usr/local`. This is outside the scope of the cookbook because it's possible that you'll run the cookbook as your own user, not root and you'd have to be root to take ownership of the directory. Easiest way to get started:
|
||||
|
||||
```bash
|
||||
sudo chown -R `whoami`:staff /usr/local
|
||||
```
|
||||
|
||||
Bear in mind that this will take ownership of the entire folder and its contents, so if you've already got stuff in there (eg MySQL owned by a `mysql` user) you'll need to be a touch more careful. This is a recommendation from the Homebrew project.
|
||||
|
||||
**Note** This cookbook *only* supports installing in `/usr/local`. While the Homebrew project itself allows for alternative installations, this cookbook doesn't.
|
||||
|
||||
## Platform
|
||||
|
||||
- Mac OS X (10.6+)
|
||||
|
||||
The only platform supported by Homebrew itself at the time of this writing is Mac OS X. It should work fine on Server edition as well, and on platforms that Homebrew supports in the future.
|
||||
|
||||
## Cookbooks
|
||||
|
||||
- build-essential: homebrew itself doesn't work well if XCode is not installed.
|
||||
|
||||
# Attributes
|
||||
|
||||
- `node['homebrew']['owner']` - The user that will own the Homebrew installation and packages. Setting this will override the default behavior which is to use the non-privileged user that has invoked the Chef run (or the `SUDO_USER` if invoked with sudo). The default is `nil`.
|
||||
- `node['homebrew']['auto-update']` - Whether the default recipe should automatically update homebrew each run or not. The default is `true` to maintain compatibility. Set to false or nil to disable. Note that disabling this feature may cause formula to not work.
|
||||
- `node['homebrew']['formulas']` - An Array of formula that should be installed using homebrew by default, used only in the `homebrew::install_formulas` recipe.
|
||||
- `node['homebrew']['casks']` - An Array of casks that should be installed using brew cask by default, used only in the `homebrew::install_casks` recipe.
|
||||
- `node['homebrew']['taps']` - An Array of taps that should be installed using brew tap by default, used only in the `homebrew::install_taps` recipe.
|
||||
|
||||
# Resources and Providers
|
||||
|
||||
This cookbook includes a package resource provider to use homebrew. Under Chef 12+, this is not necessary, and the code doesn't actually get used on Chef 12+. This was preserved to maintain backwards compatiblity with older versions of Chef.
|
||||
|
||||
## package / homebrew\_package
|
||||
|
||||
This cookbook provides a package provider called `homebrew_package` which will install/remove packages using Homebrew. This becomes the default provider for `package` if your platform is Mac OS X.
|
||||
|
||||
As this extends the built-in package resource/provider in Chef, it has all the resource attributes and actions available to the package resource. However, a couple notes:
|
||||
|
||||
- Homebrew itself doesn't have a notion of "upgrade" per se. The "upgrade" action will simply perform an install, and if the Homebrew Formula for the package is newer, it will upgrade.
|
||||
- Likewise, Homebrew doesn't have a purge, but the "purge" action will act like "remove".
|
||||
|
||||
#### Examples
|
||||
|
||||
```ruby
|
||||
package 'mysql' do
|
||||
action :install
|
||||
end
|
||||
|
||||
homebrew_package 'mysql'
|
||||
|
||||
package 'mysql' do
|
||||
provider Chef::Provider::Package::Homebrew
|
||||
end
|
||||
|
||||
package 'wireshark' do
|
||||
options '--with-qt --devel'
|
||||
end
|
||||
```
|
||||
|
||||
### homebrew\_tap
|
||||
|
||||
LWRP for `brew tap`, a Homebrew command used to add additional formula repositories. From the `brew` man page:
|
||||
|
||||
```text
|
||||
tap [tap]
|
||||
Tap a new formula repository from GitHub, or list existing taps.
|
||||
|
||||
tap is of the form user/repo, e.g. brew tap homebrew/dupes.
|
||||
```
|
||||
|
||||
Default action is `:tap` which enables the repository. Use `:untap` to disable a tapped repository.
|
||||
|
||||
#### Examples
|
||||
|
||||
```ruby
|
||||
homebrew_tap 'homebrew/dupes'
|
||||
|
||||
homebrew_tap 'homebrew/dupes' do
|
||||
action :untap
|
||||
end
|
||||
```
|
||||
|
||||
## homebrew\_cask
|
||||
|
||||
LWRP for `brew cask`, a Homebrew-style CLI workflow for the administration
|
||||
of Mac applications distributed as binaries. It's implemented as a homebrew
|
||||
"external command" called cask.
|
||||
|
||||
[homebrew-cask on GitHub](https://github.com/caskroom/homebrew-cask)
|
||||
|
||||
### Prerequisites
|
||||
|
||||
You must have the homebrew-cask repository tapped.
|
||||
|
||||
```ruby
|
||||
homebrew_tap 'caskroom/cask'
|
||||
```
|
||||
|
||||
And then install the homebrew cask package before using this LWRP.
|
||||
|
||||
```ruby
|
||||
package "brew-cask" do
|
||||
action :install
|
||||
end
|
||||
```
|
||||
|
||||
You can include the `homebrew::cask` recipe to do this.
|
||||
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
homebrew_cask "google-chrome"
|
||||
|
||||
homebrew_cask "google-chrome" do
|
||||
action :uncask
|
||||
end
|
||||
```
|
||||
|
||||
Default action is `:cask` which installs the Application binary . Use `:uncask` to
|
||||
uninstall a an Application.
|
||||
|
||||
[View the list of available Casks](https://github.com/caskroom/homebrew-cask/tree/master/Casks)
|
||||
|
||||
# Usage
|
||||
|
||||
We strongly recommend that you put "recipe[homebrew]" in your node's run list, to ensure that it is available on the system and that Homebrew itself gets installed. Putting an explicit dependency in the metadata will cause the cookbook to be downloaded and the library loaded, thus resulting in changing the package provider on Mac OS X, so if you have systems you want to use the default (Mac Ports), they would be changed to Homebrew.
|
||||
|
||||
The default recipe also ensures that Homebrew is installed and up to date if the auto update attribute (above) is true (default).
|
||||
|
||||
# License and Authors
|
||||
|
||||
- Author:: Graeme Mathieson (<mathie@woss.name>)
|
||||
- Author:: Joshua Timberman (<joshua@chef.io>)
|
||||
|
||||
```text
|
||||
Copyright:: 2011, Graeme Mathieson
|
||||
Copyright:: 2012, Opscode, Inc <legal@opscode.com>
|
||||
Copyright:: 2014-2015, Chef Software, Inc. <legal@chef.io>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
not use this file except in compliance with the License. You may obtain
|
||||
a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
```
|
||||
26
cookbooks/homebrew/attributes/default.rb
Normal file
26
cookbooks/homebrew/attributes/default.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# Author:: Joshua Timberman (<jtimberman@opscode.com>)
|
||||
# Author:: Graeme Mathieson (<mathie@woss.name>)
|
||||
# Cookbook Name:: homebrew
|
||||
# Attributes:: default
|
||||
#
|
||||
# Copyright 2011-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
default['homebrew']['owner'] = nil
|
||||
default['homebrew']['auto-update'] = true
|
||||
default['homebrew']['casks'] = []
|
||||
default['homebrew']['formulas'] = node['homebrew']['formula'] || []
|
||||
default['homebrew']['taps'] = []
|
||||
66
cookbooks/homebrew/libraries/homebrew_mixin.rb
Normal file
66
cookbooks/homebrew/libraries/homebrew_mixin.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
#
|
||||
# Author:: Joshua Timberman (<jtimberman@opscode.com>)
|
||||
# Author:: Graeme Mathieson (<mathie@woss.name>)
|
||||
# Cookbook Name:: homebrew
|
||||
# Libraries:: homebrew_mixin
|
||||
#
|
||||
# Copyright 2011-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# Include the mixin from Chef 12 if its defined, when we get to the
|
||||
# #homebrew_owner method below...
|
||||
class Chef12HomebrewUser
|
||||
include Chef::Mixin::HomebrewUser if defined?(Chef::Mixin::HomebrewUser)
|
||||
end
|
||||
|
||||
module Homebrew
|
||||
# Homebrew
|
||||
module Mixin
|
||||
def homebrew_owner
|
||||
if defined?(Chef::Mixin::HomebrewUser)
|
||||
begin
|
||||
@homebrew_owner ||= Chef12HomebrewUser.new.find_homebrew_uid
|
||||
rescue Chef::Exceptions::CannotDetermineHomebrewOwner
|
||||
@homebrew_owner ||= calculate_owner
|
||||
end
|
||||
else
|
||||
@homebrew_owner ||= calculate_owner
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def calculate_owner
|
||||
owner = homebrew_owner_attr || sudo_user || current_user
|
||||
if owner == 'root'
|
||||
fail Chef::Exceptions::User,
|
||||
"Homebrew owner is 'root' which is not supported. " +
|
||||
"To set an explicit owner, please set node['homebrew']['owner']."
|
||||
end
|
||||
owner
|
||||
end
|
||||
|
||||
def homebrew_owner_attr
|
||||
node['homebrew']['owner']
|
||||
end
|
||||
|
||||
def sudo_user
|
||||
ENV['SUDO_USER']
|
||||
end
|
||||
|
||||
def current_user
|
||||
ENV['USER']
|
||||
end
|
||||
end
|
||||
end
|
||||
115
cookbooks/homebrew/libraries/homebrew_package.rb
Normal file
115
cookbooks/homebrew/libraries/homebrew_package.rb
Normal file
@@ -0,0 +1,115 @@
|
||||
#
|
||||
# Author:: Joshua Timberman (<jtimberman@opscode.com>)
|
||||
# Author:: Graeme Mathieson (<mathie@woss.name>)
|
||||
# Cookbook Name:: homebrew
|
||||
# Libraries:: homebrew_package
|
||||
#
|
||||
# Copyright 2011-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# cookbook libraries are unconditionally included if the cookbook is
|
||||
# present on a node. This approach should avoid creating this class if
|
||||
# the node already has Chef::Provider::Package::Homebrew, such as with
|
||||
# Chef 12.
|
||||
# https://github.com/opscode/chef-rfc/blob/master/rfc016-homebrew-osx-package-provider.md
|
||||
unless defined?(Chef::Provider::Package::Homebrew) && Chef::Platform.find('mac_os_x', nil)[:package] == Chef::Provider::Package::Homebrew
|
||||
require 'chef/provider/package'
|
||||
require 'chef/resource/package'
|
||||
require 'chef/platform'
|
||||
require 'chef/mixin/shell_out'
|
||||
|
||||
class Chef
|
||||
class Provider
|
||||
class Package
|
||||
# Package
|
||||
class Homebrew < Package
|
||||
# Homebrew packagex
|
||||
include Chef::Mixin::ShellOut
|
||||
include ::Homebrew::Mixin
|
||||
|
||||
def load_current_resource
|
||||
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
||||
@current_resource.package_name(@new_resource.package_name)
|
||||
@current_resource.version(current_installed_version)
|
||||
|
||||
@current_resource
|
||||
end
|
||||
|
||||
def install_package(name, version)
|
||||
brew('install', @new_resource.options, name)
|
||||
end
|
||||
|
||||
def upgrade_package(name, version)
|
||||
brew('upgrade', name)
|
||||
end
|
||||
|
||||
def remove_package(name, version)
|
||||
brew('uninstall', @new_resource.options, name)
|
||||
end
|
||||
|
||||
# Homebrew doesn't really have a notion of purging, so just remove.
|
||||
def purge_package(name, version)
|
||||
@new_resource.options = ((@new_resource.options || '') << ' --force').strip
|
||||
remove_package(name, version)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def brew(*args)
|
||||
get_response_from_command("brew #{args.join(' ')}")
|
||||
end
|
||||
|
||||
def current_installed_version
|
||||
pkg = get_version_from_formula
|
||||
versions = pkg.to_hash['installed'].map { |v| v['version'] }
|
||||
versions.join(' ') unless versions.empty?
|
||||
end
|
||||
|
||||
def candidate_version
|
||||
pkg = get_version_from_formula
|
||||
pkg.stable ? pkg.stable.version.to_s : pkg.version.to_s
|
||||
end
|
||||
|
||||
def get_version_from_command(command)
|
||||
version = get_response_from_command(command).chomp
|
||||
version.empty? ? nil : version
|
||||
end
|
||||
|
||||
def get_version_from_formula
|
||||
brew_cmd = shell_out!('brew --prefix', :user => homebrew_owner)
|
||||
libpath = ::File.join(brew_cmd.stdout.chomp, 'Library', 'Homebrew')
|
||||
$LOAD_PATH.unshift(libpath)
|
||||
|
||||
require 'global'
|
||||
require 'cmd/info'
|
||||
|
||||
Formula[new_resource.package_name]
|
||||
end
|
||||
|
||||
def get_response_from_command(command)
|
||||
require 'etc'
|
||||
home_dir = Etc.getpwnam(homebrew_owner).dir
|
||||
|
||||
Chef::Log.debug "Executing '#{command}' as #{homebrew_owner}"
|
||||
output = shell_out!(command, :user => homebrew_owner, :environment => { 'HOME' => home_dir, 'RUBYOPT' => nil })
|
||||
output.stdout
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Platform.set :platform => :mac_os_x_server, :resource => :package, :provider => Chef::Provider::Package::Homebrew
|
||||
Chef::Platform.set :platform => :mac_os_x, :resource => :package, :provider => Chef::Provider::Package::Homebrew
|
||||
end
|
||||
43
cookbooks/homebrew/libraries/matchers.rb
Normal file
43
cookbooks/homebrew/libraries/matchers.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
if defined?(ChefSpec)
|
||||
|
||||
def install_homebrew_package(pkg)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_package, :install, pkg)
|
||||
end
|
||||
|
||||
def upgrade_homebrew_package(pkg)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_package, :upgrade, pkg)
|
||||
end
|
||||
|
||||
def remove_homebrew_package(pkg)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_package, :remove, pkg)
|
||||
end
|
||||
|
||||
def purge_homebrew_package(pkg)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_package, :purge, pkg)
|
||||
end
|
||||
|
||||
def tap_homebrew_tap(tap)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_tap, :tap, tap)
|
||||
end
|
||||
|
||||
def untap_homebrew_tap(tap)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_tap, :untap, tap)
|
||||
end
|
||||
|
||||
def cask_homebrew_cask(cask)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_cask, :cask, cask)
|
||||
end
|
||||
|
||||
def uncask_homebrew_cask(cask)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_cask, :uncask, cask)
|
||||
end
|
||||
|
||||
def install_homebrew_cask(cask)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_cask, :install, cask)
|
||||
end
|
||||
|
||||
def uninstall_homebrew_cask(cask)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:homebrew_cask, :uninstall, cask)
|
||||
end
|
||||
|
||||
end
|
||||
33
cookbooks/homebrew/metadata.json
Normal file
33
cookbooks/homebrew/metadata.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "homebrew",
|
||||
"version": "1.12.0",
|
||||
"description": "Install Homebrew, and use it as the OS X package provider on Chef versions =< 11",
|
||||
"long_description": "",
|
||||
"maintainer": "Chef Software, Inc.",
|
||||
"maintainer_email": "cookbooks@chef.io",
|
||||
"license": "Apache 2.0",
|
||||
"platforms": {
|
||||
"mac_os_x": ">= 0.0.0",
|
||||
"mac_os_x_server": ">= 0.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"build-essential": ">= 2.1.2"
|
||||
},
|
||||
"recommendations": {
|
||||
},
|
||||
"suggestions": {
|
||||
},
|
||||
"conflicting": {
|
||||
},
|
||||
"providing": {
|
||||
},
|
||||
"replacing": {
|
||||
},
|
||||
"attributes": {
|
||||
},
|
||||
"groupings": {
|
||||
},
|
||||
"recipes": {
|
||||
"homebrew": "Install Homebrew"
|
||||
}
|
||||
}
|
||||
10
cookbooks/homebrew/metadata.rb
Normal file
10
cookbooks/homebrew/metadata.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
name 'homebrew'
|
||||
maintainer 'Chef Software, Inc.'
|
||||
maintainer_email 'cookbooks@chef.io'
|
||||
license 'Apache 2.0'
|
||||
description 'Install Homebrew, and use it as the OS X package provider on Chef versions =< 11'
|
||||
version '1.12.0'
|
||||
recipe 'homebrew', 'Install Homebrew'
|
||||
supports 'mac_os_x'
|
||||
supports 'mac_os_x_server'
|
||||
depends 'build-essential', '>= 2.1.2'
|
||||
36
cookbooks/homebrew/providers/cask.rb
Normal file
36
cookbooks/homebrew/providers/cask.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'chef/mixin/shell_out'
|
||||
include Chef::Mixin::ShellOut
|
||||
include ::Homebrew::Mixin
|
||||
|
||||
use_inline_resources if defined?(:use_inline_resources)
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
@cask = Chef::Resource::HomebrewCask.new(new_resource.name)
|
||||
Chef::Log.debug("Checking whether #{new_resource.name} is installed")
|
||||
@cask.casked shell_out("/usr/local/bin/brew cask list | grep #{new_resource.name}").exitstatus == 0
|
||||
end
|
||||
|
||||
action :install do
|
||||
unless @cask.casked
|
||||
execute "installing cask #{new_resource.name}" do
|
||||
command "/usr/local/bin/brew cask install #{new_resource.name}"
|
||||
user homebrew_owner
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :uninstall do
|
||||
if @cask.casked
|
||||
execute "uninstalling cask #{new_resource.name}" do
|
||||
command "/usr/local/bin/brew cask uninstall #{new_resource.name}"
|
||||
user homebrew_owner
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :action_cask, :action_install
|
||||
alias_method :action_uncask, :action_uninstall
|
||||
54
cookbooks/homebrew/providers/tap.rb
Normal file
54
cookbooks/homebrew/providers/tap.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
#
|
||||
# Author:: Joshua Timberman (<jtimberman@opscode.com>)
|
||||
# Author:: Graeme Mathieson (<mathie@woss.name>)
|
||||
# Cookbook Name:: homebrew
|
||||
# Providers:: tap
|
||||
#
|
||||
# Copyright 2011-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include ::Homebrew::Mixin
|
||||
|
||||
def load_current_resource
|
||||
@tap = Chef::Resource::HomebrewTap.new(new_resource.name)
|
||||
tap_dir = @tap.name.gsub('/', '/homebrew-')
|
||||
|
||||
Chef::Log.debug("Checking whether we've already tapped #{new_resource.name}")
|
||||
if ::File.directory?("/usr/local/Library/Taps/#{tap_dir}")
|
||||
@tap.tapped true
|
||||
else
|
||||
@tap.tapped false
|
||||
end
|
||||
end
|
||||
|
||||
action :tap do
|
||||
unless @tap.tapped
|
||||
execute "tapping #{new_resource.name}" do
|
||||
command "/usr/local/bin/brew tap #{new_resource.name}"
|
||||
not_if "/usr/local/bin/brew tap | grep #{new_resource.name}"
|
||||
user homebrew_owner
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :untap do
|
||||
if @tap.tapped
|
||||
execute "untapping #{new_resource.name}" do
|
||||
command "/usr/local/bin/brew untap #{new_resource.name}"
|
||||
only_if "/usr/local/bin/brew tap | grep #{new_resource.name}"
|
||||
user homebrew_owner
|
||||
end
|
||||
end
|
||||
end
|
||||
39
cookbooks/homebrew/recipes/cask.rb
Normal file
39
cookbooks/homebrew/recipes/cask.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
#
|
||||
# Cookbook Name:: homebrew
|
||||
# Recipes:: cask
|
||||
#
|
||||
# Copyright 2014, Chef Software, Inc <legal@getchef.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
Chef::Resource.send(:include, Homebrew::Mixin)
|
||||
|
||||
homebrew_tap 'caskroom/cask'
|
||||
|
||||
package 'brew-cask'
|
||||
|
||||
execute 'update homebrew cask from github' do
|
||||
user node['homebrew']['owner'] || homebrew_owner
|
||||
command '/usr/local/bin/brew upgrade brew-cask && /usr/local/bin/brew cask cleanup || true'
|
||||
only_if { node['homebrew']['auto-update'] }
|
||||
end
|
||||
|
||||
directory '/opt/homebrew-cask' do
|
||||
owner node['homebrew']['owner'] || homebrew_owner
|
||||
mode 00775
|
||||
end
|
||||
|
||||
directory '/opt/homebrew-cask/Caskroom' do
|
||||
owner node['homebrew']['owner'] || homebrew_owner
|
||||
mode 00775
|
||||
end
|
||||
49
cookbooks/homebrew/recipes/default.rb
Normal file
49
cookbooks/homebrew/recipes/default.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
#
|
||||
# Author:: Joshua Timberman (<jtimberman@opscode.com>)
|
||||
# Author:: Graeme Mathieson (<mathie@woss.name>)
|
||||
# Cookbook Name:: homebrew
|
||||
# Recipes:: default
|
||||
#
|
||||
# Copyright 2011-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
Chef::Resource.send(:include, Homebrew::Mixin)
|
||||
Chef::Recipe.send(:include, Homebrew::Mixin)
|
||||
|
||||
homebrew_go = "#{Chef::Config[:file_cache_path]}/homebrew_go"
|
||||
|
||||
Chef::Log.debug("Homebrew owner is '#{homebrew_owner}'")
|
||||
|
||||
remote_file homebrew_go do
|
||||
source 'https://raw.githubusercontent.com/Homebrew/install/master/install'
|
||||
mode 00755
|
||||
end
|
||||
|
||||
execute 'install homebrew' do
|
||||
command homebrew_go
|
||||
user node['homebrew']['owner'] || homebrew_owner
|
||||
not_if { ::File.exist? '/usr/local/bin/brew' }
|
||||
end
|
||||
|
||||
if node['homebrew']['auto-update']
|
||||
package 'git' do
|
||||
not_if 'which git'
|
||||
end
|
||||
|
||||
execute 'update homebrew from github' do
|
||||
user homebrew_owner
|
||||
command '/usr/local/bin/brew update || true'
|
||||
end
|
||||
end
|
||||
24
cookbooks/homebrew/recipes/install_casks.rb
Normal file
24
cookbooks/homebrew/recipes/install_casks.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# Cookbook Name:: homebrew
|
||||
# Recipes:: install_casks
|
||||
#
|
||||
# Copyright 2014, Chef Software, Inc <legal@getchef.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe 'homebrew::cask'
|
||||
|
||||
node['homebrew']['casks'].each do |cask|
|
||||
homebrew_cask cask
|
||||
end
|
||||
24
cookbooks/homebrew/recipes/install_formulas.rb
Normal file
24
cookbooks/homebrew/recipes/install_formulas.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# Cookbook Name:: homebrew
|
||||
# Recipes:: install_casks
|
||||
#
|
||||
# Copyright 2014, Chef Software, Inc <legal@getchef.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe 'homebrew'
|
||||
|
||||
node['homebrew']['formulas'].each do |formula|
|
||||
package formula
|
||||
end
|
||||
24
cookbooks/homebrew/recipes/install_taps.rb
Normal file
24
cookbooks/homebrew/recipes/install_taps.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# Cookbook Name:: homebrew
|
||||
# Recipes:: install_taps
|
||||
#
|
||||
# Copyright 2015, Chef Software, Inc <legal@getchef.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe 'homebrew'
|
||||
|
||||
node['homebrew']['taps'].each do |tap|
|
||||
homebrew_tap tap
|
||||
end
|
||||
19
cookbooks/homebrew/resources/cask.rb
Normal file
19
cookbooks/homebrew/resources/cask.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
actions :cask, :uncask, :install, :uninstall
|
||||
attribute :name,
|
||||
:name_attribute => true,
|
||||
:kind_of => String,
|
||||
:regex => /^[\w-]+$/
|
||||
|
||||
attribute :casked,
|
||||
:kind_of => [TrueClass, FalseClass]
|
||||
|
||||
if defined?(:default_action)
|
||||
default_action :install
|
||||
else
|
||||
Chef::Log.warn("It appears you have Chef version #{Chef::VERSION},")
|
||||
Chef::Log.warn('homebrew_cask resource will remove support for versions of Chef < 10.10 in the next major release of the cookbook')
|
||||
def initialize(*args)
|
||||
super
|
||||
@action = :install
|
||||
end
|
||||
end
|
||||
35
cookbooks/homebrew/resources/tap.rb
Normal file
35
cookbooks/homebrew/resources/tap.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
#
|
||||
# Author:: Joshua Timberman (<jtimberman@opscode.com>)
|
||||
# Author:: Graeme Mathieson (<mathie@woss.name>)
|
||||
# Cookbook Name:: homebrew
|
||||
# Resources:: tap
|
||||
#
|
||||
# Copyright 2011-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :tap, :untap
|
||||
attribute :name,
|
||||
:name_attribute => true,
|
||||
:kind_of => String,
|
||||
:regex => /^[\w-]+(?:\/[\w-]+)+$/
|
||||
|
||||
attribute :tapped,
|
||||
:kind_of => [TrueClass, FalseClass]
|
||||
|
||||
### hax for default action
|
||||
def initialize(*args)
|
||||
super
|
||||
@action = :tap
|
||||
end
|
||||
Reference in New Issue
Block a user