2000-10-17 14:46:04 +00:00
|
|
|
#!/usr/local/bin/ruby
|
2001-01-06 17:11:40 +00:00
|
|
|
# pkg-plist generator by Brian Fundakowski Feldman <green@FreeBSD.org>
|
|
|
|
# (public domain)
|
|
|
|
# $FreeBSD$
|
|
|
|
|
2000-10-17 14:46:04 +00:00
|
|
|
class Plist
|
2001-01-06 17:11:40 +00:00
|
|
|
def initialize(no_manpages = true, mtree = [])
|
2000-10-17 14:46:04 +00:00
|
|
|
@no_manpages = no_manpages
|
2001-01-06 17:11:40 +00:00
|
|
|
@mtree = mtree
|
2000-10-17 14:46:04 +00:00
|
|
|
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!
|
2001-01-06 17:11:40 +00:00
|
|
|
# Strip mtree-created directories
|
|
|
|
if level > 0 && !@mtree.find {|x| x == thiswd}
|
2000-10-17 14:46:04 +00:00
|
|
|
subs.push('@dirrm ' + thiswd)
|
|
|
|
end
|
|
|
|
return subs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2001-01-06 17:11:40 +00:00
|
|
|
class Mtree
|
|
|
|
def initialize(strip = 1)
|
|
|
|
@paths = []
|
|
|
|
@curlevel = []
|
|
|
|
@strip = strip.to_i
|
2004-02-27 21:01:02 +00:00
|
|
|
@curline = ''
|
|
|
|
@global_settings = {}
|
2001-01-06 17:11:40 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
def parse_line(line)
|
|
|
|
line.chomp!
|
2004-02-27 21:01:02 +00:00
|
|
|
if line.empty? || line[0, 1] == '#'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if line[-1, 1] == "\\"
|
|
|
|
@curline.concat(line[0..-2])
|
|
|
|
next
|
|
|
|
end
|
|
|
|
line = @curline + line
|
|
|
|
@curline = ''
|
|
|
|
case line[/\S.+/]
|
|
|
|
when /^\/(\S+)/
|
|
|
|
case $1
|
|
|
|
when 'set'
|
|
|
|
$'.split.each {|setting|
|
|
|
|
key, value, = setting.split(/=/)
|
|
|
|
@global_settings[key] = value
|
|
|
|
}
|
|
|
|
when 'unset'
|
|
|
|
$'.split.each {|setting| @global_settings.delete(setting)}
|
|
|
|
else
|
|
|
|
raise "invalid command \"#{$1}\""
|
2001-03-13 01:53:04 +00:00
|
|
|
end
|
2004-02-27 21:01:02 +00:00
|
|
|
when '..'
|
2001-01-06 17:11:40 +00:00
|
|
|
if @curlevel.pop.nil?
|
|
|
|
raise '".." with no previous directory'
|
|
|
|
end
|
|
|
|
else
|
2004-02-27 21:01:02 +00:00
|
|
|
spline = line.split()
|
|
|
|
path = spline[0]
|
|
|
|
settings = @global_settings.dup
|
|
|
|
if spline.size > 1
|
|
|
|
spline[1..-1].each {|setting|
|
|
|
|
key, value, = setting.split(/=/)
|
|
|
|
settings[key] = value
|
|
|
|
}
|
|
|
|
end
|
|
|
|
@paths.push(@curlevel + [path])
|
|
|
|
if settings['type'] == nil || settings['type'] == 'dir'
|
|
|
|
@curlevel.push(path)
|
2001-03-13 01:53:04 +00:00
|
|
|
end
|
2001-01-06 17:11:40 +00:00
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def Mtree.read(filename)
|
|
|
|
m = Mtree.new
|
|
|
|
open(filename, 'r') {|file|
|
2001-03-13 01:53:04 +00:00
|
|
|
file.each_line {|line| m.parse_line(line)}
|
2001-01-06 17:11:40 +00:00
|
|
|
}
|
|
|
|
m
|
|
|
|
end
|
2001-03-13 01:53:04 +00:00
|
|
|
def paths(strip = @strip)
|
|
|
|
@paths.collect {|path| path[strip..-1].join('/')}
|
2001-01-06 17:11:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-10-17 14:46:04 +00:00
|
|
|
if __FILE__ == $0
|
2001-01-06 17:11:40 +00:00
|
|
|
require 'getopts'
|
2002-03-11 03:11:03 +00:00
|
|
|
if !getopts('Md', 'm:') || ARGV.size != 1
|
2000-10-17 14:46:04 +00:00
|
|
|
$stderr.print <<-USAGE_EOF
|
2002-03-11 03:11:03 +00:00
|
|
|
usage: #{$0} [-Md] [-m mtree] somepath
|
2000-10-17 14:46:04 +00:00
|
|
|
Generate a pkg-plist to stdout given a previously empty somepath which
|
2001-01-06 17:11:40 +00:00
|
|
|
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.
|
2002-03-11 03:11:03 +00:00
|
|
|
The -d argument puts all @dirrm commands at the end of the plist.
|
2000-10-17 14:46:04 +00:00
|
|
|
USAGE_EOF
|
|
|
|
exit 1
|
|
|
|
end
|
2001-01-06 17:11:40 +00:00
|
|
|
mtree = $OPT_m || '/etc/mtree/BSD.local.dist'
|
2002-03-11 03:11:03 +00:00
|
|
|
pl = Plist.new(!$OPT_M, Mtree.read(mtree).paths).make(ARGV[0])
|
|
|
|
if $OPT_d
|
|
|
|
plnotdirrm = []
|
|
|
|
pldirrm = []
|
|
|
|
pl.each {|ent|
|
|
|
|
if ent =~ /^@dirrm /
|
|
|
|
pldirrm.push(ent)
|
|
|
|
else
|
|
|
|
plnotdirrm.push(ent)
|
|
|
|
end
|
2003-03-28 05:08:03 +00:00
|
|
|
plnotdirrm.sort!
|
|
|
|
pldirrm.sort!
|
|
|
|
pl = plnotdirrm + pldirrm.reverse
|
2002-03-11 03:11:03 +00:00
|
|
|
}
|
2003-03-28 05:08:03 +00:00
|
|
|
else
|
|
|
|
pl.sort!
|
2002-03-11 03:11:03 +00:00
|
|
|
end
|
|
|
|
puts(pl.join("\n"))
|
2000-10-17 14:46:04 +00:00
|
|
|
end
|