module Chef::Mixin::Homebrew
Public Instance Methods
Source
# 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
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. @param [String, Integer] provided_user @return [Integer] UID of the user
Source
# 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
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 @param [String, Integer] provided_user @return [String] username
Source
# 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
Use homebrew_bin_path
to return the path to the brew binary @param [String, Array(String
)] brew_bin_path @return [String] path to the brew binary
Private Instance Methods
Source
# File lib/chef/mixin/homebrew.rb, line 78 def calculate_owner brew_path = homebrew_bin_path # By default, this follows symlinks which is what we want owner_uid = ::File.stat(brew_path).uid Chef::Log.debug "Found Homebrew owner #{Etc.getpwuid(owner_uid).name}; executing `brew` commands as them" owner_uid end