self.execute

in lib/puppet/provider/package/brew.rb [17:50]


  def self.execute(cmd, failonfail = false, combine = false)
    brew_cmd = command(:brew)
    owner = stat('-nf', '%Uu', brew_cmd).to_i
    group = stat('-nf', '%Ug', brew_cmd).to_i
    home  = Etc.getpwuid(owner).dir

    if owner == 0
      raise Puppet::ExecutionFailure, "Homebrew does not support installations owned by the \"root\" user. Please check the permissions of #{brew_cmd}"
    end

    
    if Process.uid == 0
      uid = owner
      gid = group
    else
      uid = nil
      gid = nil
    end

    custom_env = {'HOME' => home}
    custom_env['HOMEBREW_CHANGE_ARCH_TO_ARM'] = '1' if Facter.value(:has_arm64)
    cmd = ["arch", "-arm64"].append(cmd) if Facter.value(:has_arm64)

    if Puppet.features.bundled_environment?
      Bundler.with_clean_env do
        super(cmd, :uid => uid, :gid => gid, :combine => combine,
              :custom_environment => custom_env, :failonfail => failonfail)
      end
    else
      super(cmd, :uid => uid, :gid => gid, :combine => combine,
            :custom_environment => custom_env, :failonfail => failonfail)
    end
  end