2009-05-21 00:04:43 +01:00
|
|
|
#!/usr/bin/ruby
|
2009-09-03 17:10:35 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-08-10 16:48:30 +01:00
|
|
|
$:.unshift ENV['RUBYLIB']=File.expand_path(__FILE__+'/../../Library/Homebrew')
|
|
|
|
require 'pathname+yeast'
|
|
|
|
require 'ARGV+yeast'
|
|
|
|
require 'utils'
|
2009-09-03 22:39:49 +01:00
|
|
|
require 'hardware'
|
2009-08-10 16:48:30 +01:00
|
|
|
require 'brew.h'
|
|
|
|
|
2009-08-25 11:25:47 -07:00
|
|
|
if Process.uid == 0
|
|
|
|
# technically this is not the correct place, this cache is for *all users*
|
|
|
|
# so in that case, maybe we should always use it, root or not?
|
|
|
|
HOMEBREW_CACHE=Pathname.new("/Library/Caches/Homebrew")
|
|
|
|
else
|
|
|
|
HOMEBREW_CACHE=Pathname.new("~/Library/Caches/Homebrew").expand_path
|
|
|
|
end
|
|
|
|
|
2009-09-02 14:21:22 -05:00
|
|
|
HOMEBREW_PREFIX=(Pathname.getwd+__FILE__).dirname.parent.cleanpath
|
2009-08-10 16:48:30 +01:00
|
|
|
HOMEBREW_CELLAR=HOMEBREW_PREFIX+'Cellar'
|
|
|
|
HOMEBREW_VERSION='0.4'
|
|
|
|
HOMEBREW_WWW='http://bit.ly/Homebrew'
|
2009-08-03 09:59:14 -07:00
|
|
|
HOMEBREW_USER_AGENT="Homebrew #{HOMEBREW_VERSION} (Ruby #{VERSION}; Mac OS X 10.5 Leopard)"
|
2009-08-02 00:04:15 +01:00
|
|
|
|
2009-09-03 22:39:49 +01:00
|
|
|
if %w[/ /usr].include? HOMEBREW_PREFIX.to_s then abort <<-EOS
|
|
|
|
You have placed Homebrew at the prefix: #{HOMEBREW_PREFIX}
|
|
|
|
This is not currently supported. Voice your support for this feature at:
|
|
|
|
#{HOMEBREW_WWW}
|
|
|
|
EOS
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-08-12 01:56:40 +01:00
|
|
|
if `sw_vers -productVersion` =~ /10\.(\d)\.(\d+)/ and $1.to_i < 5
|
|
|
|
onoe "Homebrew requires Leopard or higher"
|
|
|
|
abort "But thanks for your interest anyway!"
|
|
|
|
end
|
2009-09-03 22:39:49 +01:00
|
|
|
if Hardware.cpu_type == :ppc or Hardware.cpu_type == :dunno
|
|
|
|
abort "Sorry, Homebrew does not support your computer's CPU architecture."
|
|
|
|
end
|
2009-09-04 09:46:53 -07:00
|
|
|
unless system "which gcc-4.2 &> /dev/null" and $?.success?
|
|
|
|
abort "Sorry, Homebrew requires gcc 4.2, which is provided by Xcode 3.1"
|
|
|
|
end
|
2009-06-15 01:41:53 +01:00
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
begin
|
|
|
|
case ARGV.shift
|
2009-08-10 16:48:30 +01:00
|
|
|
when '--prefix' then puts HOMEBREW_PREFIX
|
2009-08-04 00:12:03 +08:00
|
|
|
when '--cache' then puts HOMEBREW_CACHE
|
2009-08-10 16:48:30 +01:00
|
|
|
when '-h', '--help', '--usage', '-?' then puts ARGV.usage
|
2009-07-24 15:10:01 +01:00
|
|
|
when '-v', '--version' then puts HOMEBREW_VERSION
|
|
|
|
|
2009-07-31 22:10:50 -07:00
|
|
|
when 'home', 'homepage'
|
2009-08-11 00:27:18 +01:00
|
|
|
if ARGV.named_empty?
|
2009-08-10 16:48:30 +01:00
|
|
|
exec "open", HOMEBREW_WWW
|
|
|
|
else
|
|
|
|
exec "open", *ARGV.formulae.collect {|f| f.homepage}
|
|
|
|
end
|
2009-07-31 22:10:50 -07:00
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'ls', 'list'
|
2009-08-23 13:09:15 +01:00
|
|
|
if ARGV.named_empty?
|
|
|
|
ENV['CLICOLOR']=nil
|
|
|
|
exec 'ls', *ARGV.options<<HOMEBREW_CELLAR
|
|
|
|
else
|
|
|
|
exec "find", *ARGV.kegs+%w[-not -type d -print]
|
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-09-04 15:22:25 -07:00
|
|
|
when 'search', '-S'
|
|
|
|
formulae = (HOMEBREW_PREFIX+'Library'+'Formula').children.sort.map{|f| f.basename('.rb') }
|
|
|
|
puts_columns formulae.grep(Regexp.new(ARGV.first || ''))
|
|
|
|
|
2009-06-26 13:03:49 +01:00
|
|
|
when 'edit'
|
2009-08-11 00:27:18 +01:00
|
|
|
if ARGV.named_empty?
|
2009-08-10 16:48:30 +01:00
|
|
|
exec "mate", *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
|
|
|
|
"#{HOMEBREW_PREFIX}/bin/brew"<<
|
|
|
|
"#{HOMEBREW_PREFIX}/README"
|
2009-06-26 13:03:49 +01:00
|
|
|
else
|
2009-08-10 16:48:30 +01:00
|
|
|
exec "mate", *ARGV.formulae.collect {|f| f.path}
|
2009-06-26 13:03:49 +01:00
|
|
|
end
|
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
when 'install'
|
2009-08-29 18:46:31 +01:00
|
|
|
if ARGV.named_empty?
|
2009-09-04 15:22:25 -07:00
|
|
|
puts "You must specify a formula. Search for available formulae with `brew search'."
|
2009-08-29 18:46:31 +01:00
|
|
|
exit 0
|
|
|
|
end
|
2009-09-02 14:15:44 +01:00
|
|
|
|
2009-09-04 15:42:19 +01:00
|
|
|
require 'brewkit'
|
|
|
|
|
2009-09-02 14:15:44 +01:00
|
|
|
if ARGV.verbose?
|
|
|
|
ohai "Build Environment"
|
|
|
|
%w[CFLAGS LDFLAGS CPPFLAGS MAKEFLAGS CC CXX].each do |f|
|
|
|
|
puts "#{f}: #{ENV[f]}" unless ENV[f].to_s.empty?
|
|
|
|
end
|
|
|
|
end
|
2009-09-04 15:22:25 -07:00
|
|
|
|
2009-09-04 15:42:19 +01:00
|
|
|
unless system "which #{ENV['CC'] or 'cc'} &> /dev/null" and $?.success?
|
|
|
|
raise "We cannot find a c compiler, have you installed the latest Xcode?"
|
|
|
|
end
|
2009-09-02 14:15:44 +01:00
|
|
|
|
2009-09-03 19:48:00 +02:00
|
|
|
require 'beer_events'
|
|
|
|
|
|
|
|
watch_out_for_spill do
|
|
|
|
ARGV.formulae.each do |f|
|
|
|
|
if f.installed? and not ARGV.force?
|
|
|
|
message = "Formula already installed: #{f.prefix}"
|
|
|
|
if ARGV.formulae.count > 1
|
|
|
|
opoo message
|
|
|
|
else
|
|
|
|
puts message # if only one is being installed a warning looks severe
|
|
|
|
end
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
# we need to ensure a pristine ENV for each process or the formula
|
|
|
|
# will start with the ENV from the previous build
|
|
|
|
pid=fork
|
|
|
|
if pid.nil?
|
|
|
|
exec __FILE__, "install-just-one", f.name, *ARGV.options
|
|
|
|
else
|
|
|
|
Process.wait pid
|
|
|
|
end
|
|
|
|
#FIXME I don't think $? represents the exit code from the child fork…
|
|
|
|
exit! $? if $? != 0 # exception in other brew will be visible on screen
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|
2009-08-08 14:10:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# this is an internal option, don't expose it to the user
|
|
|
|
when 'install-just-one'
|
|
|
|
require 'keg'
|
2009-09-03 19:48:00 +02:00
|
|
|
|
2009-08-08 14:10:32 +01:00
|
|
|
f=ARGV.formulae.shift
|
2009-09-03 19:48:00 +02:00
|
|
|
|
2009-08-08 14:10:32 +01:00
|
|
|
begin
|
2009-09-02 14:52:44 +01:00
|
|
|
build_time=install f
|
2009-08-08 14:10:32 +01:00
|
|
|
ohai "Caveats", f.caveats, ''
|
2009-09-03 19:48:00 +02:00
|
|
|
ohai 'Finishing up' if ARGV.verbose?
|
2009-08-08 14:10:32 +01:00
|
|
|
clean f
|
|
|
|
raise "Nothing was installed to #{f.prefix}" unless f.installed?
|
|
|
|
rescue Exception
|
|
|
|
f.prefix.rmtree if f.prefix.directory?
|
|
|
|
raise
|
2009-06-05 08:09:34 +01:00
|
|
|
end
|
2009-09-03 19:48:00 +02:00
|
|
|
|
|
|
|
begin
|
|
|
|
Keg.new(f.prefix).link
|
|
|
|
rescue Exception
|
|
|
|
onoe "The linking step did not complete successfully"
|
|
|
|
puts "The package built, but is not symlinked into #{HOMEBREW_PREFIX}"
|
|
|
|
puts "You can try again using `brew link #{f.name}'"
|
|
|
|
ohai "Summary" unless ARGV.verbose?
|
|
|
|
end
|
|
|
|
|
|
|
|
ohai "Summary" if ARGV.verbose?
|
2009-09-02 14:52:44 +01:00
|
|
|
print "#{f.prefix}: #{f.prefix.abv}"
|
|
|
|
print ", built in #{pretty_duration build_time}" if build_time
|
|
|
|
puts
|
2009-07-22 20:27:58 +01:00
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'ln', 'link'
|
2009-08-10 16:48:30 +01:00
|
|
|
ARGV.kegs.each {|keg| puts "#{keg.link} links created for #{keg}"}
|
|
|
|
|
|
|
|
when 'unlink'
|
|
|
|
ARGV.kegs.each {|keg| puts "#{keg.unlink} links removed for #{keg}"}
|
2009-07-22 20:27:58 +01:00
|
|
|
|
2009-08-29 21:07:26 +01:00
|
|
|
when 'unlink'
|
|
|
|
ARGV.kegs.each {|keg| puts "#{keg.unlink} links removed for #{keg}"}
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
when 'rm', 'uninstall', 'remove'
|
|
|
|
ARGV.kegs.each do |keg|
|
|
|
|
puts "Uninstalling #{keg}..."
|
|
|
|
keg.uninstall
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
prune
|
|
|
|
|
|
|
|
when 'up', 'update'
|
2009-09-03 19:48:00 +02:00
|
|
|
puts "You can't yet update :( But you can try:"
|
|
|
|
puts " git pull"
|
|
|
|
puts " brew rm foo"
|
|
|
|
puts " brew install foo"
|
2009-06-08 11:42:28 +01:00
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'prune'
|
2009-08-10 16:48:30 +01:00
|
|
|
prune
|
2009-07-24 15:10:01 +01:00
|
|
|
|
|
|
|
when 'mk', 'make'
|
2009-08-10 16:48:30 +01:00
|
|
|
if ARGV.include? '--macports'
|
|
|
|
exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
|
2009-06-08 15:59:59 +01:00
|
|
|
else
|
2009-08-30 15:01:36 +01:00
|
|
|
exec "mate", *ARGV.collect {|name| make name}
|
2009-06-08 15:59:59 +01:00
|
|
|
end
|
|
|
|
|
2009-08-22 15:54:26 +01:00
|
|
|
when 'diy', 'configure'
|
2009-08-12 13:43:51 +01:00
|
|
|
puts diy
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'info', 'abv'
|
2009-08-11 00:27:18 +01:00
|
|
|
if ARGV.named_empty?
|
2009-08-10 16:48:30 +01:00
|
|
|
puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+HOMEBREW_CELLAR.abv
|
2009-07-24 15:10:01 +01:00
|
|
|
elsif ARGV[0][0..6] == 'http://'
|
|
|
|
puts Pathname.new(ARGV.shift).version
|
2009-06-13 12:59:18 +01:00
|
|
|
else
|
2009-08-10 16:48:30 +01:00
|
|
|
ARGV.named.each {|name| info name}
|
2009-06-05 12:57:00 +01:00
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-06-18 09:51:45 +01:00
|
|
|
else
|
2009-08-10 16:48:30 +01:00
|
|
|
puts ARGV.usage
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-05-23 16:37:24 +01:00
|
|
|
|
2009-08-11 00:27:18 +01:00
|
|
|
rescue UsageError
|
|
|
|
onoe "Invalid usage"
|
|
|
|
puts ARGV.usage
|
2009-08-10 16:48:30 +01:00
|
|
|
rescue SystemExit
|
|
|
|
ohai "Kernel.exit" if ARGV.verbose?
|
|
|
|
rescue Interrupt => e
|
|
|
|
puts # seemingly a newline is typical
|
|
|
|
exit 130
|
|
|
|
rescue SystemCallError, RuntimeError => e
|
2009-08-11 18:17:11 +01:00
|
|
|
if ARGV.debug?
|
2009-08-10 16:48:30 +01:00
|
|
|
onoe e.inspect
|
|
|
|
puts e.backtrace
|
2009-05-21 00:04:43 +01:00
|
|
|
else
|
2009-08-10 16:48:30 +01:00
|
|
|
onoe e
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
exit 1
|
|
|
|
rescue Exception => e
|
|
|
|
onoe "Homebrew has failed you :("
|
|
|
|
puts "Please report this bug at: #{HOMEBREW_WWW}"
|
|
|
|
puts "Please include this backtrace:"
|
|
|
|
ohai e.inspect
|
|
|
|
puts e.backtrace
|
2009-07-31 02:51:17 +01:00
|
|
|
end
|