diff options
-rw-r--r-- | lib/chef/resource/build_essential.rb | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb index fb9ef814a5..be07f153f8 100644 --- a/lib/chef/resource/build_essential.rb +++ b/lib/chef/resource/build_essential.rb @@ -47,21 +47,23 @@ class Chef declare_resource(:package, "devel/m4") declare_resource(:package, "devel/gettext") when "mac_os_x" - # 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 - declare_resource(:execute, "install XCode Command Line tools") do - 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" --verbose - # Remove the placeholder to prevent perpetual appearance in the update utility - rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress - EOH - # rubocop:enable Metrics/LineLength + unless xcode_cli_installed? + # 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 + declare_resource(:execute, "install XCode Command Line tools") do + 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. 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') + # install it + softwareupdate -i "$PROD" --verbose + # Remove the placeholder to prevent perpetual appearance in the update utility + rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress + EOH + # rubocop:enable Metrics/LineLength + end end when "omnios" declare_resource(:package, "developer/gcc48") @@ -112,6 +114,22 @@ class Chef end end + action_class do + # + # Determine if the XCode Command Line Tools are installed + # + # @return [true, false] + # + def xcode_cli_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 + # this resource forces itself to run at compile_time def after_created return unless compile_time |