
installer command accepts -applyChoiceChangesXML option to change customize options on the GUI installer from the commandline. (`man installer` for more detailed information) The introduced option `choice` enables the choice changes to be supplied via pkg stanza without tricks in preflight code.
75 lines
2.2 KiB
Ruby
75 lines
2.2 KiB
Ruby
require "hbc/artifact/base"
|
|
|
|
require "hbc/utils/hash_validator"
|
|
|
|
require "vendor/plist/plist"
|
|
|
|
module Hbc
|
|
module Artifact
|
|
class Pkg < Base
|
|
attr_reader :pkg_relative_path
|
|
|
|
def self.artifact_dsl_key
|
|
:pkg
|
|
end
|
|
|
|
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)
|
|
@pkg_install_opts.extend(HashValidator).assert_valid_keys(:allow_untrusted, :choices)
|
|
elsif @pkg_install_opts
|
|
raise
|
|
end
|
|
raise if pkg_description.nil?
|
|
rescue StandardError
|
|
raise CaskInvalidError.new(@cask, "Bad pkg stanza")
|
|
end
|
|
end
|
|
|
|
def pkg_install_opts(opt)
|
|
@pkg_install_opts[opt] if @pkg_install_opts.respond_to?(:keys)
|
|
end
|
|
|
|
def install_phase
|
|
@cask.artifacts[:pkg].each { |pkg_description| run_installer(pkg_description) }
|
|
end
|
|
|
|
def uninstall_phase
|
|
# Do nothing. Must be handled explicitly by a separate :uninstall stanza.
|
|
end
|
|
|
|
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 = [
|
|
"-pkg", source,
|
|
"-target", "/"
|
|
]
|
|
args << "-verboseR" if Hbc.verbose
|
|
args << "-allowUntrusted" if pkg_install_opts :allow_untrusted
|
|
if pkg_install_opts :choices
|
|
args << "-applyChoiceChangesXML"
|
|
args << choices_xml
|
|
end
|
|
@command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true)
|
|
end
|
|
|
|
def choices_xml
|
|
path = @cask.staged_path.join("Choices.xml")
|
|
unless File.exist? path
|
|
choices = pkg_install_opts :choices
|
|
IO.write path, Plist::Emit.dump(choices)
|
|
end
|
|
path
|
|
end
|
|
end
|
|
end
|
|
end
|