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 <dominyktiller@gmail.com>
This commit is contained in:
Dominyk Tiller 2015-10-13 20:53:54 +01:00
parent 21d804eeb8
commit 5f86a60e29

View File

@ -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.