Class: Cask::Artifact::Pkg Private

Inherits:
AbstractArtifact show all
Defined in:
cask/artifact/pkg.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Artifact corresponding to the pkg stanza.

Constant Summary

Constants inherited from AbstractArtifact

AbstractArtifact::DirectivesType

Instance Attribute Summary collapse

Attributes inherited from AbstractArtifact

#cask

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractArtifact

#cask_sandbox, #config, dirmethod, dsl_key, english_article, english_name, read_script_arguments, #run_cask_sandbox, #sort_order, #staged_path_join_executable, #to_args

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

#initialize(cask, path, **stanza_options) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:



39
40
41
42
43
# File 'cask/artifact/pkg.rb', line 39

def initialize(cask, path, **stanza_options)
  super
  @path = T.let(cask.staged_path.join(path), Pathname)
  @stanza_options = stanza_options
end

Instance Attribute Details

#path ⇒ Pathname (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



19
20
21
# File 'cask/artifact/pkg.rb', line 19

def path
  @path
end

#stanza_options ⇒ Hash{Symbol => DirectivesType} (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



22
23
24
# File 'cask/artifact/pkg.rb', line 22

def stanza_options
  @stanza_options
end

Class Method Details

.from_args(cask, path, **stanza_options) ⇒ T.attached_class

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

The stanza options are validated below rather than typed as keywords so that an unknown key names itself in the error.

Parameters:

Returns:

  • (T.attached_class)


30
31
32
33
34
35
36
# File 'cask/artifact/pkg.rb', line 30

def self.from_args(cask, path, **stanza_options)
  if stanza_options.key?(:allow_untrusted)
    odeprecated "`allow_untrusted` in the `pkg` stanza", "a trusted package"
  end
  ::Utils::Data.assert_valid_keys(stanza_options, :allow_untrusted, :choices)
  new(cask, path, **stanza_options)
end

Instance Method Details

#install_phase(adopt: false, auto_updates: false, force: false, verbose: false, predecessor: nil, command: SystemCommand) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • adopt (Boolean) (defaults to: false)
  • auto_updates (Boolean, nil) (defaults to: false)
  • force (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • predecessor (Cask, nil) (defaults to: nil)
  • command (T.class_of(SystemCommand)) (defaults to: SystemCommand)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'cask/artifact/pkg.rb', line 60

def install_phase(adopt: false, auto_updates: false, force: false, verbose: false, predecessor: nil,
                  command: SystemCommand)
  ohai "Running installer for #{cask} with `sudo` (which may request your password)..."
  unless path.exist?
    pkg = path.relative_path_from(cask.staged_path)
    pkgs = Pathname.glob(cask.staged_path/"**"/"*.pkg").map { |path| path.relative_path_from(cask.staged_path) }

    message = "Could not find PKG source file '#{pkg}'"
    if pkgs.any?
      found_packages = ::Utils::Text.to_sentence(pkgs.map { |path| "'#{path}'" })
      message += ", found #{found_packages} instead"
    end
    message += "."

    raise CaskError, message
  end

  args = [
    "-pkg",    path,
    "-target", "/"
  ]
  args << "-verboseR" if verbose
  args << "-allowUntrusted" if stanza_options[:allow_untrusted]
  with_choices_file do |choices_path|
    args << "-applyChoiceChangesXML" << choices_path if choices_path

    current_user_str = User.current&.to_s
    env = {
      "LOGNAME"  => current_user_str,
      "USER"     => current_user_str,
      "USERNAME" => current_user_str,
    }

    command.run!(
      "/usr/sbin/installer",
      sudo:         true,
      sudo_as_root: true,
      args:,
      print_stdout: true,
      env:,
    )
  end
end

#requires_sudo? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


16
# File 'cask/artifact/pkg.rb', line 16

def requires_sudo? = true

#summarize ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



46
47
48
# File 'cask/artifact/pkg.rb', line 46

def summarize
  path.relative_path_from(cask.staged_path).to_s
end