Module: Chef::Mixin::HomebrewUser

Includes:
ShellOut
Included in:
Provider::Package::Homebrew, Resource::HomebrewCask, Resource::HomebrewTap, Resource::HomebrewUpdate
Defined in:
lib/chef/mixin/homebrew_user.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_user.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_user.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) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/chef/mixin/homebrew_user.rb', line 60

def homebrew_bin_path(brew_bin_path = nil)
  if brew_bin_path && ::File.exist?(brew_bin_path)
    brew_bin_path
  else
    [which("brew"), "/opt/homebrew/bin/brew", "/usr/local/bin/brew", "/home/linuxbrew/.linuxbrew/bin/brew"].uniq.select do |x|
      next if x == false

      ::File.exist?(x) && ::File.executable?(x)
    end.first || nil
  end
end