aboutsummaryrefslogtreecommitdiffstats
path: root/Library/brew.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Library/brew.rb')
-rwxr-xr-xLibrary/brew.rb32
1 files changed, 20 insertions, 12 deletions
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