summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Seeber <harry@sysop.ooo>2019-12-18 13:20:41 -0700
committerTim Smith <tsmith84@gmail.com>2020-04-02 12:27:00 -0700
commitbc54f5dc57666659b08319af13377105e904a608 (patch)
tree1d7141f5573807dd26274c6753fbbdc9a9f5dee1
parentc39fdfccdd7a1446a026471943e1ac1e262e6644 (diff)
downloadchef-bc54f5dc57666659b08319af13377105e904a608.tar.gz
support Catalina softwareupdate output ("Label: ") and support updating CLT when updates are available
Signed-off-by: Harry Seeber <harry@sysop.ooo>
-rw-r--r--lib/chef/resource/build_essential.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb
index 963481b5ee..141e591a3b 100644
--- a/lib/chef/resource/build_essential.rb
+++ b/lib/chef/resource/build_essential.rb
@@ -67,7 +67,8 @@ class Chef
package "devel/m4"
package "devel/gettext"
when macos?
- unless xcode_cli_installed?
+ update_label = xcode_cli_package
+ unless xcode_cli_installed? && update_label.empty?
# 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
@@ -76,7 +77,7 @@ class Chef
# in Apple's SUS catalog
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
# find the CLI Tools update. We tail here because sometimes there's 2 and newest is last
- PROD=$(softwareupdate -l | grep "\*.*Command Line" | tail -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n')
+ PROD=#{update_label}
# install it
softwareupdate -i "$PROD" --verbose
# Remove the placeholder to prevent perpetual appearance in the update utility
@@ -151,6 +152,19 @@ class Chef
# pkgutil returns an error if the package isn't found aka not installed
cmd.error? ? false : true
end
+
+ #
+ # Return to package label of the latest XCode Command Line Tools update, if available
+ #
+ # @return [String]
+ def xcode_cli_package
+ cmd = <<-EOH.gsub(/^ {14}/, '')
+ softwareupdate -l | grep "\*.*Command Line" | tail -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n' | sed 's/Label: //g'
+ EOH
+ cmd.run_command
+ cmd.error!
+ cmd.stdout
+ end
end
# this resource forces itself to run at compile_time