class Chef::Resource::BuildEssential

Public Instance Methods

install_xcode_cli_tools(label) click to toggle source

Install Xcode Command Line tools via softwareupdate CLI

@param [String] label The label (package name) to install

# File lib/chef/resource/build_essential.rb, line 141
        def install_xcode_cli_tools(label)
          # 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
          bash "install Xcode Command Line Tools" do
            code <<-EOH
              # 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
              # install it
              softwareupdate -i "#{label}" --verbose
              # Remove the placeholder to prevent perpetual appearance in the update utility
              rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
            EOH
          end
        end
xcode_cli_installed?() click to toggle source

Determine if the XCode Command Line Tools are installed by checking for success from `xcode-select -p`

@return [true, false]

# File lib/chef/resource/build_essential.rb, line 162
def xcode_cli_installed?
  !shell_out("xcode-select", "-p").error?
end
xcode_cli_package_label() click to toggle source

Return to package label of the latest Xcode Command Line Tools update, if available

@return [String, NilClass]

# File lib/chef/resource/build_essential.rb, line 170
def xcode_cli_package_label
  available_updates = shell_out("softwareupdate", "--list")

  # raise if we fail to check
  available_updates.error!

  # https://rubular.com/r/UPEE5P7mZLvXNs
  # this will return the match or nil
  available_updates.stdout[/^\s*\* (?:Label: )?(Command Line Tools.*)/, 1]
end