Module: Chef::Mixin::HomebrewUser

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

Instance Method Summary collapse

Methods included from ShellOut

apply_default_env, maybe_add_timeout, #shell_out, #shell_out!

Methods included from PathSanity

#enforce_path_sanity, #sanitized_path

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