Cross package maker. DEB/RPM generation or conversion. Derived from jordansissel/fpm.

⌈⌋ ⎇ branch:  cross package maker


Check-in [3f92e4ba03]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:- work-in-progress making it so you can conver rpms to puppet modules.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3f92e4ba03f94e893e1159d20265cf1f94b647a0
User & Date: jls@semicomplete.com 2011-06-19 08:15:00
Context
2011-06-20
05:17
Merge branch 'feature/puppet' of github.com:jordansissel/fpm into feature/puppet check-in: 4292cd85b6 user: jls@semicomplete.com tags: trunk
2011-06-19
08:15
- work-in-progress making it so you can conver rpms to puppet modules. check-in: 3f92e4ba03 user: jls@semicomplete.com tags: trunk
07:17
- seems to work. Missing a few features, but it works :) check-in: 76c074cf6e user: jls@semicomplete.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/fpm/builder.rb.

81
82
83
84
85
86
87
















88
89
90
91
92
93
94

    File.delete(output) if File.exists?(output) && !File.directory?(output)

    make_builddir!

    ::Dir.chdir root do
      @source.make_tarball!(tar_path, builddir)

















      generate_md5sums if @package.needs_md5sums
      generate_specfile
      edit_specfile if @edit
    end

    ::Dir.chdir(builddir) do







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

    File.delete(output) if File.exists?(output) && !File.directory?(output)

    make_builddir!

    ::Dir.chdir root do
      @source.make_tarball!(tar_path, builddir)

      # Hack to unpack before generating the spec, etc.
      # Need to formalize this feature.
      # Perhaps something like @package.prepare
      if @package.respond_to?(:unpack_data_to)
        data_tarball = File.join(builddir, "data.tar.gz")
        FileUtils.mkdir_p(output)
        Dir.chdir(output) do
          FileUtils.mkdir_p(@package.unpack_data_to)
          system("gzip -d #{data_tarball}")
          Dir.chdir(@package.unpack_data_to) do
            @source.root = Dir.pwd
            system("tar -xf #{data_tarball.gsub(/\.gz$/, "")}")
          end
        end
      end

      generate_md5sums if @package.needs_md5sums
      generate_specfile
      edit_specfile if @edit
    end

    ::Dir.chdir(builddir) do

Changes to lib/fpm/package.rb.

140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169

  def render_spec
    # find all files in paths given.
    paths = []
    @source.paths.each do |path|
      Find.find(path) { |p| paths << p }
    end

    template.result(binding)
  end # def render_spec

  def default_output
    if iteration
      "#{name}-#{version}-#{iteration}.#{architecture}.#{type}"
    else
      "#{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







>












>







|



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

  def render_spec
    # find all files in paths given.
    paths = []
    @source.paths.each do |path|
      Find.find(path) { |p| paths << p }
    end
    #@logger.info(:paths => paths.sort)
    template.result(binding)
  end # def render_spec

  def default_output
    if iteration
      "#{name}-#{version}-#{iteration}.#{architecture}.#{type}"
    else
      "#{name}-#{version}.#{architecture}.#{type}"
    end
  end # def default_output

  def fixpath(path)
    p :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 :fixpath => {:path => realpath, :caller => caller[0] }
    return realpath
  end # def fixpath
end # class FPM::Package

Changes to lib/fpm/source.rb.

19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
  end

  def dependencies
    self[:dependencies] ||= []
  end

  attr_reader :paths

  attr_reader :root
  def initialize(paths, root, params={})
    @paths = paths
    @root = root

    self[:suffix] = params[:suffix]
    self[:settings] = params[:settings]








>
|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  end

  def dependencies
    self[:dependencies] ||= []
  end

  attr_reader :paths
  attr_accessor :root

  def initialize(paths, root, params={})
    @paths = paths
    @root = root

    self[:suffix] = params[:suffix]
    self[:settings] = params[:settings]

Changes to lib/fpm/source/rpm.rb.

1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


24
25
26
27
28
require "fpm/source"

class FPM::Source::RPM < FPM::Source
  def get_metadata

    self[:name] = %x{rpm -q --qf '%{name}' -p #{@paths.first}}

    self[:version] = %x{rpm -q --qf '%{version}' -p #{@paths.first}}
    self[:iteration] = %x{rpm -q --qf '%{release}' -p #{@paths.first}}
    self[:summary] = %x{rpm -q --qf '%{summary}' -p #{@paths.first}}
    #self[:description] = %x{rpm -q --qf '%{description}' -p #{@paths.first}}
    self[:dependencies] = %x{rpm -qRp #{@paths.first}}.split("\n")\
      .collect { |line| line.strip }

    @rpm = @paths.first
    @paths = %x{rpm -qlp #{@paths.first}}.split("\n")

  end

  def make_tarball!(tar_path, builddir)
    tmpdir = "#{tar_path}.dir"
    ::Dir.mkdir(tmpdir)
    system("rpm2cpio #{@rpm} | (cd #{tmpdir}; cpio -i --make-directories)")
    tar(tar_path, ".", tmpdir)



    # TODO(sissel): Make a helper method.
    system(*["gzip", "-f", tar_path])
  end
end




>
|

|
|
|
|
|


<
|
<







>
>





1
2
3
4
5
6
7
8
9
10
11
12
13
14

15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
require "fpm/source"

class FPM::Source::RPM < FPM::Source
  def get_metadata
    @rpm = @paths.first
    self[:name] = %x{rpm -q --qf '%{name}' -p #{@rpm}}

    self[:version] = %x{rpm -q --qf '%{version}' -p #{@rpm}}
    self[:iteration] = %x{rpm -q --qf '%{release}' -p #{@rpm}}
    self[:summary] = %x{rpm -q --qf '%{summary}' -p #{@rpm}}
    #self[:description] = %x{rpm -q --qf '%{description}' -p #{@rpm}}
    self[:dependencies] = %x{rpm -qRp #{@rpm}}.split("\n")\
      .collect { |line| line.strip }


    @paths = %x{rpm -qlp #{@rpm}}.split("\n")

  end

  def make_tarball!(tar_path, builddir)
    tmpdir = "#{tar_path}.dir"
    ::Dir.mkdir(tmpdir)
    system("rpm2cpio #{@rpm} | (cd #{tmpdir}; cpio -i --make-directories)")
    tar(tar_path, ".", tmpdir)
    @paths = "."
    @root = tmpdir

    # TODO(sissel): Make a helper method.
    system(*["gzip", "-f", tar_path])
  end
end

Changes to lib/fpm/target/puppet.rb.

16
17
18
19
20
21
22




23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    end
    return @architecture
  end # def architecture

  def specfile(builddir)
    "#{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"
        when "post-install"
        when "pre-uninstall"
        when "post-uninstall"
      end # case name
    end # self.scripts.each

    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!








>
>
>
>














<


<
<
<
<
<







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42





43
44
45
46
47
48
49
    end
    return @architecture
  end # def architecture

  def specfile(builddir)
    "#{builddir}/package.pp"
  end # def specfile

  def unpack_data_to
    "files"
  end

  def build!(params)
    # TODO(sissel): Support these somehow, perhaps with execs and files.
    self.scripts.each do |name, path|
      case name
        when "pre-install"
        when "post-install"
        when "pre-uninstall"
        when "post-uninstall"
      end # case name
    end # self.scripts.each

    Dir.mkdir(params[:output])
    builddir = Dir.pwd


    Dir.chdir(params[:output]) do





      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!