Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- seems to work. Missing a few features, but it works :)

  • Loading branch information...
commit 4bcb64fc57734a354a6ee149c797abe8805524de 1 parent ee9f00d
Jordan Sissel authored
4 lib/fpm/builder.rb
View
@@ -1,4 +1,6 @@
-require 'fileutils'
+require "fileutils"
+require "pathname"
+
class FPM::Builder
# where is the package's root?
def root
12 lib/fpm/package.rb
View
@@ -154,4 +154,16 @@ def default_output
"#{name}-#{version}.#{architecture}.#{type}"
end
end # def default_output
+
+ def fixpath(path)
+ if path.first != "/"
+ path = File.join(@source.root, path)
+ end
+ return path if File.symlink?(path)
+ realpath = Pathname.new(path).realpath.to_s
+ re = Regexp.new("^#{Regexp.escape(@source.root)}")
+ realpath.gsub!(re, "")
+ #p :realpath => [path, realpath]
+ return realpath
+ end # def fixpath
end # class FPM::Package
2  lib/fpm/target/deb.rb
View
@@ -122,5 +122,5 @@ def fix_dependency(dep)
return dep
end
end # def fix_dependency
-end # class FPM::Deb
+end # class FPM::Target::Deb
63 lib/fpm/target/puppet.rb
View
@@ -2,6 +2,9 @@
require "fpm/namespace"
require "fpm/package"
require "fpm/errors"
+require "etc"
+
+require "fileutils" # for FileUtils
# TODO(sissel): Add dependency checking support.
# IIRC this has to be done as a 'checkinstall' step.
@@ -15,10 +18,11 @@ def architecture
end # def architecture
def specfile(builddir)
- "#{builddir}/pacakge.pp"
+ "#{builddir}/package.pp"
end # def specfile
def build!(params)
+ # TODO(sissel): Support these somehow, perhaps with execs and files.
self.scripts.each do |name, path|
case name
when "pre-install"
@@ -28,24 +32,55 @@ def build!(params)
end # case name
end # self.scripts.each
- # Unpack data.tar.gz
- Dir.mkdir("files")
- Dir.mkdir("manifests")
- system("gzip -d data.tar.gz");
- Dir.chdir("files") { system("tar -xf ../data.tar") }
+ Dir.mkdir(params[:output])
+ builddir = Dir.pwd
+ data_tarball = File.join(builddir, "data.tar.gz")
+
+ Dir.chdir(params[:output]) do
+ # Unpack data.tar.gz
+ Dir.mkdir("files")
+ system("gzip -d #{data_tarball}");
+ Dir.chdir("files") { system("tar -xf #{data_tarball.gsub(/.gz$/, "")}") }
+ Dir.mkdir("manifests")
+ FileUtils.cp(specfile(builddir), "manifests")
+ end
# Files are now in the 'files' path
# Generate a manifest 'package.pp' with all the information from
end # def build!
+ # The directory we create should just be the name of the package as the
+ # module name
def default_output
- v = version
- v = "#{epoch}:#{v}" if epoch
- if iteration
- "#{name}_#{v}-#{iteration}_#{architecture}.#{type}"
- else
- "#{name}_#{v}_#{architecture}.#{type}"
- end
+ name
end # def default_output
-end # class FPM::Deb
+
+ def puppetsort(hash)
+ # TODO(sissel): Implement sorting that follows the puppet style guide
+ # Such as, 'ensure' goes first, etc.
+ return hash.to_a
+ end # def puppetsort
+
+ def uid2user(uid)
+ begin
+ pwent = Etc.getpwuid(uid)
+ return pwent.name
+ rescue ArgumentError => e
+ # Invalid user id? No user? Return the uid.
+ @logger.warn("Failed to find username for uid #{uid}")
+ return uid.to_s
+ end
+ end # def uid2user
+
+ def gid2group(gid)
+ begin
+ grent = Etc.getgrgid(gid)
+ return grent.name
+ rescue ArgumentError => e
+ # Invalid user id? No user? Return the uid.
+ @logger.warn("Failed to find group for gid #{gid}")
+ return gid.to_s
+ end
+ end # def uid2user
+end # class FPM::Target::Puppet
5 lib/fpm/target/rpm.rb
View
@@ -45,6 +45,5 @@ def build!(params)
# This should only output one rpm, should we verify this?
system("mv", path, params[:output])
end
-
- end
-end
+ end # def build!
+end # class FPM::Target::RPM
22 templates/puppet.erb
View
@@ -1,4 +1,7 @@
+# TODO(sissel): implement 'anti' class for this package.
class <%= name %>::package {
+ $version = "<%= version %>"
+ $iteration = "<%= iteration %>"
file {
<% paths.each do |path|
@@ -12,11 +15,20 @@ class <%= name %>::package {
stat = File.stat(path)
else
params[:ensure] = "file"
+ params[:source] = "puppet:///modules/#{name}/#{path}"
+ end
+
+ if params[:ensure] != "link"
+ params[:owner] = uid2user(stat.uid)
+ params[:group] = gid2group(stat.gid)
+ params[:mode] = sprintf("%04o", stat.mode & 0777)
end
- settings = params.collect { |k,v| "#{k} = \"#{v}\"" }.join(",")
--%>
- "<%= path %>":
- <%= settings %>
-<% end -%>
+ settings = puppetsort(params).collect { |k,v| "#{k} => \"#{v}\"" }.join(",\n ")
+-%>
+ # <%= stat.inspect %>
+ "<%= fixpath(path) %>":
+ <%= settings %>;
+<% end # paths.each -%>
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.