2009-05-21 00:04:43 +01:00
|
|
|
#!/usr/bin/ruby
|
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'
|
|
|
|
require 'brew.h'
|
|
|
|
|
|
|
|
# TODO if whoami == root then use /Library/Caches/Homebrew instead
|
|
|
|
HOMEBREW_CACHE=Pathname.new("~/Library/Caches/Homebrew").expand_path
|
|
|
|
HOMEBREW_PREFIX=Pathname.new(__FILE__).dirname.parent.cleanpath
|
|
|
|
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-08-10 16:48:30 +01:00
|
|
|
if %w[/ /usr].include? HOMEBREW_PREFIX.to_s then abort <<-troba
|
|
|
|
You have placed Homebrew at the prefix: #{HOMEBREW_PREFIX}
|
|
|
|
This is not currently supported. Voice your support for this feature at:
|
|
|
|
#{HOMEBREW_WWW}
|
|
|
|
troba
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-05-23 16:37:24 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
# Pathname often throws if CWD doesn't exist
|
|
|
|
Dir.chdir '/' unless File.directory? ENV['PWD']
|
2009-06-05 08:09:34 +01:00
|
|
|
|
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-10 16:48:30 +01:00
|
|
|
if ARGV.named.empty?
|
|
|
|
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-10 16:48:30 +01:00
|
|
|
exec "find", *ARGV.kegs.concat(%w[-not -type d -print])
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-06-26 13:03:49 +01:00
|
|
|
when 'edit'
|
|
|
|
if ARGV.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-08 14:10:32 +01:00
|
|
|
# we need to ensure a pristine ENV for each process or the formula
|
|
|
|
# will start with the ENV from the previous build
|
2009-08-10 16:48:30 +01:00
|
|
|
ARGV.formulae.each do |f|
|
2009-08-08 14:10:32 +01:00
|
|
|
pid=fork
|
|
|
|
if pid.nil?
|
|
|
|
exec "brew", "install-just-one", f.name, *ARGV.options
|
|
|
|
else
|
|
|
|
Process.wait pid
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|
2009-08-08 14:10:32 +01:00
|
|
|
exit! 1 if $? != 0 # exception in other brew will be visible on screen
|
|
|
|
end
|
|
|
|
|
|
|
|
# this is an internal option, don't expose it to the user
|
|
|
|
when 'install-just-one'
|
|
|
|
require 'keg'
|
|
|
|
f=ARGV.formulae.shift
|
|
|
|
raise "#{f.name} is already installed" if f.installed? unless ARGV.force?
|
|
|
|
BEGINNING=Time.now
|
|
|
|
begin
|
|
|
|
install f
|
|
|
|
ohai "Caveats", f.caveats, ''
|
|
|
|
ohai 'Finishing up'
|
|
|
|
clean f
|
|
|
|
raise "Nothing was installed to #{f.prefix}" unless f.installed?
|
|
|
|
Keg.new(f.prefix).link
|
|
|
|
rescue Exception
|
|
|
|
f.prefix.rmtree if f.prefix.directory?
|
|
|
|
raise
|
2009-06-05 08:09:34 +01:00
|
|
|
end
|
2009-08-08 14:10:32 +01:00
|
|
|
puts "#{f.prefix}: #{f.prefix.abv}, built in #{pretty_duration Time.now-BEGINNING}"
|
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-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'
|
|
|
|
puts "Reserved command"
|
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-10 16:48:30 +01:00
|
|
|
exec "mate", *ARGV.named.collect {|name| make name}
|
2009-06-08 15:59:59 +01:00
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'info', 'abv'
|
2009-08-10 16:48:30 +01:00
|
|
|
if ARGV.named.empty?
|
|
|
|
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-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
|
|
|
|
if ARGV.verbose? or ARGV.debug?
|
|
|
|
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
|