add :allow_untrusted modifier on install

This commit is contained in:
Roland Walker 2014-02-03 09:49:45 -05:00
parent 45bc4a152d
commit 45ed67c64f
4 changed files with 47 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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
]

View File

@ -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