summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Seeber <harry@sysop.ooo>2019-12-18 13:20:41 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-31 10:51:50 -0700
commit40353d06191524de4a9289d132c1c1eb7bd8d518 (patch)
treeb5de36783c249fb4465651f989e0f1b92912223d
parent22f0f14f99d3ba51aa7b189f1f3ffceb95838a1b (diff)
downloadchef-40353d06191524de4a9289d132c1c1eb7bd8d518.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 a142932258..b378d61bf3 100644
--- a/lib/chef/resource/build_essential.rb
+++ b/lib/chef/resource/build_essential.rb
@@ -61,7 +61,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
@@ -70,7 +71,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
@@ -138,6 +139,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
end
end