brew/bin/brew

145 lines
4.1 KiB
Plaintext
Raw Normal View History

2009-05-21 00:04:43 +01:00
#!/usr/bin/ruby
$:.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'
HOMEBREW_USER_AGENT="Homebrew #{HOMEBREW_VERSION} (Ruby #{VERSION}; Mac OS X 10.5 Leopard)"
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
end
2009-05-23 16:37:24 +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
begin
case ARGV.shift
when '--prefix' then puts HOMEBREW_PREFIX
when '--cache' then puts HOMEBREW_CACHE
when '-h', '--help', '--usage', '-?' then puts ARGV.usage
when '-v', '--version' then puts HOMEBREW_VERSION
when 'home', 'homepage'
if ARGV.named.empty?
exec "open", HOMEBREW_WWW
else
exec "open", *ARGV.formulae.collect {|f| f.homepage}
end
when 'ls', 'list'
exec "find", *ARGV.kegs.concat(%w[-not -type d -print])
2009-06-26 13:03:49 +01:00
when 'edit'
if ARGV.empty?
exec "mate", *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
"#{HOMEBREW_PREFIX}/bin/brew"<<
"#{HOMEBREW_PREFIX}/README"
2009-06-26 13:03:49 +01:00
else
exec "mate", *ARGV.formulae.collect {|f| f.path}
2009-06-26 13:03:49 +01:00
end
when 'install'
# we need to ensure a pristine ENV for each process or the formula
# will start with the ENV from the previous build
ARGV.formulae.each do |f|
pid=fork
if pid.nil?
exec "brew", "install-just-one", f.name, *ARGV.options
else
Process.wait pid
end
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
puts "#{f.prefix}: #{f.prefix.abv}, built in #{pretty_duration Time.now-BEGINNING}"
2009-07-22 20:27:58 +01:00
when 'ln', 'link'
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
when 'rm', 'uninstall', 'remove'
ARGV.kegs.each do |keg|
puts "Uninstalling #{keg}..."
keg.uninstall
end
prune
when 'up', 'update'
puts "Reserved command"
when 'prune'
prune
when 'mk', 'make'
if ARGV.include? '--macports'
exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
else
exec "mate", *ARGV.named.collect {|name| make name}
end
when 'info', 'abv'
if ARGV.named.empty?
puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+HOMEBREW_CELLAR.abv
elsif ARGV[0][0..6] == 'http://'
puts Pathname.new(ARGV.shift).version
2009-06-13 12:59:18 +01:00
else
ARGV.named.each {|name| info name}
2009-06-05 12:57:00 +01:00
end
else
puts ARGV.usage
end
2009-05-23 16:37:24 +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
onoe e
end
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
end