always generate CLT demand file
This commit is contained in:
Родитель
8dde4a5580
Коммит
e9d015e8cb
|
@ -1,11 +1,11 @@
|
|||
# command_line_tools
|
||||
|
||||
The [``command_line_tools``](https://github.com/Microsoft/macos-cookbook/blob/master/resources/command_line_tools.rb) resource manages the state of a single Xcode Command Line Tools installation, and will only install the latest version for the current running version of macOS.
|
||||
The [`command_line_tools`](https://github.com/Microsoft/macos-cookbook/blob/master/resources/command_line_tools.rb) resource manages the state of a single Xcode Command Line Tools installation, and will only install the latest version for the current running version of macOS.
|
||||
|
||||
## Syntax
|
||||
|
||||
```ruby
|
||||
command_line_tools 'name' do
|
||||
command_line_tools 'name' do # defaults to '' if not specified
|
||||
compile_time true, false # defaults to false if not specified
|
||||
action Symbol # defaults to :install if not specified
|
||||
end
|
||||
|
@ -13,32 +13,32 @@ end
|
|||
|
||||
where:
|
||||
|
||||
- ``command_line_tools`` is the resource.
|
||||
- ``name`` is the name given to the resource block.
|
||||
- ``action`` identifies which steps the chef-client will take to bring the node into the desired state.
|
||||
- ``compile_time`` is the property available to this resource.
|
||||
- `command_line_tools` is the resource.
|
||||
- `name` is the name given to the resource block, which is optional.
|
||||
- `action` identifies which steps the chef-client will take to bring the node into the desired state.
|
||||
- `compile_time` is the property available to this resource.
|
||||
|
||||
## Actions
|
||||
|
||||
The ``command_line_tools`` resource has the following actions:
|
||||
The `command_line_tools` resource has the following actions:
|
||||
|
||||
``:install``
|
||||
`:install`
|
||||
|
||||
Default. Install Command Line Tools from Apple. Takes no action if any version has previously been installed on the system.
|
||||
Default. Install Command Line Tools from Apple. Takes no action if any version has previously been installed on the system, unless that version has been deleted, in which case it will attempt to install that version again.
|
||||
|
||||
``:upgrade``
|
||||
`:upgrade`
|
||||
|
||||
Check for an updated version of Command Line Tools and install them if available.
|
||||
Check for an updated version of Command Line Tools and install them, unless the latest version is already installed.
|
||||
|
||||
``:nothing``
|
||||
`:nothing`
|
||||
|
||||
This resource block does not act unless notified by another resource to take action. Once notified, this resource block either runs immediately or is queued up to run at the end of the Chef Client run.
|
||||
|
||||
## Properties
|
||||
|
||||
``compile_time``
|
||||
`compile_time`
|
||||
|
||||
**Ruby Type:** true, false | **Default Value:** ``false``
|
||||
**Ruby Type:** true, false | **Default Value:** `false`
|
||||
|
||||
Install the Xcode Command Line Tools at compile time.
|
||||
|
||||
|
@ -47,7 +47,7 @@ The ``command_line_tools`` resource has the following actions:
|
|||
### Install Xcode Command Line Tools
|
||||
|
||||
```ruby
|
||||
command_line_tools 'random_name'
|
||||
command_line_tools
|
||||
```
|
||||
|
||||
If running **macOS 10.14.2**, it will install **'Command Line Tools (macOS Mojave version 10.14) for Xcode-10.14'** via the `softwareupdate` utility.
|
||||
|
|
34
kitchen.yml
34
kitchen.yml
|
@ -7,6 +7,7 @@ driver:
|
|||
|
||||
provisioner:
|
||||
product_name: chef
|
||||
product_version: 18
|
||||
multiple_converge: 2
|
||||
|
||||
verifier:
|
||||
|
@ -19,33 +20,20 @@ verifier:
|
|||
- test/integration/default
|
||||
|
||||
platforms:
|
||||
- name: mojave-chef17
|
||||
driver:
|
||||
box: microsoft/macos-mojave
|
||||
box_version: 10.14.6
|
||||
provisioner:
|
||||
product_version: 17
|
||||
|
||||
- name: catalina-chef17
|
||||
driver:
|
||||
box: microsoft/macos-catalina
|
||||
box_version: 10.15.7
|
||||
provisioner:
|
||||
product_version: 17
|
||||
|
||||
- name: big-sur-chef17
|
||||
- name: big-sur-x86
|
||||
driver:
|
||||
box: microsoft/macos-big-sur
|
||||
box_version: 11.6.5
|
||||
provisioner:
|
||||
product_version: 17
|
||||
box_version: 11.7.8
|
||||
|
||||
- name: monterey-chef17
|
||||
- name: monterey-x86
|
||||
driver:
|
||||
box: microsoft/macos-monterey
|
||||
box_version: 12.6.3
|
||||
provisioner:
|
||||
product_version: 17
|
||||
box_version: 12.6.7
|
||||
|
||||
- name: ventura-arm
|
||||
driver:
|
||||
box: microsoft/macos-ventura-arm
|
||||
box_version: 13.4.1
|
||||
|
||||
suites:
|
||||
- name: default
|
||||
|
@ -104,7 +92,7 @@ suites:
|
|||
- recipe[macos_test::command_line_tools]
|
||||
verifier:
|
||||
controls:
|
||||
- command-line-tool-sentinel
|
||||
- command-line-tool-demand
|
||||
- xcrun
|
||||
|
||||
- name: certificate
|
||||
|
|
|
@ -6,20 +6,20 @@ module MacOS
|
|||
attr_reader :version
|
||||
|
||||
def initialize
|
||||
@version = if installed.empty?
|
||||
@version = if install_receipts.empty?
|
||||
latest_from_catalog
|
||||
else
|
||||
latest_installed
|
||||
latest_receipt
|
||||
end
|
||||
end
|
||||
|
||||
def installed
|
||||
def install_receipts
|
||||
packages = Plist.parse_xml(install_history_plist)
|
||||
packages.select { |package| package['displayName'].match? 'Command Line Tools' }
|
||||
end
|
||||
|
||||
def latest_installed
|
||||
[installed.last['displayName'], installed.last['displayVersion']].join '-'
|
||||
def latest_receipt
|
||||
[install_receipts.last['displayName'], install_receipts.last['displayVersion']].join '-'
|
||||
end
|
||||
|
||||
def latest_from_catalog
|
||||
|
@ -46,7 +46,7 @@ module MacOS
|
|||
end
|
||||
|
||||
def all_available
|
||||
softwareupdate_list.select { |product_name| product_name.match /\*.{1,8}Command Line Tools/ }
|
||||
softwareupdate_list.select { |product_name| product_name.match(/\*.{1,8}Command Line Tools/) }
|
||||
end
|
||||
|
||||
def platform_specific
|
||||
|
@ -54,9 +54,9 @@ module MacOS
|
|||
end
|
||||
|
||||
def enable_install_on_demand
|
||||
install_sentinel = '/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress'
|
||||
FileUtils.touch install_sentinel
|
||||
FileUtils.chown 'root', 'wheel', install_sentinel
|
||||
install_demand = '/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress'
|
||||
FileUtils.touch install_demand
|
||||
FileUtils.chown 'root', 'wheel', install_demand
|
||||
end
|
||||
|
||||
def xcode_version(product)
|
||||
|
|
|
@ -2,45 +2,46 @@ unified_mode true
|
|||
|
||||
provides :command_line_tools
|
||||
|
||||
property :name, String, default: ''
|
||||
property :compile_time, [true, false],
|
||||
description: 'Install the Xcode Command Line Tools at compile time.',
|
||||
default: false, desired_state: false
|
||||
|
||||
action :install do
|
||||
command_line_tools = CommandLineTools.new
|
||||
|
||||
file 'create sentinel file' do
|
||||
file 'create demand file' do
|
||||
path '/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress'
|
||||
group 'wheel'
|
||||
end
|
||||
|
||||
command_line_tools = CommandLineTools.new
|
||||
|
||||
execute "install #{command_line_tools.version}" do
|
||||
command ['softwareupdate', '--install', command_line_tools.version]
|
||||
not_if { ::File.exist?('/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib') }
|
||||
live_stream true
|
||||
end
|
||||
|
||||
file 'delete sentinel file' do
|
||||
file 'delete demand file' do
|
||||
path '/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress'
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
|
||||
action :upgrade do
|
||||
command_line_tools = CommandLineTools.new
|
||||
|
||||
file 'create sentinel file' do
|
||||
file 'create demand file' do
|
||||
path '/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress'
|
||||
group 'wheel'
|
||||
end
|
||||
|
||||
command_line_tools = CommandLineTools.new
|
||||
|
||||
execute "upgrade #{command_line_tools.version}" do
|
||||
command ['softwareupdate', '--install', command_line_tools.latest_from_catalog]
|
||||
not_if { command_line_tools.version == command_line_tools.latest_from_catalog }
|
||||
live_stream true
|
||||
end
|
||||
|
||||
file 'delete sentinel file' do
|
||||
file 'delete demand file' do
|
||||
path '/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress'
|
||||
action :delete
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
include MacOS
|
||||
|
||||
shared_context 'able to create on-demand installation sentinel' do
|
||||
shared_context 'able to create on-demand installation demand' do
|
||||
before do
|
||||
allow(FileUtils).to receive(:touch).and_return(true)
|
||||
allow(FileUtils).to receive(:chown).and_return(true)
|
||||
|
@ -38,7 +38,7 @@ end
|
|||
|
||||
describe MacOS::CommandLineTools do
|
||||
context 'when there are several products for one Xcode version but several macOS versions' do
|
||||
include_context 'able to create on-demand installation sentinel'
|
||||
include_context 'able to create on-demand installation demand'
|
||||
include_context 'on macOS Mojave'
|
||||
include_context 'with no CLT previously installed'
|
||||
before do
|
||||
|
@ -59,7 +59,7 @@ describe MacOS::CommandLineTools do
|
|||
end
|
||||
|
||||
context 'when there are no products for the current macOS version' do
|
||||
include_context 'able to create on-demand installation sentinel'
|
||||
include_context 'able to create on-demand installation demand'
|
||||
include_context 'on macOS Mojave'
|
||||
include_context 'with no CLT previously installed'
|
||||
before do
|
||||
|
@ -79,7 +79,7 @@ describe MacOS::CommandLineTools do
|
|||
end
|
||||
|
||||
context 'when provided an available list of software update products in Catalina' do
|
||||
include_context 'able to create on-demand installation sentinel'
|
||||
include_context 'able to create on-demand installation demand'
|
||||
include_context 'on macOS Catalina'
|
||||
include_context 'with no CLT previously installed'
|
||||
before do
|
||||
|
@ -97,7 +97,7 @@ describe MacOS::CommandLineTools do
|
|||
end
|
||||
|
||||
context 'when provided an available list of software update products in Catalina' do
|
||||
include_context 'able to create on-demand installation sentinel'
|
||||
include_context 'able to create on-demand installation demand'
|
||||
include_context 'on macOS Catalina'
|
||||
include_context 'with CLT previously installed'
|
||||
before do
|
||||
|
|
|
@ -21,9 +21,9 @@ describe 'command_line_tools' do
|
|||
end
|
||||
end
|
||||
|
||||
it { is_expected.to create_file('create sentinel file') }
|
||||
it { is_expected.to create_file('create demand file') }
|
||||
it { is_expected.to run_execute('install Command Line Tools (macOS High Sierra version 10.13) for Xcode-10.0') }
|
||||
it { is_expected.to delete_file('delete sentinel file') }
|
||||
it { is_expected.to delete_file('delete demand file') }
|
||||
end
|
||||
|
||||
context 'with libxcrun present' do
|
||||
|
@ -37,9 +37,9 @@ describe 'command_line_tools' do
|
|||
end
|
||||
end
|
||||
|
||||
it { is_expected.to create_file('create sentinel file') }
|
||||
it { is_expected.to create_file('create demand file') }
|
||||
it { is_expected.to_not run_execute('install Command Line Tools (macOS High Sierra version 10.13) for Xcode-10.0') }
|
||||
it { is_expected.to delete_file('delete sentinel file') }
|
||||
it { is_expected.to delete_file('delete demand file') }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -65,11 +65,11 @@ describe 'command_line_tools' do
|
|||
end
|
||||
end
|
||||
|
||||
it { is_expected.to create_file('create sentinel file') }
|
||||
it { is_expected.to create_file('create demand file') }
|
||||
it {
|
||||
is_expected.to run_execute('upgrade Command Line Tools for Xcode-11.0')
|
||||
.with(command: ['softwareupdate', '--install', 'Command Line Tools for Xcode-22.0'])
|
||||
}
|
||||
it { is_expected.to delete_file('delete sentinel file') }
|
||||
it { is_expected.to delete_file('delete demand file') }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1 @@
|
|||
command_line_tools 'install them' do
|
||||
action :install
|
||||
end
|
||||
|
||||
command_line_tools 'upgrade them' do
|
||||
action :upgrade
|
||||
end
|
||||
command_line_tools
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
title 'xcode command line tools'
|
||||
|
||||
control 'command-line-tool-sentinel' do
|
||||
title 'Command Line Tools sentinel has been deleted'
|
||||
control 'command-line-tool-demand' do
|
||||
title 'Command Line Tools demand has been deleted'
|
||||
desc '
|
||||
Verify that the Command Line Tools sentinel has been deleted, and that
|
||||
Verify that the Command Line Tools demand has been deleted, and that
|
||||
there are no lingering CLT updates since we should have installed the latest
|
||||
'
|
||||
describe file('/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress') do
|
||||
|
|
Загрузка…
Ссылка в новой задаче