Resource to install .pkg files on Mac nodes without brew or MacPorts?

Hi,

This may be a dumb question…but how do I install a .pkg file from a URL on a Mac OS X node without using MacPorts or homebrew?

I can just use the execute resource and call ‘installer’ but I was wondering if there was an LWRP for this.

There is a DMG recipe at https://github.com/chef-cookbooks/dmg but that only installs .dmg files, not .pkg files, though the page says:

“Optionally, the LWRP can install an “mpkg” or “pkg” package using installer(8).” But it isn’t clear how to do that.

yo,

See the documentation examples for Silverlight or Virtualbox in the readme.

The same resource and install action that handles a dmg can handle the pkg or mpkg, see here:

https://github.com/chef-cookbooks/dmg/blob/master/providers/package.rb#L72

Set the appropriate type attribute for the resource to get your desired behavior:

cheers

OK, so here is my recipe in its entirety:

include_recipe 'dmg'

dmg_package "R" do
  source 'https://cran.r-project.org/bin/macosx/R-3.3.0.pkg'
  type 'pkg'
end

Here’s the error from running it in test kitchen. It looks from the error that it is treating the pkg file as a dmg and trying to attach it. I just want to run ‘installer’ on it.

            ================================================================================
             Error executing action `run` on resource 'ruby_block[attach /tmp/kitchen/cache/R.dmg]'
             ================================================================================

             Mixlib::ShellOut::ShellCommandFailed
             ------------------------------------
             Expected process to exit with [0], but received '1'
             ---- Begin output of  hdiutil attach  '/tmp/kitchen/cache/R.dmg' -quiet ----
             STDOUT:
             STDERR:
             ---- End output of  hdiutil attach  '/tmp/kitchen/cache/R.dmg' -quiet ----
             Ran  hdiutil attach  '/tmp/kitchen/cache/R.dmg' -quiet returned 1

             Cookbook Trace:
             ---------------
             /tmp/kitchen/cache/cookbooks/dmg/providers/package.rb:57:in `block (3 levels) in class_from_file'

             Resource Declaration:
             ---------------------
             # In /tmp/kitchen/cache/cookbooks/dmg/providers/package.rb

       51:     ruby_block "attach #{dmg_file}" do
       52:       block do
       53:         cmd = shell_out("hdiutil imageinfo #{passphrase_cmd} '#{dmg_file}' | grep -q 'Software License Agreement: true'")
       54:         software_license_agreement = (cmd.exitstatus == 0)
       55:         raise "Requires EULA Acceptance; add 'accept_eula true' to package resource" if software_license_agreement && !new_resource.accept_eula
       56:         accept_eula_cmd = new_resource.accept_eula ? 'echo Y | PAGER=true' : ''
       57:         shell_out!("#{accept_eula_cmd} hdiutil attach #{passphrase_cmd} '#{dmg_file}' -quiet")
       58:       end
       59:       not_if "hdiutil info #{passphrase_cmd} | grep -q 'image-path.*#{dmg_file}'"
       60:     end
       61:

             Compiled Resource:
             ------------------
             # Declared in /tmp/kitchen/cache/cookbooks/dmg/providers/package.rb:51:in `block in class_from_file'

             ruby_block("attach /tmp/kitchen/cache/R.dmg") do
        action [:run]
        retries 0
        retry_delay 2
        default_guard_interpreter :default
        block_name "attach /tmp/kitchen/cache/R.dmg"
        declared_type :ruby_block
        cookbook_name "BBS-provision-cookbook-mac"
        block #<Proc:0x007f8d257692b0@/tmp/kitchen/cache/cookbooks/dmg/providers/package.rb:52>
        not_if "hdiutil info  | grep -q 'image-path.*/tmp/kitchen/cache/R.dmg'"
             end

             Platform:
             ---------
             x86_64-darwin13.0


           ================================================================================
           Error executing action `install` on resource 'dmg_package[R]'
           ================================================================================

           Mixlib::ShellOut::ShellCommandFailed
           ------------------------------------
           ruby_block[attach /tmp/kitchen/cache/R.dmg] (/tmp/kitchen/cache/cookbooks/dmg/providers/package.rb line 51) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
           ---- Begin output of  hdiutil attach  '/tmp/kitchen/cache/R.dmg' -quiet ----
           STDOUT:
           STDERR:
           ---- End output of  hdiutil attach  '/tmp/kitchen/cache/R.dmg' -quiet ----
           Ran  hdiutil attach  '/tmp/kitchen/cache/R.dmg' -quiet returned 1

           Cookbook Trace:
           ---------------
           /tmp/kitchen/cache/cookbooks/dmg/providers/package.rb:57:in `block (3 levels) in class_from_file'

           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cache/cookbooks/BBS-provision-cookbook-mac/recipes/default.rb

             3: dmg_package "R" do
             4:   source 'https://cran.r-project.org/bin/macosx/R-3.3.0.pkg'
             5:   type 'pkg'
             6: end
             7:

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/BBS-provision-cookbook-mac/recipes/default.rb:3:in `from_file'

           dmg_package("R") do
             action :install
             updated true
             updated_by_last_action true
             retries 0
             retry_delay 2
             default_guard_interpreter :default
             declared_type :dmg_package
             cookbook_name "BBS-provision-cookbook-mac"
             recipe_name "default"
             source "https://cran.r-project.org/bin/macosx/R-3.3.0.pkg"
             type "pkg"
             app "R"
             destination "/Applications"
           end

           Platform:
           ---------
           x86_64-darwin13.0

I think the message in the DMG cookbook’s README is confusing in that it refers to the fact that it knows how to install .pkg files off a .dmg, not .pkg's directly.

I use the equivalent of:

  execute "install-#{pkgdata['name']}" do
    command "installer -pkg #{Chef::Config[:file_cache_path]}/#{pkgdata['name']}.pkg -target /"
    action :run
    not_if "pkgutil --pkgs=#{pkgdata['package_id']}"
  end

to do this.

Thanks. This seems like such a basic thing to do that I would have thought there was a recipe or LWRP to do it, or a provider for the package resource. Would love to be able to just say:

package 'foo.pkg'

Hey @dtenenba,
you should check out our repo. I have a remote_pkg lwrp. I am working on a core resource as well.
https://github.com/facebook/IT-CPE/tree/master/chef/cookbooks/remote_pkg