2016-08-18 22:11:42 +03:00
|
|
|
require "hbc/artifact/base"
|
|
|
|
|
2016-10-04 15:24:58 +02:00
|
|
|
require "hbc/utils/hash_validator"
|
|
|
|
|
2017-05-07 17:28:39 +01:00
|
|
|
require "vendor/plist/plist"
|
2016-11-10 11:56:00 +09:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
module Artifact
|
|
|
|
class Pkg < Base
|
|
|
|
attr_reader :pkg_relative_path
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.artifact_dsl_key
|
|
|
|
:pkg
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def load_pkg_description(pkg_description)
|
|
|
|
@pkg_relative_path = pkg_description.shift
|
|
|
|
@pkg_install_opts = pkg_description.shift
|
|
|
|
begin
|
|
|
|
if @pkg_install_opts.respond_to?(:keys)
|
2016-11-10 11:56:00 +09:00
|
|
|
@pkg_install_opts.extend(HashValidator).assert_valid_keys(:allow_untrusted, :choices)
|
2016-09-24 13:52:43 +02:00
|
|
|
elsif @pkg_install_opts
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
raise if pkg_description.nil?
|
|
|
|
rescue StandardError
|
|
|
|
raise CaskInvalidError.new(@cask, "Bad pkg stanza")
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def pkg_install_opts(opt)
|
|
|
|
@pkg_install_opts[opt] if @pkg_install_opts.respond_to?(:keys)
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def install_phase
|
|
|
|
@cask.artifacts[:pkg].each { |pkg_description| run_installer(pkg_description) }
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def run_installer(pkg_description)
|
|
|
|
load_pkg_description pkg_description
|
|
|
|
ohai "Running installer for #{@cask}; your password may be necessary."
|
|
|
|
ohai "Package installers may write to any location; options such as --appdir are ignored."
|
|
|
|
source = @cask.staged_path.join(pkg_relative_path)
|
|
|
|
unless source.exist?
|
|
|
|
raise CaskError, "pkg source file not found: '#{source}'"
|
|
|
|
end
|
|
|
|
args = [
|
2016-10-14 20:33:16 +02:00
|
|
|
"-pkg", source,
|
|
|
|
"-target", "/"
|
|
|
|
]
|
2017-05-21 00:15:56 +02:00
|
|
|
args << "-verboseR" if verbose?
|
2016-09-24 13:52:43 +02:00
|
|
|
args << "-allowUntrusted" if pkg_install_opts :allow_untrusted
|
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
|
|
|
|
@command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true)
|
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
|
|
|
|
return yield nil unless pkg_install_opts(:choices)
|
2016-11-20 14:09:16 +09:00
|
|
|
|
2016-11-21 04:13:29 +09:00
|
|
|
Tempfile.open(["choices", ".xml"]) do |file|
|
|
|
|
begin
|
|
|
|
file.write Plist::Emit.dump(pkg_install_opts(:choices))
|
|
|
|
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
|