diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b6db7fc68b..9b36649b2e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -83,7 +83,7 @@ Fill in the following fields for your Cask: | `sha256` | SHA-256 checksum of the file; checked when the file is downloaded to prevent any funny business (can be omitted with `no_checksum`) | __artifact info__ | information about artifacts inside the Cask (can be specified multiple times) | `link` | relative path to a file that should be linked into the `Applications` folder on installation (see __Link Details__ for more information) -| `install` | relative path to `pkg` that should be run to install the application +| `install` | relative path to `pkg` that should be run to install the application (see __Install Details__ for more information) | `uninstall` | indicates what commands/scripts must be run to uninstall a pkg-based application (see __Uninstall Details__ for more information) Additional fields you might need for special use-cases: @@ -242,6 +242,26 @@ link 'TexmakerMacosxLion/texmaker.app' Linking to the .app file without reference to the containing folder will result in installation failing with a "symlink source is not there" error. +### Install Details + +The first argument to `install` should be a relative path to the `pkg` file +to be installed. For example: + +```ruby +install 'Vagrant.pkg' +``` + +Subsequent arguments to `install` are key/value pairs which modify the +install process. Currently supported keys are + + * `:allow_untrusted` -- pass `-allowUntrusted` to `/usr/sbin/installer` + +Example: + +```ruby +install 'Soundflower.pkg', :allow_untrusted => true +``` + ### Uninstall Details A `pkg`-based Cask using `install` will **not** know how to uninstall diff --git a/lib/cask/artifact/pkg.rb b/lib/cask/artifact/pkg.rb index 69ec9f1b4df..0771f593b5c 100644 --- a/lib/cask/artifact/pkg.rb +++ b/lib/cask/artifact/pkg.rb @@ -31,21 +31,42 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base return executable, script_arguments end + def load_pkg_description(pkg_description) + @pkg_relative_path = pkg_description.shift + @pkg_install_opts = pkg_description.shift + if @pkg_install_opts.respond_to?(:keys) + @pkg_install_opts.assert_valid_keys( :allow_untrusted ) + elsif @pkg_install_opts + raise "Bad install stanza in Cask #{@cask}" + end + raise "Bad install stanza in Cask #{@cask}" if pkg_description.nil? + end + + def pkg_install_opts(opt) + @pkg_install_opts[opt] if @pkg_install_opts.respond_to?(:keys) + end + + def pkg_relative_path + @pkg_relative_path + end + def install - @cask.artifacts[:install].each { |pkg| run_installer(pkg) } + @cask.artifacts[:install].each { |pkg_description| run_installer(pkg_description) } end def uninstall @cask.artifacts[:uninstall].each { |opts| manually_uninstall(opts) } end - def run_installer(pkg_relative_path) + def run_installer(pkg_description) + load_pkg_description pkg_description ohai "Running installer for #{@cask}; your password may be necessary." args = [ '-pkg', @cask.destination_path.join(pkg_relative_path), '-target', '/' ] args << '-verboseR' if ARGV.verbose? + args << '-allowUntrusted' if pkg_install_opts :allow_untrusted @command.run!('/usr/sbin/installer', {:sudo => true, :args => args, :print => true}) end diff --git a/lib/cask/dsl.rb b/lib/cask/dsl.rb index 426413f188f..1d93a849a4b 100644 --- a/lib/cask/dsl.rb +++ b/lib/cask/dsl.rb @@ -75,7 +75,8 @@ module Cask::DSL :binary, :caskroom_only, :input_method, - :screen_saver + :screen_saver, + :install, ] ARTIFACT_TYPES.each do |type| @@ -85,7 +86,6 @@ module Cask::DSL end SPECIAL_ARTIFACT_TYPES = [ - :install, :nested_container, :uninstall ] diff --git a/test/cask/dsl_test.rb b/test/cask/dsl_test.rb index 4be0adcd843..7cb84d2ae08 100644 --- a/test/cask/dsl_test.rb +++ b/test/cask/dsl_test.rb @@ -90,7 +90,7 @@ describe Cask::DSL do end instance = CaskWithInstallables.new - Array(instance.artifacts[:install]).sort.must_equal %w[Bar.pkg Foo.pkg] + Array(instance.artifacts[:install]).sort.must_equal [['Bar.pkg'], ['Foo.pkg']] end it "prevents defining multiple urls" do