TheKevJames / puppet-homebrew

homebrew (+brewcask! +taps!) package installer and provider
https://forge.puppet.com/thekevjames/homebrew
Apache License 2.0
18 stars 44 forks source link

Non root and bundler #83

Closed genebean closed 7 years ago

genebean commented 7 years ago

This PR makes it so the provider still works when you are running puppet as a non-root user and when it is being run by way of Bundler. For me this also fixes #78.

Adding the same code to all 4 providers seemed a little odd but I didn't fully read up on #77 either. It would make sense to me to put chunks of code like

  def self.execute(cmd, failonfail = false, combine = false)
    owner = stat('-nf', '%Uu', '/usr/local/bin/brew').to_i
    group = stat('-nf', '%Ug', '/usr/local/bin/brew').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 /usr/local/bin/brew'
    end

    # the uid and gid can only be set if running as root
    if Process.uid == 0
      uid = owner
      gid = group
    else
      uid = nil
      gid = nil
    end

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

into lib/puppet/util/homebrew.rb or similar to make things a little more DRY. If that's desired then I will happily rework this a bit.

GitCop commented 7 years ago

There were the following issues with your Pull Request

Guidelines are available at https://github.com/thekevjames/puppet-homebrew


This message was auto-generated by https://gitcop.com

genebean commented 7 years ago

Not totally sure what you are looking for in the commit message... happy to adjust if you will elaborate.

genebean commented 7 years ago

It looks like the only tests that failed were for ruby 2.2.5 due to Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

genebean commented 7 years ago

@TheKevJames - what do I need to do to get this merged in?

TheKevJames commented 7 years ago

Hey! Sorry I haven't had a chance to look at this yet; I'm on vacation, but I'll try to find the time to check this out shortly.

genebean commented 7 years ago

Thanks!

genebean commented 7 years ago

@TheKevJames Just wanted to follow up with you and see if you have had a chance to take a look.

TheKevJames commented 7 years ago

Hey there! I'm so sorry it took me so long to get to this -- my vacation ended up going a lot longer than expected. This looks good to me, I'll get it merged and deployed right away. Thanks for the contribution!

genebean commented 7 years ago

Thanks!