module Chef::Mixin::HomebrewUser
Public Instance Methods
find_homebrew_uid(provided_user = nil)
click to toggle source
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
# 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)
click to toggle source
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
# 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)
click to toggle source
# 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
Private Instance Methods
calculate_owner()
click to toggle source
# File lib/chef/mixin/homebrew_user.rb, line 74 def calculate_owner brew_path = homebrew_bin_path if brew_path # By default, this follows symlinks which is what we want owner = ::File.stat(brew_path).uid else raise Chef::Exceptions::CannotDetermineHomebrewOwner, 'Couldn\'t find the "brew" executable anywhere on the path.' end Chef::Log.debug "Found Homebrew owner #{Etc.getpwuid(owner).name}; executing `brew` commands as them" owner end