From 45b84df1bdcbdcd75022e024d1cf400f1c73fdaa Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 10 Aug 2012 09:33:33 -0400 Subject: [PATCH] Be more verbose when users insist on being sudoers If you google for "Cowardly refusing to sudo brew" you get a lot of confused users who didn't read any of the Homebrew documentation and then had a hissy-fit. --- Library/Homebrew/cmd/install.rb | 6 ++---- Library/Homebrew/cmd/link.rb | 4 +--- Library/Homebrew/exceptions.rb | 8 ++++++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index aa7987048e..319b277fd9 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -2,7 +2,7 @@ require 'formula_installer' require 'hardware' require 'blacklist' -module Homebrew extend self +module Homebrew extend self def install raise FormulaUnspecifiedError if ARGV.named.empty? @@ -15,9 +15,7 @@ module Homebrew extend self end unless ARGV.force? 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 install'" + raise "Cowardly refusing to `sudo brew install'\n#{SUDO_BAD_ERRMSG}" end install_formulae ARGV.formulae diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index 2595af3b87..8e942cd916 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -4,9 +4,7 @@ module Homebrew extend self raise KegUnspecifiedError if ARGV.named.empty? 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 link'" + raise "Cowardly refusing to `sudo brew link'\n#{SUDO_BAD_ERRMSG}" end if ARGV.force? then mode = :force diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 9ed6646f1f..5dd2209b20 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -179,3 +179,11 @@ 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