diff --git a/Library/brew.rb b/Library/brew.rb index df83df120b..f8fa07f27b 100755 --- a/Library/brew.rb +++ b/Library/brew.rb @@ -4,11 +4,6 @@ std_trap = trap("INT") { exit! 130 } # no backtrace thanks HOMEBREW_BREW_FILE = ENV["HOMEBREW_BREW_FILE"] -if ARGV == %w[--prefix] - puts File.dirname(File.dirname(HOMEBREW_BREW_FILE)) - exit 0 -end - require "pathname" HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent.join("Homebrew") $:.unshift(HOMEBREW_LIBRARY_PATH.to_s) @@ -22,38 +17,6 @@ elsif ARGV.first == "-v" ARGV << ARGV.shift end -if OS.mac? - # Check for bad xcode-select before other checks, because `doctor` and - # many other things will hang. Note that this bug was fixed in 10.9 - if MacOS.version < :mavericks && MacOS.active_developer_dir == "/" - odie <<-EOS.undent - Your xcode-select path is currently set to '/'. - This causes the `xcrun` tool to hang, and can render Homebrew unusable. - If you are using Xcode, you should: - sudo xcode-select -switch /Applications/Xcode.app - Otherwise, you should: - sudo rm -rf /usr/share/xcode-select - EOS - end - - # Check for user agreement of the Xcode license before permitting - # any other brew usage to continue. This prevents the situation where - # people are instructed to "please re-run as root via sudo" on brew commands. - # The check can only fail when Xcode is installed & the active developer dir. - if MacOS::Xcode.installed? && `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success? - odie <<-EOS.undent - You have not agreed to the Xcode license. Please resolve this by running: - sudo xcodebuild -license - EOS - end -end - -case HOMEBREW_PREFIX.to_s -when "/", "/usr" - # it may work, but I only see pain this route and don't want to support it - abort "Cowardly refusing to continue at this prefix: #{HOMEBREW_PREFIX}" -end - if OS.mac? && MacOS.version < "10.6" abort <<-EOABORT.undent Homebrew requires Snow Leopard or higher. For Tiger and Leopard support, see: @@ -61,10 +24,6 @@ if OS.mac? && MacOS.version < "10.6" EOABORT end -# Many Pathname operations use getwd when they shouldn't, and then throw -# odd exceptions. Reduce our support burden by showing a user-friendly error. -Dir.getwd rescue abort "The current working directory doesn't exist, cannot proceed." - def require?(path) require path rescue LoadError => e @@ -94,20 +53,6 @@ begin cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd) - sudo_check = %w[ install reinstall postinstall link pin unpin - update upgrade create migrate tap switch ] - - if sudo_check.include? cmd - if Process.uid.zero? && !File.stat(HOMEBREW_BREW_FILE).uid.zero? - raise <<-EOS.undent - Cowardly refusing to `sudo brew #{cmd}` - 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 - end - # Add contributed commands to PATH before checking. Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/cmd"].each do |tap_cmd_dir| ENV["PATH"] += "#{File::PATH_SEPARATOR}#{tap_cmd_dir}" diff --git a/bin/brew b/bin/brew index 5a4aef5fbd..b0e38aba46 100755 --- a/bin/brew +++ b/bin/brew @@ -37,6 +37,19 @@ else HOMEBREW_CELLAR="$HOMEBREW_REPOSITORY/Cellar" fi +case "$*" in + --prefix) echo "$HOMEBREW_PREFIX"; exit 0 ;; + --cellar) echo "$HOMEBREW_CELLAR"; exit 0 ;; + --repository|--repo) echo "$HOMEBREW_REPOSITORY"; exit 0 ;; +esac + +if [ "$HOMEBREW_PREFIX" = "/" ] || [ "$HOMEBREW_PREFIX" = "/usr" ] +then + # it may work, but I only see pain this route and don't want to support it + echo "Cowardly refusing to continue at this prefix: $HOMEBREW_PREFIX" >&2 + exit 1 +fi + # Users may have these set, pointing the system Ruby # at non-system gem paths unset GEM_HOME @@ -47,9 +60,14 @@ then unset HOMEBREW_RUBY_PATH fi +if [ "$(uname -s)" = "Darwin" ] +then + HOMEBREW_OSX="1" +fi + if [ -z "$HOMEBREW_RUBY_PATH" ] then - if [ "$(uname -s)" = "Darwin" ] + if [ -n "$HOMEBREW_OSX" ] then HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" else @@ -64,6 +82,42 @@ export HOMEBREW_REPOSITORY export HOMEBREW_LIBRARY export HOMEBREW_CELLAR +if [ -n "$HOMEBREW_OSX" ] +then + if [ "$('xcode-select' --print-path)" = "/" ] + then + cat >&2 <&2 <&2 + exit 1 +fi + for i in "$@" do if [[ "$1" = -v ]] @@ -72,10 +126,26 @@ do set -- "$@" -v fi [[ "$i" =~ ^- ]] && continue + HOMEBREW_COMMAND="$i" HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/cmd/$i.sh" break done +if [ "$(id -u)" = "0" ] && [ "$(stat -f%u "$HOMEBREW_BREW_FILE")" != "0" ] +then + case "$HOMEBREW_COMMAND" in + install|reinstall|postinstall|link|pin|unpin|update|update-bash|upgrade|create|migrate|tap|switch) + cat >&2 <