2009-08-31 16:01:36 +01:00
|
|
|
# Copyright 2009 Max Howell and other contributors.
|
2009-07-24 15:10:01 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
2009-07-24 15:10:01 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
2009-07-24 15:10:01 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2009-08-10 16:48:30 +01:00
|
|
|
#
|
|
|
|
class Keg <Pathname
|
|
|
|
def initialize path
|
|
|
|
super path
|
|
|
|
raise "#{to_s} is not a valid keg" unless parent.parent == HOMEBREW_CELLAR
|
|
|
|
raise "#{to_s} is not a directory" unless directory?
|
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
def uninstall
|
|
|
|
chmod_R 0777 # ensure we have permission to delete
|
|
|
|
rmtree
|
|
|
|
parent.rmdir_if_possible
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
|
2009-08-29 21:07:26 +01:00
|
|
|
def unlink
|
|
|
|
n=0
|
|
|
|
Pathname.new(self).find do |src|
|
|
|
|
next if src == self
|
|
|
|
dst=HOMEBREW_PREFIX+src.relative_path_from(self)
|
|
|
|
next unless dst.symlink?
|
|
|
|
dst.unlink
|
|
|
|
n+=1
|
|
|
|
Find.prune if src.directory?
|
|
|
|
end
|
|
|
|
n
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
def link
|
|
|
|
$n=0
|
|
|
|
$d=0
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
mkpaths=(1..9).collect {|x| "man/man#{x}"} <<'man'<<'doc'<<'locale'<<'info'<<'aclocal'
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
# yeah indeed, you have to force anything you need in the main tree into
|
|
|
|
# these dirs REMEMBER that *NOT* everything needs to be in the main tree
|
|
|
|
link_dir('etc') {:mkpath}
|
2009-08-23 19:05:42 +01:00
|
|
|
link_dir('bin') {:skip}
|
2009-08-12 09:43:16 +08:00
|
|
|
link_dir('sbin') {:link}
|
2009-08-10 16:48:30 +01:00
|
|
|
link_dir('include') {:link}
|
|
|
|
link_dir('share') {|path| :mkpath if mkpaths.include? path.to_s}
|
2009-07-29 00:56:22 +01:00
|
|
|
|
2009-09-17 21:26:17 +01:00
|
|
|
link_dir('lib') do |path|
|
|
|
|
case path.to_s
|
|
|
|
when /^pkgconfig/ then :mkpath
|
|
|
|
when /^php/ then :mkpath
|
|
|
|
when /^perl5/ then :mkpath
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
return $n+$d
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2009-08-10 16:48:30 +01:00
|
|
|
# symlinks the contents of self+foo recursively into /usr/local/foo
|
|
|
|
def link_dir foo
|
|
|
|
root=self+foo
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
root.find do |src|
|
|
|
|
next if src == root
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
dst=HOMEBREW_PREFIX+src.relative_path_from(self)
|
|
|
|
dst.extend ObserverPathnameExtension
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
if src.file?
|
|
|
|
dst.make_relative_symlink src
|
|
|
|
elsif src.directory?
|
2009-07-24 15:10:01 +01:00
|
|
|
# no need to put .app bundles in the path, the user can just use
|
|
|
|
# spotlight, or the open command and actual mac apps use an equivalent
|
2009-08-10 16:48:30 +01:00
|
|
|
Find.prune if src.extname.to_s == '.app'
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
case yield src.relative_path_from(root)
|
|
|
|
when :skip then Find.prune
|
|
|
|
when :mkpath then dst.mkpath
|
|
|
|
else dst.make_relative_symlink src; Find.prune
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|