From 5f86a60e29ba06896d37cc4936743c652fefeb06 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 13 Oct 2015 20:53:54 +0100 Subject: brew: check xcode license status The xcrun code is stolen right out of the INSTALL script. 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. Closes Homebrew/homebrew#44974. Signed-off-by: Dominyk Tiller --- Library/brew.rb | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/Library/brew.rb b/Library/brew.rb index 886b07910..e0e9673a9 100755 --- a/Library/brew.rb +++ b/Library/brew.rb @@ -25,18 +25,30 @@ elsif ARGV.first == "-v" exit 0 if ARGV.length == 1 end -# Check for bad xcode-select before anything else, because `doctor` and -# many other things will hang -# Note that this bug was fixed in 10.9 -if OS.mac? && 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 +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 @@ -45,7 +57,7 @@ when "/", "/usr" abort "Cowardly refusing to continue at this prefix: #{HOMEBREW_PREFIX}" end -if OS.mac? and MacOS.version < "10.6" +if OS.mac? && MacOS.version < "10.6" abort <<-EOABORT.undent Homebrew requires Snow Leopard or higher. For Tiger and Leopard support, see: https://github.com/mistydemeo/tigerbrew @@ -88,7 +100,7 @@ begin sudo_check = %w[ install link pin unpin upgrade ] if sudo_check.include? cmd - if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? + 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. -- cgit v1.2.3