aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMike McQuaid2016-01-10 19:35:16 +0000
committerMike McQuaid2016-01-17 19:48:02 +0000
commit6f91b429ceee780088b659e519e19262bcfd48cf (patch)
treeb069d347bd4c45cda0160fabfeed39ff7e64e8db /bin
parentb01ce411641c64d36688a58999c3644ab0daf4a7 (diff)
downloadbrew-6f91b429ceee780088b659e519e19262bcfd48cf.tar.bz2
Move some brew.rb logic to bin/brew.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/brew72
1 files changed, 71 insertions, 1 deletions
diff --git a/bin/brew b/bin/brew
index 5a4aef5fb..b0e38aba4 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 <<EOS
+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
+ exit 1
+ fi
+
+ XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)"
+ XCRUN_STATUS="$?"
+
+ if [ "$XCRUN_STATUS" -ne 0 ] && [[ "$XCRUN_OUTPUT" = *license* ]]
+ then
+ cat >&2 <<EOS
+You have not agreed to the Xcode license. Please resolve this by running:
+ sudo xcodebuild -license
+EOS
+ exit 1
+ fi
+fi
+
+# Many Pathname operations use getwd when they shouldn't, and then throw
+# odd exceptions. Reduce our support burden by showing a user-friendly error.
+if ! [ -d "$(pwd)" ]
+then
+ echo "The current working directory doesn't exist, cannot proceed." >&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 <<EOS
+Cowardly refusing to 'sudo brew $HOMEBREW_COMMAND'
+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
+ exit 1
+ ;;
+ esac
+fi
+
if [ -n "$HOMEBREW_BASH_COMMAND" ] && [ -x "$HOMEBREW_BASH_COMMAND" ]
then
# source rather than executing directly to ensure the entire file is read into