2009-05-21 00:04:43 +01:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
# Copyright 2009 Max Howell <max@methylblue.com>
|
|
|
|
|
# Licensed as per the GPL version 3
|
2009-05-21 01:15:47 +01:00
|
|
|
require 'find'
|
|
|
|
|
require 'pathname'
|
2009-05-21 00:04:43 +01:00
|
|
|
$root = Pathname.new(__FILE__).realpath.dirname.parent.parent
|
|
|
|
|
|
|
|
|
|
case ARGV[0]
|
|
|
|
|
when 'brew', 'install' then
|
|
|
|
|
file="#{$root}/Formula/#{ARGV[1]}"
|
|
|
|
|
file+='.rb' unless File.exist? file
|
|
|
|
|
system "ruby #{file}"
|
|
|
|
|
|
|
|
|
|
when 'ln' then
|
|
|
|
|
abort "#{ARGV[1]} is not a directory" unless File.directory? ARGV[1]
|
|
|
|
|
|
|
|
|
|
#TODO check is under +/ with name AND version
|
|
|
|
|
#TODO you should mkdirs as you find them and symlink files otherwise
|
|
|
|
|
#TODO consider using hardlinks
|
|
|
|
|
|
|
|
|
|
Find.find ARGV[1] do |from|
|
|
|
|
|
next if from == ARGV[1] #rubysucks
|
|
|
|
|
|
|
|
|
|
from=Pathname.new from
|
2009-05-21 01:21:20 +01:00
|
|
|
to=$root+from.relative_path_from(Pathname.new(ARGV[1]))
|
2009-05-21 00:04:43 +01:00
|
|
|
|
|
|
|
|
if from.directory?
|
2009-05-21 01:21:20 +01:00
|
|
|
to.mkpath unless to.exist?
|
2009-05-21 00:04:43 +01:00
|
|
|
elsif from.file?
|
2009-05-21 01:21:20 +01:00
|
|
|
tod=to.dirname
|
|
|
|
|
Dir.chdir(tod) { `ln -s #{from.relative_path_from tod}` }
|
2009-05-21 00:04:43 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
when 'prune', 'pasteurize' then
|
|
|
|
|
$root.find do |path|
|
|
|
|
|
if path.directory?
|
|
|
|
|
name=path.basename
|
2009-05-21 01:15:47 +01:00
|
|
|
Find.prune if name == 'Cellar' or name == 'Formula'
|
2009-05-21 00:04:43 +01:00
|
|
|
elsif path.symlink?
|
|
|
|
|
path.unlink unless path.readlink.exist?
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
puts "usage: #{$0} [prune] [ln path]"
|
|
|
|
|
end
|