Module: Chef::Mixin::Homebrew

Includes:
ShellOut
Included in:
Provider::Package::Homebrew, Resource::HomebrewCask, Resource::HomebrewTap, Resource::HomebrewUpdate
Defined in:
lib/chef/mixin/homebrew.rb

Instance Method Summary collapse

Instance Method Details

#find_homebrew_uid(provided_user = nil) ⇒ Integer

This tries to find the user to execute brew as. If a user is provided, that overrides the brew executable user. It is an error condition if the brew executable owner is root or we cannot find the brew executable.

Parameters:

  • provided_user (String, Integer) (defaults to: nil)

Returns:

  • (Integer)

    UID of the user



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chef/mixin/homebrew.rb', line 39

def find_homebrew_uid(provided_user = nil)
  # They could provide us a user name or a UID
  if provided_user
    return provided_user if provided_user.is_a? Integer

    return Etc.getpwnam(provided_user).uid
  end

  @homebrew_owner_uid ||= calculate_owner
  @homebrew_owner_uid
end

#find_homebrew_username(provided_user = nil) ⇒ String

Use find_homebrew_uid to return the UID and then lookup the name from that UID because sometimes you want the name not the UID

Parameters:

  • provided_user (String, Integer) (defaults to: nil)

Returns:



55
56
57
58
# File 'lib/chef/mixin/homebrew.rb', line 55

def find_homebrew_username(provided_user = nil)
  @homebrew_owner_username ||= Etc.getpwuid(find_homebrew_uid(provided_user)).name
  @homebrew_owner_username
end

#homebrew_bin_path(brew_bin_path = nil) ⇒ String

Use homebrew_bin_path to return the path to the brew binary

Parameters:

Returns:

  • (String)

    path to the brew binary



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/chef/mixin/homebrew.rb', line 63

def homebrew_bin_path(brew_bin_path = nil)
  if brew_bin_path && ::File.exist?(brew_bin_path)
    brew_bin_path
  else
    brew_path = which("brew", prepend_path: %w{/opt/homebrew/bin /usr/local/bin /home/linuxbrew/.linuxbrew/bin})
    unless brew_path
      raise Chef::Exceptions::CannotDetermineHomebrewPath,
        'Couldn\'t find the "brew" executable anywhere on the path.'
    end
    brew_path
  end
end