| 
									
										
										
										
											2014-06-03 10:14:58 -05:00
										 |  |  | #!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0 | 
					
						
							| 
									
										
										
										
											2013-03-02 17:42:21 -06:00
										 |  |  | # encoding: UTF-8 | 
					
						
							| 
									
										
										
										
											2009-10-02 16:57:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-22 15:50:27 -04:00
										 |  |  | std_trap = trap("INT") { exit! 130 } # no backtrace thanks | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-08 08:55:42 -08:00
										 |  |  | HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] | 
					
						
							| 
									
										
											  
											
												Rewrite of HOMEBREW_ folder locations
This rewrite attempts to sort out where the Prefix, Cellar, and
Repository are relative to the real and symlinked 'brew' command.
Also included is a --config option which dumps all of these variables.
Any top-level script must define a "BREW_FILE" that gives the path
to brew as it exists in the path. 'brew' itself just uses __FILE__ and
install.rb does a `which brew` (there may be a better way?)
The Prefix is always relative to the location of brew as it exists in
the path. Thus, whether or not /usr/local/bin/brew is a symlink or real
file, the Prefix is always /usr/local. If you have brew in some other
prefix, such as /nonstandard/bin/brew, then '/nonstandard/ will be
managed by brew instead.
The Repository, Cellar, and "Library/Homebrew" required code is always
found relative to the "real" path or brew. If brew is a real file in
/usr/local/bin/brew, then everything else will be found in /usr/local
and we'll expect a /usr/local/.git
Otherwise, we dereference brew's symlink and look for everything else
relative to that path instead.
											
										 
											2009-10-05 11:52:05 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-28 09:52:13 -04:00
										 |  |  | if ARGV == %w{--prefix} | 
					
						
							|  |  |  |   puts File.dirname(File.dirname(HOMEBREW_BREW_FILE)) | 
					
						
							|  |  |  |   exit 0
 | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-07 18:10:30 +00:00
										 |  |  | require 'pathname' | 
					
						
							| 
									
										
										
										
											2014-05-02 12:59:38 -05:00
										 |  |  | HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.dirname.parent.join("Library", "Homebrew") | 
					
						
							|  |  |  | $:.unshift(HOMEBREW_LIBRARY_PATH.to_s) | 
					
						
							| 
									
										
										
										
											2009-09-04 15:28:18 +01:00
										 |  |  | require 'global' | 
					
						
							| 
									
										
										
										
											2009-08-10 16:48:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  | if ARGV.first == '--version' | 
					
						
							| 
									
										
										
										
											2009-10-15 14:54:11 +01:00
										 |  |  |   puts HOMEBREW_VERSION | 
					
						
							|  |  |  |   exit 0
 | 
					
						
							| 
									
										
										
										
											2014-02-13 20:26:29 +00:00
										 |  |  | elsif ARGV.first == '-v' | 
					
						
							| 
									
										
										
										
											2012-07-23 14:27:50 -07:00
										 |  |  |   puts "Homebrew #{HOMEBREW_VERSION}" | 
					
						
							|  |  |  |   # Shift the -v to the end of the parameter list | 
					
						
							|  |  |  |   ARGV << ARGV.shift | 
					
						
							|  |  |  |   # If no other arguments, just quit here. | 
					
						
							|  |  |  |   exit 0 if ARGV.length == 1
 | 
					
						
							| 
									
										
										
										
											2009-10-15 14:54:11 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-13 10:46:30 -08:00
										 |  |  | # 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 | 
					
						
							| 
									
										
										
										
											2014-05-01 18:36:46 -05:00
										 |  |  | if OS.mac? && MacOS.version < :mavericks && MacOS.active_developer_dir == "/" | 
					
						
							| 
									
										
										
										
											2014-04-01 18:40:20 -05:00
										 |  |  |   odie <<-EOS.undent
 | 
					
						
							| 
									
										
										
										
											2013-12-13 10:46:30 -08:00
										 |  |  |   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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-15 14:54:11 +01:00
										 |  |  | 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}" | 
					
						
							| 
									
										
										
										
											2009-06-02 13:39:39 +01:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2013-10-22 20:47:37 -05:00
										 |  |  | if OS.mac? and MacOS.version < "10.5" | 
					
						
							| 
									
										
										
										
											2010-11-09 13:00:33 +00:00
										 |  |  |   abort <<-EOABORT.undent
 | 
					
						
							|  |  |  |     Homebrew requires Leopard or higher. For Tiger support, see: | 
					
						
							| 
									
										
										
										
											2012-12-27 21:54:54 -04:00
										 |  |  |     https://github.com/mistydemeo/tigerbrew | 
					
						
							| 
									
										
										
										
											2010-11-09 13:00:33 +00:00
										 |  |  |   EOABORT | 
					
						
							| 
									
										
										
										
											2009-08-12 01:56:40 +01:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2009-09-18 19:16:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-13 13:42:32 +00:00
										 |  |  | # 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." | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | def require? path | 
					
						
							| 
									
										
										
										
											2014-05-02 12:59:38 -05:00
										 |  |  |   require path | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | rescue LoadError => e | 
					
						
							|  |  |  |   # HACK :( because we should raise on syntax errors but | 
					
						
							|  |  |  |   # not if the file doesn't exist. TODO make robust! | 
					
						
							|  |  |  |   raise unless e.to_s.include? path | 
					
						
							| 
									
										
											  
											
												Rewrite of HOMEBREW_ folder locations
This rewrite attempts to sort out where the Prefix, Cellar, and
Repository are relative to the real and symlinked 'brew' command.
Also included is a --config option which dumps all of these variables.
Any top-level script must define a "BREW_FILE" that gives the path
to brew as it exists in the path. 'brew' itself just uses __FILE__ and
install.rb does a `which brew` (there may be a better way?)
The Prefix is always relative to the location of brew as it exists in
the path. Thus, whether or not /usr/local/bin/brew is a symlink or real
file, the Prefix is always /usr/local. If you have brew in some other
prefix, such as /nonstandard/bin/brew, then '/nonstandard/ will be
managed by brew instead.
The Repository, Cellar, and "Library/Homebrew" required code is always
found relative to the "real" path or brew. If brew is a real file in
/usr/local/bin/brew, then everything else will be found in /usr/local
and we'll expect a /usr/local/.git
Otherwise, we dereference brew's symlink and look for everything else
relative to that path instead.
											
										 
											2009-10-05 11:52:05 -07:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-02 13:39:39 +01:00
										 |  |  | begin | 
					
						
							| 
									
										
										
										
											2012-08-22 15:50:27 -04:00
										 |  |  |   trap("INT", std_trap) # restore default CTRL-C handler | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-08 18:17:28 -07:00
										 |  |  |   aliases = {'ls' => 'list', | 
					
						
							|  |  |  |              'homepage' => 'home', | 
					
						
							|  |  |  |              '-S' => 'search', | 
					
						
							|  |  |  |              'up' => 'update', | 
					
						
							|  |  |  |              'ln' => 'link', | 
					
						
							|  |  |  |              'instal' => 'install', # gem does the same | 
					
						
							|  |  |  |              'rm' => 'uninstall', | 
					
						
							|  |  |  |              'remove' => 'uninstall', | 
					
						
							|  |  |  |              'configure' => 'diy', | 
					
						
							|  |  |  |              'abv' => 'info', | 
					
						
							|  |  |  |              'dr' => 'doctor', | 
					
						
							| 
									
										
										
										
											2011-03-13 12:53:07 +00:00
										 |  |  |              '--repo' => '--repository', | 
					
						
							| 
									
										
										
										
											2013-11-01 19:04:04 -05:00
										 |  |  |              'environment' => '--env', | 
					
						
							| 
									
										
										
										
											2014-04-26 23:31:39 -07:00
										 |  |  |              '--config' => 'config', | 
					
						
							| 
									
										
										
										
											2011-03-13 12:53:07 +00:00
										 |  |  |              } | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  |   empty_argv = ARGV.empty? | 
					
						
							|  |  |  |   help_regex = /(-h$|--help$|--usage$|-\?$|help$)/ | 
					
						
							|  |  |  |   help_flag = false | 
					
						
							|  |  |  |   cmd = nil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ARGV.dup.each_with_index do |arg, i| | 
					
						
							|  |  |  |     if help_flag && cmd | 
					
						
							|  |  |  |       break | 
					
						
							|  |  |  |     elsif arg =~ help_regex | 
					
						
							|  |  |  |       help_flag = true | 
					
						
							|  |  |  |     elsif !cmd | 
					
						
							|  |  |  |       cmd = ARGV.delete_at(i) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   cmd = aliases[cmd] if aliases[cmd] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-08 18:17:28 -07:00
										 |  |  |   sudo_check = Set.new %w[ install link pin unpin upgrade ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if sudo_check.include? cmd | 
					
						
							|  |  |  |     if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? | 
					
						
							|  |  |  |       raise "Cowardly refusing to `sudo brew #{cmd}`\n#{SUDO_BAD_ERRMSG}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-15 10:28:06 -07:00
										 |  |  |   # Add contributed commands to PATH before checking. | 
					
						
							| 
									
										
										
										
											2014-05-02 12:59:37 -05:00
										 |  |  |   ENV['PATH'] += "#{File::PATH_SEPARATOR}#{HOMEBREW_CONTRIB}/cmd" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-26 09:24:07 +01:00
										 |  |  |   internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd) if cmd | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # Usage instructions should be displayed if and only if one of: | 
					
						
							|  |  |  |   # - a help flag is passed AND an internal command is matched | 
					
						
							| 
									
										
										
										
											2014-06-26 09:27:22 +01:00
										 |  |  |   # - a help flag is passed AND there is no command specified | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  |   # - no arguments are passed | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   # It should never affect external commands so they can handle usage | 
					
						
							|  |  |  |   # arguments themselves. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-26 09:27:22 +01:00
										 |  |  |   if empty_argv || (help_flag && (cmd.nil? || internal_cmd)) | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  |     # TODO - `brew help cmd` should display subcommand help | 
					
						
							|  |  |  |     require 'cmd/help' | 
					
						
							|  |  |  |     puts ARGV.usage | 
					
						
							|  |  |  |     exit ARGV.any? ? 0 : 1
 | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if internal_cmd | 
					
						
							| 
									
										
										
										
											2013-02-17 13:30:58 +00:00
										 |  |  |     Homebrew.send cmd.to_s.gsub('-', '_').downcase | 
					
						
							|  |  |  |   elsif which "brew-#{cmd}" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     %w[CACHE CELLAR LIBRARY_PATH PREFIX REPOSITORY].each do |e| | 
					
						
							| 
									
										
										
										
											2014-05-02 12:59:38 -05:00
										 |  |  |       ENV["HOMEBREW_#{e}"] = Object.const_get("HOMEBREW_#{e}").to_s | 
					
						
							| 
									
										
										
										
											2010-02-27 13:29:49 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     exec "brew-#{cmd}", *ARGV | 
					
						
							| 
									
										
										
										
											2014-05-04 09:14:37 -05:00
										 |  |  |   elsif (path = which("brew-#{cmd}.rb")) && require?(path) | 
					
						
							| 
									
										
										
										
											2014-04-11 15:10:59 +01:00
										 |  |  |     exit Homebrew.failed? ? 1 : 0
 | 
					
						
							| 
									
										
										
										
											2009-09-24 19:19:57 +01:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2012-03-07 07:00:27 -08:00
										 |  |  |     onoe "Unknown command: #{cmd}" | 
					
						
							|  |  |  |     exit 1
 | 
					
						
							| 
									
										
										
										
											2009-06-02 13:39:39 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-05-23 16:37:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 18:16:42 +00:00
										 |  |  | rescue FormulaUnspecifiedError | 
					
						
							| 
									
										
										
										
											2009-11-11 18:38:50 +00:00
										 |  |  |   abort "This command requires a formula argument" | 
					
						
							| 
									
										
										
										
											2009-10-26 18:16:42 +00:00
										 |  |  | rescue KegUnspecifiedError | 
					
						
							| 
									
										
										
										
											2009-11-11 18:38:50 +00:00
										 |  |  |   abort "This command requires a keg argument" | 
					
						
							| 
									
										
										
										
											2009-08-11 00:27:18 +01:00
										 |  |  | rescue UsageError | 
					
						
							|  |  |  |   onoe "Invalid usage" | 
					
						
							| 
									
										
										
										
											2009-11-11 18:38:50 +00:00
										 |  |  |   abort ARGV.usage | 
					
						
							| 
									
										
										
										
											2009-08-10 16:48:30 +01:00
										 |  |  | rescue SystemExit | 
					
						
							| 
									
										
										
										
											2009-10-26 18:23:28 +00:00
										 |  |  |   puts "Kernel.exit" if ARGV.verbose? | 
					
						
							| 
									
										
										
										
											2009-11-11 18:51:05 +00:00
										 |  |  |   raise | 
					
						
							| 
									
										
										
										
											2009-08-10 16:48:30 +01:00
										 |  |  | rescue Interrupt => e | 
					
						
							| 
									
										
										
										
											2009-10-26 18:23:28 +00:00
										 |  |  |   puts # seemingly a newline is typical | 
					
						
							| 
									
										
										
										
											2009-08-10 16:48:30 +01:00
										 |  |  |   exit 130
 | 
					
						
							| 
									
										
										
										
											2009-11-12 01:33:14 +00:00
										 |  |  | rescue BuildError => e | 
					
						
							| 
									
										
										
										
											2012-03-07 11:11:05 +00:00
										 |  |  |   e.dump | 
					
						
							| 
									
										
										
										
											2009-11-12 01:33:14 +00:00
										 |  |  |   exit 1
 | 
					
						
							|  |  |  | rescue RuntimeError, SystemCallError => e | 
					
						
							| 
									
										
										
										
											2012-08-28 20:14:44 -04:00
										 |  |  |   raise if e.message.empty? | 
					
						
							| 
									
										
										
										
											2009-11-12 01:33:14 +00:00
										 |  |  |   onoe e | 
					
						
							|  |  |  |   puts e.backtrace if ARGV.debug? | 
					
						
							|  |  |  |   exit 1
 | 
					
						
							| 
									
										
										
										
											2009-08-10 16:48:30 +01:00
										 |  |  | rescue Exception => e | 
					
						
							| 
									
										
										
										
											2009-11-11 18:38:50 +00:00
										 |  |  |   onoe e | 
					
						
							| 
									
										
										
										
											2011-08-31 11:07:27 +01:00
										 |  |  |   puts "#{Tty.white}Please report this bug:" | 
					
						
							| 
									
										
										
										
											2014-07-13 21:24:07 -05:00
										 |  |  |   puts "    #{Tty.em}#{OS::ISSUES_URL}#{Tty.reset}" | 
					
						
							| 
									
										
										
										
											2009-11-12 01:33:14 +00:00
										 |  |  |   puts e.backtrace | 
					
						
							| 
									
										
										
										
											2009-09-23 09:32:04 +01:00
										 |  |  |   exit 1
 | 
					
						
							| 
									
										
										
										
											2012-03-15 10:57:34 +13:00
										 |  |  | else | 
					
						
							|  |  |  |   exit 1 if Homebrew.failed? | 
					
						
							| 
									
										
										
										
											2009-07-31 02:51:17 +01:00
										 |  |  | end |