Initial Chef repository

This commit is contained in:
Greg Karékinian
2015-07-21 19:45:23 +02:00
parent 7e5401fc71
commit ee4079fa85
1151 changed files with 185163 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
if defined?(ChefSpec)
def install_xcode_command_line_tools(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:xcode_command_line_tools, :install, resource_name)
end
end

View File

@@ -0,0 +1,124 @@
#
# Cookbook Name:: build-essential
# Library:: timing
#
# Copyright 2014, Chef Software, 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.
#
#
# This module is used to clean up the recipe DSL and "potentially" execute
# resources at compile time (depending on the value of an attribute).
#
# This library is only for use within the build-essential cookbook. Resources
# inside the potentially_at_compile_time block will not fire notifications in
# some situations. This is fixable, but since none of the resources in this
# cookbook actually use notifications, it is not worth the added technical debt.
#
# TL;DR Don't use this DSL method outside of this cookbook.
#
module BuildEssential
module Timing
#
# Potentially evaluate the given block at compile time, depending on the
# value of the +node['build-essential']['compile_time']+ attribute.
#
# @example
# potentially_at_compile_time do
# package 'apache2'
# end
#
# @param [Proc] block
# the thing to eval
#
def potentially_at_compile_time(&block)
if compile_time?
CompileTime.new(self).evaluate(&block)
else
instance_eval(&block)
end
end
private
#
# Checks if the DSL should be evaluated at compile time.
#
# @return [true, false]
#
def compile_time?
check_for_old_attributes!
!!node['build-essential']['compile_time']
end
#
# Checks for the presence of the "old" attributes.
#
# @todo Remove in 2.0.0
#
# @return [void]
#
def check_for_old_attributes!
unless node['build_essential'].nil?
Chef::Log.warn <<-EOH
node['build_essential'] has been changed to node['build-essential'] to match the
cookbook name and community standards. I have gracefully converted the attribute
for you, but this warning and conversion will be removed in the next major
release of the build-essential cookbook.
EOH
node.default['build-essential'] = node['build_essential']
end
unless node['build-essential']['compiletime'].nil?
Chef::Log.warn <<-EOH
node['build-essential']['compiletime'] has been deprecated. Please use
node['build-essential']['compile_time'] instead. I have gracefully converted the
attribute for you, but this warning and converstion will be removed in the next
major release of the build-essential cookbook.
EOH
node.default['build-essential']['compile_time'] = node['build-essential']['compiletime']
end
end
#
# A class graciously borrowed from Chef Sugar for evaluating a resource at
# compile time in a block.
#
class CompileTime
def initialize(recipe)
@recipe = recipe
end
def evaluate(&block)
instance_eval(&block)
end
def method_missing(m, *args, &block)
resource = @recipe.send(m, *args, &block)
if resource.is_a?(Chef::Resource)
actions = Array(resource.action)
resource.action(:nothing)
actions.each do |action|
resource.run_action(action)
end
end
resource
end
end
end
end
# Include the timing module into the main recipe DSL
Chef::Recipe.send(:include, BuildEssential::Timing)

View File

@@ -0,0 +1,211 @@
#
# Cookbook Name:: build-essential
# Library:: xcode_command_line_tools
#
# Copyright 2014, Chef Software, 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.
#
class Chef
class Resource::XcodeCommandLineTools < Resource::LWRPBase
def self.resource_name
:xcode_command_line_tools
end
actions :install
default_action :install
def initialize(name, run_context = nil)
super
@provider = case node['platform_version'].to_f
when 10.7, 10.8
Provider::XcodeCommandLineToolsFromDmg
when 10.9, 10.10
Provider::XcodeCommandLineToolsFromSoftwareUpdate
else
Chef::Log.warn <<-EOH
OSX #{node['platform_version']} is not an officially supported platform for the
build-essential cookbook. I am going to try and install the command line tools
from Software Update, but there is a high probability that it will fail...
If you have tested and verified OSX #{node['platform_version']} and you are sick
of seeing this warning in your Chef Client runs, please submit a Pull Request to
https://github.com/chef-cookbooks/build-essential and add this version of OSX
to provider list.
EOH
Provider::XcodeCommandLineToolsFromSoftwareUpdate
end
end
end
end
#
# This is a legacy provider for installing OSX from DMGs. It only supports OSX
# versions 10.7 and 10.8 and will (hopefully) be deprecated in the future. It
# downloads a remote .dmg file, mounts it, installs it, and unmounts it
# automatically. In later versions of OSX, the operating system handles this for
# the end user.
#
class Chef
class Provider::XcodeCommandLineToolsFromDmg < Provider::LWRPBase
action(:install) do
if installed?
Chef::Log.debug("#{new_resource} already installed - skipping")
else
converge_by("Install #{new_resource}") do
download
attach
install
detach
end
end
end
private
#
# Determine if the XCode Command Line Tools are installed
#
# @return [true, false]
#
def installed?
cmd = Mixlib::ShellOut.new('pkgutil --pkgs=com.apple.pkg.DeveloperToolsCLI')
cmd.run_command
cmd.error!
true
rescue Mixlib::ShellOut::ShellCommandFailed
false
end
#
# The path where the dmg should be cached on disk.
#
# @return [String]
#
def dmg_cache_path
::File.join(Chef::Config[:file_cache_path], 'osx-command-line-tools.dmg')
end
#
# The path where the dmg should be downloaded from. This is intentionally
# not a configurable object by the end user. If you do not like where we
# are downloading XCode from - too bad.
#
# @return [String]
#
def dmg_remote_source
case node['platform_version'].to_f
when 10.7
'http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg'
when 10.8
'http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_mountain_lion_march_2014.dmg'
else
raise "Unknown DMG download URL for OSX #{node['platform_version']}"
end
end
#
# The path where the volume should be mounted.
#
# @return [String]
#
def mount_path
::File.join(Chef::Config[:file_cache_path], 'osx-command-line-tools')
end
#
# Action: download the remote dmg.
#
# @return [void]
#
def download
remote_file = Resource::RemoteFile.new(dmg_cache_path, run_context)
remote_file.source(dmg_remote_source)
remote_file.backup(false)
remote_file.run_action(:create)
end
#
# Action: attach the dmg (basically, double-click on it)
#
# @return [void]
#
def attach
execute %|hdiutil attach "#{dmg_cache_path}" -mountpoint "#{mount_path}"|
end
#
# Action: install the package inside the dmg
#
# @return [void]
#
def install
execute %|installer -package "$(find '#{mount_path}' -name *.mpkg)" -target "/"|
end
#
# Action: detach the dmg (basically, drag it to eject on the dock)
#
# @return [void]
#
def detach
execute %|hdiutil detach "#{mount_path}"|
end
end
end
class Chef
class Provider::XcodeCommandLineToolsFromSoftwareUpdate < Provider::LWRPBase
action(:install) do
if installed?
Chef::Log.debug("#{new_resource} already installed - skipping")
else
converge_by("Install #{new_resource}") do
# This script was graciously borrowed and modified from Tim Sutton's
# osx-vm-templates at https://github.com/timsutton/osx-vm-templates/blob/b001475df54a9808d3d56d06e71b8fa3001fff42/scripts/xcode-cli-tools.sh
execute 'install XCode Command Line tools' do
# rubocop:disable Metrics/LineLength
command <<-EOH.gsub(/^ {14}/, '')
# create the placeholder file that's checked by CLI updates' .dist code
# in Apple's SUS catalog
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
# find the CLI Tools update
PROD=$(softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n')
# install it
softwareupdate -i "$PROD" -v
EOH
# rubocop:enable Metrics/LineLength
end
end
end
end
private
#
# Determine if the XCode Command Line Tools are installed
#
# @return [true, false]
#
def installed?
cmd = Mixlib::ShellOut.new('pkgutil --pkgs=com.apple.pkg.CLTools_Executables')
cmd.run_command
cmd.error!
true
rescue Mixlib::ShellOut::ShellCommandFailed
false
end
end
end