mirror of
https://git.FreeBSD.org/ports.git
synced 2024-12-28 05:29:48 +00:00
9725d8378f
mtree files.
100 lines
2.2 KiB
Ruby
Executable File
100 lines
2.2 KiB
Ruby
Executable File
#!/usr/local/bin/ruby
|
|
# pkg-plist generator by Brian Fundakowski Feldman <green@FreeBSD.org>
|
|
# (public domain)
|
|
# $FreeBSD$
|
|
|
|
class Plist
|
|
def initialize(no_manpages = true, mtree = [])
|
|
@no_manpages = no_manpages
|
|
@mtree = mtree
|
|
self
|
|
end
|
|
def make(dir)
|
|
@root = dir.to_s + '/'
|
|
imake('', 0, '')
|
|
end
|
|
private
|
|
def imake(dir, level, prevwd)
|
|
thiswd = prevwd + dir # always ends in '/'
|
|
rootedwd = @root + thiswd
|
|
subs = []
|
|
Dir.foreach(rootedwd) {|dirent|
|
|
next if dirent =~ /^\.\.?$/
|
|
if test(?d, rootedwd + dirent)
|
|
subs.concat(imake(dirent + '/', level + 1, thiswd))
|
|
else
|
|
if thiswd !~ /^man\// || !@no_manpages
|
|
subs.push(thiswd + dirent)
|
|
end
|
|
end
|
|
}
|
|
thiswd.chop!
|
|
# Strip mtree-created directories
|
|
if level > 0 && !@mtree.find {|x| x == thiswd}
|
|
subs.push('@dirrm ' + thiswd)
|
|
end
|
|
return subs
|
|
end
|
|
end
|
|
|
|
class Mtree
|
|
def initialize(strip = 1)
|
|
@paths = []
|
|
@curlevel = []
|
|
@strip = strip.to_i
|
|
@cont = false
|
|
self
|
|
end
|
|
def parse_line(line)
|
|
line.chomp!
|
|
spline = line.split
|
|
oldcont = @cont
|
|
@cont = line[-1, 1] == "\\"
|
|
case spline[0]
|
|
when nil
|
|
when /^[\/#]/
|
|
# ignore "command" lines and comments
|
|
when '..'
|
|
if oldcont
|
|
raise 'continued line has a .. directive?!'
|
|
end
|
|
if @curlevel.pop.nil?
|
|
raise '".." with no previous directory'
|
|
end
|
|
else
|
|
if !oldcont
|
|
@curlevel.push(spline[0])
|
|
@paths.push(@curlevel.dup)
|
|
end
|
|
end
|
|
self
|
|
end
|
|
def Mtree.read(filename)
|
|
m = Mtree.new
|
|
open(filename, 'r') {|file|
|
|
file.each_line {|line| m.parse_line(line)}
|
|
}
|
|
m
|
|
end
|
|
def paths(strip = @strip)
|
|
@paths.collect {|path| path[strip..-1].join('/')}
|
|
end
|
|
end
|
|
|
|
if __FILE__ == $0
|
|
require 'getopts'
|
|
if !getopts('M', 'm:') || ARGV.size != 1
|
|
$stderr.print <<-USAGE_EOF
|
|
usage: #{$0} [-M] [-m mtree] somepath
|
|
Generate a pkg-plist to stdout given a previously empty somepath which
|
|
a port has been installed into (PREFIX=somepath). The mtree file is
|
|
consulted to prevent base directories from being added to the plist.
|
|
The -M argument allows manpages to be added to the plist.
|
|
USAGE_EOF
|
|
exit 1
|
|
end
|
|
man = $OPT_M || true
|
|
mtree = $OPT_m || '/etc/mtree/BSD.local.dist'
|
|
puts Plist.new(man, Mtree.read(mtree).paths).make(ARGV[0]).join("\n")
|
|
end
|