2018-07-16 22:46:02 +02:00
|
|
|
require "vendor/plist/plist"
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-09-03 19:39:07 +01:00
|
|
|
require "cask/artifact/abstract_artifact"
|
2016-10-04 15:24:58 +02:00
|
|
|
|
2018-07-16 22:46:02 +02:00
|
|
|
require "extend/hash_validator"
|
|
|
|
using HashValidator
|
2016-11-10 11:56:00 +09:00
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
module Cask
|
2016-09-24 13:52:43 +02:00
|
|
|
module Artifact
|
2017-04-06 00:33:31 +02:00
|
|
|
class Pkg < AbstractArtifact
|
2016-09-24 13:52:43 +02:00
|
|
|
attr_reader :pkg_relative_path
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-10-02 00:26:58 +02:00
|
|
|
def self.from_args(cask, path, **stanza_options)
|
2018-07-16 22:46:02 +02:00
|
|
|
stanza_options.assert_valid_keys!(:allow_untrusted, :choices)
|
2017-10-02 00:26:58 +02:00
|
|
|
new(cask, path, **stanza_options)
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-10-02 00:26:58 +02:00
|
|
|
attr_reader :path, :stanza_options
|
2017-04-06 00:33:31 +02:00
|
|
|
|
2017-10-02 00:26:58 +02:00
|
|
|
def initialize(cask, path, **stanza_options)
|
2017-04-06 00:33:31 +02:00
|
|
|
super(cask)
|
|
|
|
@path = cask.staged_path.join(path)
|
2017-10-02 00:26:58 +02:00
|
|
|
@stanza_options = stanza_options
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2017-04-06 00:33:31 +02:00
|
|
|
def summarize
|
|
|
|
path.relative_path_from(cask.staged_path).to_s
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-04-06 00:33:31 +02:00
|
|
|
def install_phase(**options)
|
|
|
|
run_installer(**options)
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-04-06 00:33:31 +02:00
|
|
|
private
|
|
|
|
|
2017-10-02 00:26:58 +02:00
|
|
|
def run_installer(command: nil, verbose: false, **_options)
|
2017-04-06 00:33:31 +02:00
|
|
|
ohai "Running installer for #{cask}; your password may be necessary."
|
2016-09-24 13:52:43 +02:00
|
|
|
ohai "Package installers may write to any location; options such as --appdir are ignored."
|
2017-04-06 00:33:31 +02:00
|
|
|
unless path.exist?
|
|
|
|
raise CaskError, "pkg source file not found: '#{path.relative_path_from(cask.staged_path)}'"
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
args = [
|
2017-04-06 00:33:31 +02:00
|
|
|
"-pkg", path,
|
2016-10-14 20:33:16 +02:00
|
|
|
"-target", "/"
|
|
|
|
]
|
2017-04-06 00:33:31 +02:00
|
|
|
args << "-verboseR" if verbose
|
2017-10-02 00:26:58 +02:00
|
|
|
if stanza_options.fetch(:allow_untrusted, false)
|
|
|
|
args << "-allowUntrusted"
|
|
|
|
end
|
2016-11-21 04:13:29 +09:00
|
|
|
with_choices_file do |choices_path|
|
2016-11-20 14:09:16 +09:00
|
|
|
args << "-applyChoiceChangesXML" << choices_path if choices_path
|
2018-06-01 23:26:12 +02:00
|
|
|
logged_in_user = Utils.current_user
|
|
|
|
env = {
|
|
|
|
"LOGNAME" => logged_in_user,
|
|
|
|
"USER" => logged_in_user,
|
|
|
|
"USERNAME" => logged_in_user,
|
|
|
|
}
|
|
|
|
command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true, env: env)
|
2016-11-10 11:56:00 +09:00
|
|
|
end
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-11-10 11:56:00 +09:00
|
|
|
|
2016-11-21 04:13:29 +09:00
|
|
|
def with_choices_file
|
2017-10-02 00:26:58 +02:00
|
|
|
choices = stanza_options.fetch(:choices, {})
|
2017-04-06 00:33:31 +02:00
|
|
|
return yield nil if choices.empty?
|
2016-11-20 14:09:16 +09:00
|
|
|
|
2016-11-21 04:13:29 +09:00
|
|
|
Tempfile.open(["choices", ".xml"]) do |file|
|
|
|
|
begin
|
2017-04-06 00:33:31 +02:00
|
|
|
file.write Plist::Emit.dump(choices)
|
2016-11-21 04:13:29 +09:00
|
|
|
file.close
|
|
|
|
yield file.path
|
|
|
|
ensure
|
|
|
|
file.unlink
|
|
|
|
end
|
2016-11-20 14:09:16 +09:00
|
|
|
end
|
2016-11-10 11:56:00 +09:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|