Permalink
Browse files

- Add --prefix flag for prefixing paths before packaging. This is not

  necessary for 'gem'.
  Example, package up /etc but install to /server/$(hostname) or
  something fun:
    fpm -s dir -t deb --prefix /server/$(hostname) /etc

  This is useful for packages/directories that you would prefer
  installed in a specific heirarchy.
  • Loading branch information...
1 parent f288c1b commit d403c461f5a1f1f51ad0012b2571fe17c64589fc @jordansissel committed Jan 8, 2011
Showing with 40 additions and 5 deletions.
  1. +5 −0 bin/fpm
  2. +3 −2 lib/fpm/builder.rb
  3. +1 −1 lib/fpm/source.rb
  4. +31 −2 lib/fpm/source/dir.rb
View
@@ -59,6 +59,11 @@ def main(args)
opts.on("-s SOURCE_TYPE", "what to build the package from") do |st|
settings.source_type = st
end
+
+ opts.on("--prefix PREFIX",
+ "A path to prefix files with when building the target package. This may not be necessary for all source types. For example, the 'gem' type will prefix with your gem directory (gem env | grep -A1 PATHS:)") do |prefix|
+ settings.prefix = prefix
+ end
end # OptionParser
opts.parse!(args)
View
@@ -33,7 +33,8 @@ def initialize(settings, paths=[])
@source = source_class_for(settings.source_type || 'dir').new(
paths, root,
:version => settings.version,
- :name => settings.package_name
+ :name => settings.package_name,
+ :prefix => settings.prefix
)
@package = package_class_for(settings.package_type).new(@source)
@@ -57,7 +58,7 @@ def assemble!
make_builddir!
::Dir.chdir root do
- @source.make_tarball!(tar_path)
+ @source.make_tarball!(tar_path, builddir)
generate_md5sums
generate_specfile
View
@@ -50,7 +50,7 @@ def get_source(params)
# noop by default
end # def get_source
- def make_tarball!(tar_path)
+ def make_tarball!(tar_path, builddir)
raise NoMethodError,
"Please subclass FPM::Source and define make_tarball!(tar_path)"
end
View
@@ -1,12 +1,41 @@
require "fpm/source"
+require "fileutils"
class FPM::Source::Dir < FPM::Source
def get_metadata
self[:name] = File.basename(File.expand_path(root))
end
- def make_tarball!(tar_path)
- tar(tar_path, paths)
+ def make_tarball!(tar_path, builddir)
+ if self[:prefix]
+ self[:prefix] = self[:prefix][1..-1] if self[:prefix] =~ /^\//
+ # Prefix all files with a path.
+ FileUtils.mkdir_p(self[:prefix])
+ paths.each do |path|
+ # Trim @root (--chdir)
+ path = path[@root.size .. -1] if path.start_with?(@root)
+
+ # Copy to self[:prefix] (aka --prefix)
+ dest = "#{builddir}/tarbuild/#{self[:prefix]}/#{path}"
+ FileUtils.mkdir_p(dest)
+ rsync = ["rsync", "-a", path, dest]
+ system(*rsync)
+
+ # FileUtils.cp_r is pretty silly about how it copies files in some
+ # cases (funky permissions, etc)
+ # Use rsync instead..
+ #FileUtils.cp_r(path, dest)
+ end
+ ::Dir.chdir("#{builddir}/tarbuild") do
+ puts "TAR"
+ puts tar_path
+ puts "#{builddir}/tarbuild"
+ system("ls #{builddir}/tarbuild")
+ tar(tar_path, ".")
+ end
+ else
+ tar(tar_path, paths)
+ end
# TODO(sissel): Make a helper method.
system(*["gzip", "-f", tar_path])

0 comments on commit d403c46

Please sign in to comment.