| 
									
										
										
										
											2016-08-24 14:46:05 +01:00
										 |  |  | unless ENV["HOMEBREW_BREW_FILE"] | 
					
						
							|  |  |  |   raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-22 15:50:27 -04:00
										 |  |  | std_trap = trap("INT") { exit! 130 } # no backtrace thanks | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 14:35:39 +08:00
										 |  |  | # check ruby version before requiring any modules. | 
					
						
							|  |  |  | RUBY_TWO = RUBY_VERSION.split(".").first.to_i >= 2
 | 
					
						
							|  |  |  | raise "Homebrew must be run under Ruby 2!" unless RUBY_TWO | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "pathname" | 
					
						
							| 
									
										
										
										
											2016-07-15 19:33:30 +01:00
										 |  |  | HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent | 
					
						
							| 
									
										
										
										
											2014-05-02 12:59:38 -05:00
										 |  |  | $:.unshift(HOMEBREW_LIBRARY_PATH.to_s) | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "global" | 
					
						
							| 
									
										
										
										
											2009-08-10 16:48:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-08 09:56:20 +01:00
										 |  |  | if ARGV == %w[--version] || ARGV == %w[-v] | 
					
						
							| 
									
										
										
										
											2016-10-03 16:12:19 +02:00
										 |  |  |   require "tap" | 
					
						
							| 
									
										
										
										
											2016-09-22 08:56:40 +01:00
										 |  |  |   puts "Homebrew #{HOMEBREW_VERSION}" | 
					
						
							| 
									
										
										
										
											2016-10-03 16:12:19 +02:00
										 |  |  |   puts "Homebrew/homebrew-core #{CoreTap.instance.version_string}" | 
					
						
							| 
									
										
										
										
											2009-10-15 14:54:11 +01:00
										 |  |  |   exit 0
 | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +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 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   # HACK: ( because we should raise on syntax errors but | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   # 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  |   empty_argv = ARGV.empty? | 
					
						
							| 
									
										
										
										
											2016-04-17 04:07:36 +02:00
										 |  |  |   help_flag_list = %w[-h --help --usage -?] | 
					
						
							| 
									
										
										
										
											2016-10-01 18:17:52 +03:00
										 |  |  |   help_flag = !ENV["HOMEBREW_HELP"].nil? | 
					
						
							| 
									
										
										
										
											2015-07-23 23:57:11 +02:00
										 |  |  |   internal_cmd = true | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  |   cmd = nil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ARGV.dup.each_with_index do |arg, i| | 
					
						
							| 
									
										
										
										
											2016-09-22 20:12:28 +02:00
										 |  |  |     break if help_flag && cmd | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-01 18:17:52 +03:00
										 |  |  |     if arg == "help" && !cmd | 
					
						
							| 
									
										
										
										
											2016-04-17 04:07:36 +02:00
										 |  |  |       # Command-style help: `help <cmd>` is fine, but `<cmd> help` is not. | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  |       help_flag = true | 
					
						
							| 
									
										
										
										
											2016-10-01 18:17:52 +03:00
										 |  |  |     elsif !cmd && !help_flag_list.include?(arg) | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  |       cmd = ARGV.delete_at(i) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-15 10:28:06 -07:00
										 |  |  |   # Add contributed commands to PATH before checking. | 
					
						
							| 
									
										
										
										
											2014-09-24 15:14:16 -07:00
										 |  |  |   Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/cmd"].each do |tap_cmd_dir| | 
					
						
							|  |  |  |     ENV["PATH"] += "#{File::PATH_SEPARATOR}#{tap_cmd_dir}" | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-05-02 12:59:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:40:05 +03:00
										 |  |  |   # Add cask commands to PATH. | 
					
						
							|  |  |  |   ENV["PATH"] += "#{File::PATH_SEPARATOR}#{HOMEBREW_LIBRARY}/Homebrew/cask/cmd" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-24 21:35:07 -07:00
										 |  |  |   # Add SCM wrappers. | 
					
						
							| 
									
										
										
										
											2016-07-15 19:03:45 +01:00
										 |  |  |   ENV["PATH"] += "#{File::PATH_SEPARATOR}#{HOMEBREW_SHIMS_PATH}/scm" | 
					
						
							| 
									
										
										
										
											2014-09-24 21:35:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 21:20:34 +08:00
										 |  |  |   if cmd | 
					
						
							|  |  |  |     internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-05 21:32:25 +01:00
										 |  |  |     unless internal_cmd | 
					
						
							| 
									
										
										
										
											2015-09-10 21:20:34 +08:00
										 |  |  |       internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("dev-cmd", cmd) | 
					
						
							| 
									
										
										
										
											2016-09-05 21:32:25 +01:00
										 |  |  |       if internal_cmd && !ARGV.homebrew_developer? | 
					
						
							| 
									
										
										
										
											2016-11-09 12:44:13 +00:00
										 |  |  |         system "git", "config", "--file=#{HOMEBREW_REPOSITORY}/.git/config", | 
					
						
							|  |  |  |                                 "--replace-all", "homebrew.devcmdrun", "true" | 
					
						
							| 
									
										
										
										
											2016-09-05 21:32:25 +01:00
										 |  |  |         ENV["HOMEBREW_DEV_CMD_RUN"] = "1" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-09-10 21:20:34 +08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # Usage instructions should be displayed if and only if one of: | 
					
						
							| 
									
										
										
										
											2016-10-01 18:25:16 +01:00
										 |  |  |   # - a help flag is passed AND a 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 | 
					
						
							| 
									
										
										
										
											2016-04-17 03:45:10 +02:00
										 |  |  |   if empty_argv || help_flag | 
					
						
							|  |  |  |     require "cmd/help" | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |     Homebrew.help cmd, empty_argv: empty_argv | 
					
						
							| 
									
										
										
										
											2016-04-19 07:24:21 +02:00
										 |  |  |     # `Homebrew.help` never returns, except for external/unknown commands. | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 15:00:46 +01:00
										 |  |  |   # Migrate LinkedKegs/PinnedKegs if update didn't already do so | 
					
						
							|  |  |  |   migrate_legacy_keg_symlinks_if_necessary | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-21 16:36:34 +01:00
										 |  |  |   # Uninstall old brew-cask if it's still around; we just use the tap now. | 
					
						
							|  |  |  |   if cmd == "cask" && (HOMEBREW_CELLAR/"brew-cask").exist? | 
					
						
							|  |  |  |     system(HOMEBREW_BREW_FILE, "uninstall", "--force", "brew-cask") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 09:45:01 +01:00
										 |  |  |   if internal_cmd | 
					
						
							| 
									
										
										
										
											2016-01-18 12:29:30 +08:00
										 |  |  |     Homebrew.send cmd.to_s.tr("-", "_").downcase | 
					
						
							| 
									
										
										
										
											2013-02-17 13:30:58 +00:00
										 |  |  |   elsif which "brew-#{cmd}" | 
					
						
							| 
									
										
										
										
											2016-01-21 16:19:46 +01:00
										 |  |  |     %w[CACHE LIBRARY_PATH].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 | 
					
						
							| 
									
										
										
										
											2015-11-07 16:52:01 +08:00
										 |  |  |     require "tap" | 
					
						
							| 
									
										
										
										
											2016-07-04 17:05:37 +01:00
										 |  |  |     possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) } | 
					
						
							|  |  |  |     possible_tap = Tap.fetch(possible_tap.first) if possible_tap | 
					
						
							| 
									
										
										
										
											2015-11-07 16:52:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if possible_tap && !possible_tap.installed? | 
					
						
							| 
									
										
										
										
											2016-02-05 22:11:04 +08:00
										 |  |  |       brew_uid = HOMEBREW_BREW_FILE.stat.uid | 
					
						
							| 
									
										
										
										
											2016-01-14 16:07:11 +08:00
										 |  |  |       tap_commands = [] | 
					
						
							|  |  |  |       if Process.uid.zero? && !brew_uid.zero? | 
					
						
							|  |  |  |         tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap}] | 
					
						
							| 
									
										
										
										
											2016-04-20 01:38:00 +02:00
										 |  |  |       safe_system(*tap_commands) | 
					
						
							| 
									
										
										
										
											2015-11-07 16:52:01 +08:00
										 |  |  |       exec HOMEBREW_BREW_FILE, cmd, *ARGV | 
					
						
							| 
									
										
										
										
											2015-12-08 10:40:47 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2016-07-23 20:49:23 +02:00
										 |  |  |       odie "Unknown command: #{cmd}" | 
					
						
							| 
									
										
										
										
											2015-11-07 16:52:01 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2009-06-02 13:39:39 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-05-23 16:37:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-19 08:11:17 +02:00
										 |  |  | rescue UsageError => e | 
					
						
							| 
									
										
										
										
											2016-04-19 07:33:13 +02:00
										 |  |  |   require "cmd/help" | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |   Homebrew.help cmd, usage_error: e.message | 
					
						
							| 
									
										
										
										
											2015-12-21 08:44:41 +00:00
										 |  |  | rescue SystemExit => e | 
					
						
							|  |  |  |   onoe "Kernel.exit" if ARGV.verbose? && !e.success? | 
					
						
							| 
									
										
										
										
											2016-01-30 23:09:45 -08:00
										 |  |  |   $stderr.puts e.backtrace if ARGV.debug? | 
					
						
							| 
									
										
										
										
											2009-11-11 18:51:05 +00:00
										 |  |  |   raise | 
					
						
							| 
									
										
										
										
											2009-08-10 16:48:30 +01:00
										 |  |  | rescue Interrupt => e | 
					
						
							| 
									
										
										
										
											2016-01-30 23:09:45 -08:00
										 |  |  |   $stderr.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 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:21:08 +01:00
										 |  |  |   Utils::Analytics.report_exception(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 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:21:08 +01:00
										 |  |  |   Utils::Analytics.report_exception(e) | 
					
						
							| 
									
										
										
										
											2012-08-28 20:14:44 -04:00
										 |  |  |   raise if e.message.empty? | 
					
						
							| 
									
										
										
										
											2009-11-12 01:33:14 +00:00
										 |  |  |   onoe e | 
					
						
							| 
									
										
										
										
											2016-01-30 23:09:45 -08:00
										 |  |  |   $stderr.puts e.backtrace if ARGV.debug? | 
					
						
							| 
									
										
										
										
											2009-11-12 01:33:14 +00:00
										 |  |  |   exit 1
 | 
					
						
							| 
									
										
										
										
											2016-12-10 13:04:14 +00:00
										 |  |  | rescue MethodDeprecatedError => e | 
					
						
							|  |  |  |   Utils::Analytics.report_exception(e) | 
					
						
							|  |  |  |   onoe e | 
					
						
							|  |  |  |   if e.issues_url | 
					
						
							|  |  |  |     $stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):" | 
					
						
							|  |  |  |     $stderr.puts "  #{Formatter.url(e.issues_url)}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   exit 1
 | 
					
						
							| 
									
										
										
										
											2009-08-10 16:48:30 +01:00
										 |  |  | rescue Exception => e | 
					
						
							| 
									
										
										
										
											2016-05-03 14:21:08 +01:00
										 |  |  |   Utils::Analytics.report_exception(e) | 
					
						
							| 
									
										
										
										
											2009-11-11 18:38:50 +00:00
										 |  |  |   onoe e | 
					
						
							| 
									
										
										
										
											2016-05-08 17:02:02 +01:00
										 |  |  |   if internal_cmd && defined?(OS::ISSUES_URL) | 
					
						
							| 
									
										
										
										
											2016-08-30 21:38:13 +02:00
										 |  |  |     $stderr.puts "#{Tty.bold}Please report this bug:#{Tty.reset}" | 
					
						
							|  |  |  |     $stderr.puts "  #{Formatter.url(OS::ISSUES_URL)}" | 
					
						
							| 
									
										
										
										
											2015-07-23 23:57:11 +02:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-01-30 23:09:45 -08:00
										 |  |  |   $stderr.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 |