diff options
| author | Adam Vandenberg | 2013-06-08 18:17:28 -0700 | 
|---|---|---|
| committer | Adam Vandenberg | 2013-06-08 20:44:56 -0700 | 
| commit | 4c9ac19e878750cf2c2832759d9902796079d9f0 (patch) | |
| tree | 0a510b5ddc495dfc6c265d0227849e4617cba41d | |
| parent | bae36f0830df37989b86ece36cc5282f32d7d087 (diff) | |
| download | brew-4c9ac19e878750cf2c2832759d9902796079d9f0.tar.bz2 | |
Consolidate sudo checks.
Closes Homebrew/homebrew#20318.
| -rw-r--r-- | Library/Homebrew/cmd/install.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/link.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/pin.rb | 3 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/unpin.rb | 3 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/upgrade.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/exceptions.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/global.rb | 6 | ||||
| -rwxr-xr-x | Library/brew.rb | 32 | 
8 files changed, 26 insertions, 40 deletions
| diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index c0aa1a2e9..cbeb433eb 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -18,10 +18,6 @@ module Homebrew extend self        end      end unless ARGV.force? -    if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? -      raise "Cowardly refusing to `sudo brew install'\n#{SUDO_BAD_ERRMSG}" -    end -      install_formulae ARGV.formulae    end diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index 0184febaf..67ce43478 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -5,10 +5,6 @@ module Homebrew extend self    def link      raise KegUnspecifiedError if ARGV.named.empty? -    if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? -      raise "Cowardly refusing to `sudo brew link'\n#{SUDO_BAD_ERRMSG}" -    end -      mode = OpenStruct.new      mode.overwrite = true if ARGV.include? '--overwrite' diff --git a/Library/Homebrew/cmd/pin.rb b/Library/Homebrew/cmd/pin.rb index 2c0d5d33d..b8c1d1e33 100644 --- a/Library/Homebrew/cmd/pin.rb +++ b/Library/Homebrew/cmd/pin.rb @@ -2,9 +2,6 @@ require 'formula'  module Homebrew extend self    def pin -    if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? -      abort "Cowardly refusing to `sudo pin'" -    end      raise FormulaUnspecifiedError if ARGV.named.empty?      ARGV.formulae.each do |f| diff --git a/Library/Homebrew/cmd/unpin.rb b/Library/Homebrew/cmd/unpin.rb index 265f7a941..4da280eef 100644 --- a/Library/Homebrew/cmd/unpin.rb +++ b/Library/Homebrew/cmd/unpin.rb @@ -2,9 +2,6 @@ require 'formula'  module Homebrew extend self    def unpin -    if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? -      abort "Cowardly refusing to `sudo unpin'" -    end      raise FormulaUnspecifiedError if ARGV.named.empty?      ARGV.formulae.each do |f| diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index fe41a1507..28882360b 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -8,12 +8,6 @@ end  module Homebrew extend self    def upgrade -    if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? -      # note we only abort if Homebrew is *not* installed as sudo and the user -      # calls brew as root. The fix is to chown brew to root. -      abort "Cowardly refusing to `sudo brew upgrade'" -    end -      Homebrew.perform_preinstall_checks      if ARGV.named.empty? diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index c91d917d0..9c812ce34 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -213,11 +213,3 @@ class ChecksumMismatchError < RuntimeError      super + advice.to_s    end  end - -module Homebrew extend self -  SUDO_BAD_ERRMSG = <<-EOS.undent -    You can use brew with sudo, but only if the brew executable is owned by root. -    However, this is both not recommended and completely unsupported so do so at -    your own risk. -  EOS -end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index cb6e36e07..f6e942bff 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -99,3 +99,9 @@ HOMEBREW_PULL_OR_COMMIT_URL_REGEX = 'https:\/\/github.com\/(\w+)\/homebrew(-\w+)  require 'compat' unless ARGV.include? "--no-compat" or ENV['HOMEBREW_NO_COMPAT']  ORIGINAL_PATHS = ENV['PATH'].split(':').map{ |p| Pathname.new(p).expand_path rescue nil }.compact.freeze + +SUDO_BAD_ERRMSG = <<-EOS.undent +  You can use brew with sudo, but only if the brew executable is owned by root. +  However, this is both not recommended and completely unsupported so do so at +  your own risk. +EOS diff --git a/Library/brew.rb b/Library/brew.rb index 92de2cbee..eb46e88a3 100755 --- a/Library/brew.rb +++ b/Library/brew.rb @@ -58,17 +58,17 @@ end  begin    trap("INT", std_trap) # restore default CTRL-C handler -  aliases = {'ls' => :list, -             'homepage' => :home, -             '-S' => :search, -             'up' => :update, -             'ln' => :link, -             'instal' => :install, # gem does the same -             'rm' => :uninstall, -             'remove' => :uninstall, -             'configure' => :diy, -             'abv' => :info, -             'dr' => :doctor, +  aliases = {'ls' => 'list', +             'homepage' => 'home', +             '-S' => 'search', +             'up' => 'update', +             'ln' => 'link', +             'instal' => 'install', # gem does the same +             'rm' => 'uninstall', +             'remove' => 'uninstall', +             'configure' => 'diy', +             'abv' => 'info', +             'dr' => 'doctor',               '--repo' => '--repository',               'environment' => '--env'  # same as gem               } @@ -76,11 +76,19 @@ begin    cmd = ARGV.shift    cmd = aliases[cmd] if aliases[cmd] -  if cmd == '-c1' +  if cmd == '-c1' # Shortcut for one line of configuration      cmd = '--config'      ARGV.unshift('-1')    end +  sudo_check = Set.new %w[ install link pin unpin upgrade ] + +  if sudo_check.include? cmd +    if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? +      raise "Cowardly refusing to `sudo brew #{cmd}`\n#{SUDO_BAD_ERRMSG}" +    end +  end +    # Add example external commands to PATH before checking.    ENV['PATH'] += ":#{HOMEBREW_REPOSITORY}/Library/Contributions/cmd"    if require? HOMEBREW_REPOSITORY/"Library/Homebrew/cmd"/cmd | 
