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

⌈⌋ ⎇ branch:  cross package maker


Check-in [3e59e52c89]

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

Overview
Comment:Add "safesystem" function Basically, its a replacement for system. If the command fails, then it raises an exception and prints out the entire command that was attempted. This will prevent issues where fpm finished (with return code 0) and produces an artifact with real size (>0 bytes) but the artifact is worthless as it contains nothing. Fixes #86
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3e59e52c89a75d4f7da2ebc21eb02815fa710f53
User & Date: tabletcorry@gmail.com 2011-08-02 03:35:56
Context
2011-08-18
02:17
Add --python-package-prefix option Allows the prefix of packages to change to a user specified value. Useful if you do not want to conflict with other python packages, or want to install to a special ruby instance check-in: 063ec0e05a user: tabletcorry@gmail.com tags: trunk
2011-08-02
03:35
Add "safesystem" function Basically, its a replacement for system. If the command fails, then it raises an exception and prints out the entire command that was attempted. This will prevent issues where fpm finished (with return code 0) and produces an artifact with real size (>0 bytes) but the artifact is worthless as it contains nothing. Fixes #86 check-in: 3e59e52c89 user: tabletcorry@gmail.com tags: trunk
2011-07-28
17:56
Add --gem-package-prefix option Allows the prefix of packages to change to a user specified value. Useful if you do not want to conflict with other rubygem packages, or want to install to a special ruby instance Fixes #84 check-in: 7c46384d51 user: tabletcorry@gmail.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/fpm/builder.rb.

1

2
3
4
5
6
7
8
require "fileutils"

require "pathname"

class FPM::Builder
  # where is the package's root?
  def root
    @root ||= (@source.root || '.')
  end

>







1
2
3
4
5
6
7
8
9
require "fileutils"
require "fpm/util"
require "pathname"

class FPM::Builder
  # where is the package's root?
  def root
    @root ||= (@source.root || '.')
  end
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
      # 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")
        Dir.chdir(builddir) 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







|


|







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
      # 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")
        Dir.chdir(builddir) do
          FileUtils.mkdir_p(@package.unpack_data_to)
          safesystem("gzip -d #{data_tarball}")
          Dir.chdir(@package.unpack_data_to) do
            @source.root = Dir.pwd
            safesystem("tar -xf #{data_tarball.gsub(/\.gz$/, "")}")
          end
        end
      end

      generate_md5sums if @package.needs_md5sums
      generate_specfile
      edit_specfile if @edit
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
  end

  private
  def edit_specfile
    # TODO(sissel): support editing multiple files for targets like
    # puppet which generate multiple manifests.
    editor = ENV['FPM_EDITOR'] || ENV['EDITOR'] || 'vi'
    system("#{editor} '#{package.specfile(builddir)}'")
    unless File.size? package.specfile(builddir)
      puts "Empty specfile.  Aborting."
      exit 1
    end
  end

  private







|







182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
  end

  private
  def edit_specfile
    # TODO(sissel): support editing multiple files for targets like
    # puppet which generate multiple manifests.
    editor = ENV['FPM_EDITOR'] || ENV['EDITOR'] || 'vi'
    safesystem("#{editor} '#{package.specfile(builddir)}'")
    unless File.size? package.specfile(builddir)
      puts "Empty specfile.  Aborting."
      exit 1
    end
  end

  private

Changes to lib/fpm/source.rb.

1

2
3
4
5
6
7
8
require "fpm/namespace"


# Abstract class for a "thing to build a package from"
class FPM::Source
  # standard package metadata
  %w(
    name
    version

>







1
2
3
4
5
6
7
8
9
require "fpm/namespace"
require "fpm/util"

# Abstract class for a "thing to build a package from"
class FPM::Source
  # standard package metadata
  %w(
    name
    version
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    # than it is worth. For now, rely on tar's --exclude.
    dir_tar = [tar_cmd, "--owner=root", "--group=root" ] \
              + excludes \
              + ["-cf", output, "--no-recursion" ] \
              + dirs

    ::Dir.chdir(chdir) do
      system(*dir_tar) if dirs.any?
    end

    files_tar = [ tar_cmd ] \
                + excludes \
                + [ "--owner=root", "--group=root", "-rf", output ] \
                + paths
    ::Dir.chdir(chdir) do
      system(*files_tar)
    end
  end # def tar

  def tar_cmd
    # Rely on gnu tar for solaris.
    case %x{uname -s}.chomp
    when "SunOS"
      return "gtar"
    else
      return "tar"
    end
  end # def tar_cmd
end # class FPM::Source







|







|













121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
    # than it is worth. For now, rely on tar's --exclude.
    dir_tar = [tar_cmd, "--owner=root", "--group=root" ] \
              + excludes \
              + ["-cf", output, "--no-recursion" ] \
              + dirs

    ::Dir.chdir(chdir) do
      safesystem(*dir_tar) if dirs.any?
    end

    files_tar = [ tar_cmd ] \
                + excludes \
                + [ "--owner=root", "--group=root", "-rf", output ] \
                + paths
    ::Dir.chdir(chdir) do
      safesystem(*files_tar)
    end
  end # def tar

  def tar_cmd
    # Rely on gnu tar for solaris.
    case %x{uname -s}.chomp
    when "SunOS"
      return "gtar"
    else
      return "tar"
    end
  end # def tar_cmd
end # class FPM::Source

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

1
2
3

4
5
6
7
8
9
10
require "fpm/source"
require "fileutils"
require "fpm/rubyfixes"


class FPM::Source::Dir < FPM::Source
  def get_metadata
    self[:name] = File.basename(File.expand_path(root))
  end

  def make_tarball!(tar_path, builddir)



>







1
2
3
4
5
6
7
8
9
10
11
require "fpm/source"
require "fileutils"
require "fpm/rubyfixes"
require "fpm/util"

class FPM::Source::Dir < FPM::Source
  def get_metadata
    self[:name] = File.basename(File.expand_path(root))
  end

  def make_tarball!(tar_path, builddir)
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
52
53
54
55
56
57
58
        else
          dest = "#{builddir}/tarbuild/#{self[:prefix]}/#{File.dirname(path)}"
        end

        ::FileUtils.mkdir_p(dest)
        rsync = ["rsync", "-a", path, dest]
        p rsync
        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

      # Prefix paths with 'prefix' if necessary.
      if self[:prefix]
        @paths = @paths.collect { |p| File.join("/", self[:prefix], p) }
      end

      ::Dir.chdir("#{builddir}/tarbuild") do
        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])
  end # def make_tarball!
end # class FPM::Source::Dir







|













|







|


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
        else
          dest = "#{builddir}/tarbuild/#{self[:prefix]}/#{File.dirname(path)}"
        end

        ::FileUtils.mkdir_p(dest)
        rsync = ["rsync", "-a", path, dest]
        p rsync
        safesystem(*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

      # Prefix paths with 'prefix' if necessary.
      if self[:prefix]
        @paths = @paths.collect { |p| File.join("/", self[:prefix], p) }
      end

      ::Dir.chdir("#{builddir}/tarbuild") do
        safesystem("ls #{builddir}/tarbuild")
        tar(tar_path, ".")
      end
    else
      tar(tar_path, paths)
    end

    # TODO(sissel): Make a helper method.
    safesystem(*["gzip", "-f", tar_path])
  end # def make_tarball!
end # class FPM::Source::Dir

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

1
2
3
4
5

6
7
8
9
10
11
12
require "fpm/namespace"
require "fpm/source"
require "rubygems/package"
require "rubygems"
require "fileutils"


class FPM::Source::Gem < FPM::Source
  def self.flags(opts, settings)
    opts.on("--bin-path DIRECTORY",
            "The directory to install gem executables") do |path|
      settings.source[:bin_path] = path
    end





>







1
2
3
4
5
6
7
8
9
10
11
12
13
require "fpm/namespace"
require "fpm/source"
require "rubygems/package"
require "rubygems"
require "fileutils"
require "fpm/util"

class FPM::Source::Gem < FPM::Source
  def self.flags(opts, settings)
    opts.on("--bin-path DIRECTORY",
            "The directory to install gem executables") do |path|
      settings.source[:bin_path] = path
    end
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
      tmp_bin_path = File.join(tmpdir, self[:settings][:bin_path])
      args += ["--bindir", tmp_bin_path]
      @paths << self[:settings][:bin_path]
      FileUtils.mkdir_p(tmp_bin_path) # Fixes #27
    end

    args << gem
    system(*args)

    # make paths relative  (/foo becomes ./foo)
    tar(tar_path, @paths.collect {|p| ".#{p}"}, tmpdir)
    FileUtils.rm_r(tmpdir)

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

end # class FPM::Source::Gem







|






|



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
      tmp_bin_path = File.join(tmpdir, self[:settings][:bin_path])
      args += ["--bindir", tmp_bin_path]
      @paths << self[:settings][:bin_path]
      FileUtils.mkdir_p(tmp_bin_path) # Fixes #27
    end

    args << gem
    safesystem(*args)

    # make paths relative  (/foo becomes ./foo)
    tar(tar_path, @paths.collect {|p| ".#{p}"}, tmpdir)
    FileUtils.rm_r(tmpdir)

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

end # class FPM::Source::Gem

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

1
2

3
4
5
6
7
8
9
require "fpm/namespace"
require "fpm/source"

require "fileutils"

class FPM::Source::Npm < FPM::Source
  def get_source(params)
    @npm = @paths.first
  end # def get_source



>







1
2
3
4
5
6
7
8
9
10
require "fpm/namespace"
require "fpm/source"
require "fpm/util"
require "fileutils"

class FPM::Source::Npm < FPM::Source
  def get_source(params)
    @npm = @paths.first
  end # def get_source

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

  def make_tarball!(tar_path, builddir)
    tmpdir = "#{tar_path}.dir"
    installdir = "#{tmpdir}/#{::Gem::dir}"
    ::FileUtils.mkdir_p(installdir)
    args = ["gem", "install", "--quiet", "--no-ri", "--no-rdoc",
       "--install-dir", installdir, "--ignore-dependencies", @paths.first]
    system(*args)
    tar(tar_path, ".", tmpdir)

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

end # class FPM::Source::Gem







|



|



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

  def make_tarball!(tar_path, builddir)
    tmpdir = "#{tar_path}.dir"
    installdir = "#{tmpdir}/#{::Gem::dir}"
    ::FileUtils.mkdir_p(installdir)
    args = ["gem", "install", "--quiet", "--no-ri", "--no-rdoc",
       "--install-dir", installdir, "--ignore-dependencies", @paths.first]
    safesystem(*args)
    tar(tar_path, ".", tmpdir)

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

end # class FPM::Source::Gem

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

1
2

3
4
5
6
7
8
9
require "fpm/namespace"
require "fpm/source"

require "rubygems/package"
require "rubygems"
require "fileutils"
require "tmpdir"
require "json"

class FPM::Source::Python < FPM::Source


>







1
2
3
4
5
6
7
8
9
10
require "fpm/namespace"
require "fpm/source"
require "fpm/util"
require "rubygems/package"
require "rubygems"
require "fileutils"
require "tmpdir"
require "json"

class FPM::Source::Python < FPM::Source
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

    if version.nil?
      want_pkg = "#{package}"
    else
      want_pkg = "#{package}==#{version}"
    end

    return_value = system(self[:settings][:easy_install], "--editable", "--build-directory", @tmpdir, want_pkg)

    if return_value.nil?
        raise "The execution of #{self[:settings][:easy_install]} failed"
    end

    # easy_install will put stuff in @tmpdir/packagename/, flatten that.
    #  That is, we want @tmpdir/setup.py, and start with
    #  @tmpdir/somepackage/setup.py
    dirs = ::Dir.glob(File.join(@tmpdir, "*"))
    if dirs.length != 1
      raise "Unexpected directory layout after easy_install. Maybe file a bug? The directory is #{@tmpdir}"







|
<
<
<
<







44
45
46
47
48
49
50
51




52
53
54
55
56
57
58

    if version.nil?
      want_pkg = "#{package}"
    else
      want_pkg = "#{package}==#{version}"
    end

    safesystem(self[:settings][:easy_install], "--editable", "--build-directory", @tmpdir, want_pkg)





    # easy_install will put stuff in @tmpdir/packagename/, flatten that.
    #  That is, we want @tmpdir/setup.py, and start with
    #  @tmpdir/somepackage/setup.py
    dirs = ::Dir.glob(File.join(@tmpdir, "*"))
    if dirs.length != 1
      raise "Unexpected directory layout after easy_install. Maybe file a bug? The directory is #{@tmpdir}"
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  def make_tarball!(tar_path, builddir)
    setup_py = @paths.first
    dir = File.dirname(setup_py)

    # Some setup.py's assume $PWD == current directory of setup.py, so let's
    # chdir first.
    ::Dir.chdir(dir) do
      system(self[:settings][:python], "setup.py", "bdist")
    end

    dist_tar = ::Dir.glob(File.join(dir, "dist", "*.tar.gz")).first
    puts "Found dist tar: #{dist_tar}"
    puts "Copying to #{tar_path}"

    @paths = [ "." ]

    system("cp", dist_tar, "#{tar_path}.gz")
  end # def make_tarball!

  def garbage
    trash = []
    trash << @tmpdir if @tmpdir
    return trash
  end # def garbage

end # class FPM::Source::Gem







|








|









94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  def make_tarball!(tar_path, builddir)
    setup_py = @paths.first
    dir = File.dirname(setup_py)

    # Some setup.py's assume $PWD == current directory of setup.py, so let's
    # chdir first.
    ::Dir.chdir(dir) do
      safesystem(self[:settings][:python], "setup.py", "bdist")
    end

    dist_tar = ::Dir.glob(File.join(dir, "dist", "*.tar.gz")).first
    puts "Found dist tar: #{dist_tar}"
    puts "Copying to #{tar_path}"

    @paths = [ "." ]

    safesystem("cp", dist_tar, "#{tar_path}.gz")
  end # def make_tarball!

  def garbage
    trash = []
    trash << @tmpdir if @tmpdir
    return trash
  end # def garbage

end # class FPM::Source::Gem

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
require "fpm/source"


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

    self[:version] = %x{rpm -q --qf '%{version}' -p #{@rpm}}.chomp
    self[:iteration] = %x{rpm -q --qf '%{release}' -p #{@rpm}}.chomp
    self[:summary] = %x{rpm -q --qf '%{summary}' -p #{@rpm}}.chomp
    #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 = ["."]
    # 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
require "fpm/source"
require "fpm/util"

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

    self[:version] = %x{rpm -q --qf '%{version}' -p #{@rpm}}.chomp
    self[:iteration] = %x{rpm -q --qf '%{release}' -p #{@rpm}}.chomp
    self[:summary] = %x{rpm -q --qf '%{summary}' -p #{@rpm}}.chomp
    #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)
    safesystem("rpm2cpio #{@rpm} | (cd #{tmpdir}; cpio -i --make-directories)")
    tar(tar_path, ".", tmpdir)
    @paths = ["."]
    # TODO(sissel): Make a helper method.
    safesystem(*["gzip", "-f", tar_path])
  end
end

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


1
2
3
4
5
6
7
8
9
10

require "fpm/source"
require "fileutils"
require "fpm/rubyfixes"

class FPM::Source::Tar < FPM::Source
  def get_metadata
    self[:name] = @paths.first.split(".").first
  end # def get_metadata

  def make_tarball!(tar_path, builddir)
>

|
|







1
2
3
4
5
6
7
8
9
10
11
require "fpm/rubyfixes"
require "fpm/source"
require "fpm/util"
require "fileutils"

class FPM::Source::Tar < FPM::Source
  def get_metadata
    self[:name] = @paths.first.split(".").first
  end # def get_metadata

  def make_tarball!(tar_path, builddir)
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    case compression
      when :bzip2; flags += " -j"
      when :gzip; flags += " -z"
      when :lzma; flags += " --lzma"
    end
    #puts("tar #{flags}")
    #sleep 5
    system("tar #{flags}")

    if self[:prefix]
      @paths = [self[:prefix]]
    else
      @paths = ["."]
    end

    ::Dir.chdir("#{builddir}/tarbuild") do
      tar(tar_path, ".")
    end

    # TODO(sissel): Make a helper method.
    system(*["gzip", "-f", tar_path])
  end # def make_tarball!
end # class FPM::Source::Dir







|












|


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    case compression
      when :bzip2; flags += " -j"
      when :gzip; flags += " -z"
      when :lzma; flags += " --lzma"
    end
    #puts("tar #{flags}")
    #sleep 5
    safesystem("tar #{flags}")

    if self[:prefix]
      @paths = [self[:prefix]]
    else
      @paths = ["."]
    end

    ::Dir.chdir("#{builddir}/tarbuild") do
      tar(tar_path, ".")
    end

    # TODO(sissel): Make a helper method.
    safesystem(*["gzip", "-f", tar_path])
  end # def make_tarball!
end # class FPM::Source::Dir

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

1
2
3
4

5
6
7
8
9
10
11
require "erb"
require "fpm/namespace"
require "fpm/package"
require "fpm/errors"


class FPM::Target::Deb < FPM::Package

  def self.flags(opts, settings)
    settings.target[:deb] = "deb"

    opts.on("--ignore-iteration-in-dependencies",




>







1
2
3
4
5
6
7
8
9
10
11
12
require "erb"
require "fpm/namespace"
require "fpm/package"
require "fpm/errors"
require "fpm/util"

class FPM::Target::Deb < FPM::Package

  def self.flags(opts, settings)
    settings.target[:deb] = "deb"

    opts.on("--ignore-iteration-in-dependencies",
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

  def build!(params)
    control_files = [ "control", "md5sums" ]
    # place the postinst prerm files
    self.scripts.each do |name, path|
      case name
        when "pre-install"
          system("cp #{path} ./preinst")
          control_files << "preinst"
        when "post-install"
          system("cp #{path} ./postinst")
          control_files << "postinst"
        when "pre-uninstall"
          system("cp #{path} ./prerm")
          control_files << "prerm"
        when "post-uninstall"
          system("cp #{path} ./postrm")
          control_files << "postrm"
        else raise "Unsupported script name '#{name}' (path: #{path})"
      end # case name
    end # self.scripts.each

    if self.config_files.any?
      File.open('conffiles', 'w'){ |f| f.puts(config_files.join("\n")) }
      control_files << 'conffiles'
    end

    # Make the control
    system("tar -zcf control.tar.gz #{control_files.map{ |f| "./#{f}" }.join(" ")}")

    # create debian-binary
    File.open("debian-binary", "w") { |f| f.puts "2.0" }

    # pack up the .deb
    system("ar -qc #{params[:output]} debian-binary control.tar.gz data.tar.gz")
  end # def build

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







|


|


|


|











|





|







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

  def build!(params)
    control_files = [ "control", "md5sums" ]
    # place the postinst prerm files
    self.scripts.each do |name, path|
      case name
        when "pre-install"
          safesystem("cp #{path} ./preinst")
          control_files << "preinst"
        when "post-install"
          safesystem("cp #{path} ./postinst")
          control_files << "postinst"
        when "pre-uninstall"
          safesystem("cp #{path} ./prerm")
          control_files << "prerm"
        when "post-uninstall"
          safesystem("cp #{path} ./postrm")
          control_files << "postrm"
        else raise "Unsupported script name '#{name}' (path: #{path})"
      end # case name
    end # self.scripts.each

    if self.config_files.any?
      File.open('conffiles', 'w'){ |f| f.puts(config_files.join("\n")) }
      control_files << 'conffiles'
    end

    # Make the control
    safesystem("tar -zcf control.tar.gz #{control_files.map{ |f| "./#{f}" }.join(" ")}")

    # create debian-binary
    File.open("debian-binary", "w") { |f| f.puts "2.0" }

    # pack up the .deb
    safesystem("ar -qc #{params[:output]} debian-binary control.tar.gz data.tar.gz")
  end # def build

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

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

1

2
3
4
5
6
7
8
require "fpm/package"


class FPM::Target::Rpm < FPM::Package
  def architecture
    case @architecture
      when nil
        return %x{uname -m}.chomp   # default to current arch
      when "native"

>







1
2
3
4
5
6
7
8
9
require "fpm/package"
require "fpm/util"

class FPM::Target::Rpm < FPM::Package
  def architecture
    case @architecture
      when nil
        return %x{uname -m}.chomp   # default to current arch
      when "native"
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    %w(BUILD RPMS SRPMS SOURCES SPECS).each { |d| Dir.mkdir(d) }
    args = ["rpmbuild", "-ba",
           "--define", "buildroot #{Dir.pwd}/BUILD",
           "--define", "_topdir #{Dir.pwd}",
           "--define", "_sourcedir #{Dir.pwd}",
           "--define", "_rpmdir #{Dir.pwd}/RPMS",
           "#{name}.spec"]
    ret = system(*args)
    if !ret
      raise "rpmbuild failed (exit code: #{$?.exitstatus})"
    end

    Dir["#{Dir.pwd}/RPMS/**/*.rpm"].each do |path|
      # This should only output one rpm, should we verify this?
      system("mv", path, params[:output])
    end
  end # def build!
end # class FPM::Target::RPM







|
<
<
<



|



41
42
43
44
45
46
47
48



49
50
51
52
53
54
55
    %w(BUILD RPMS SRPMS SOURCES SPECS).each { |d| Dir.mkdir(d) }
    args = ["rpmbuild", "-ba",
           "--define", "buildroot #{Dir.pwd}/BUILD",
           "--define", "_topdir #{Dir.pwd}",
           "--define", "_sourcedir #{Dir.pwd}",
           "--define", "_rpmdir #{Dir.pwd}/RPMS",
           "#{name}.spec"]
    safesystem(*args)




    Dir["#{Dir.pwd}/RPMS/**/*.rpm"].each do |path|
      # This should only output one rpm, should we verify this?
      safesystem("mv", path, params[:output])
    end
  end # def build!
end # class FPM::Target::RPM

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

1
2
3
4

5
6
7
8
9
10
11
require "erb"
require "fpm/namespace"
require "fpm/package"
require "fpm/errors"


# TODO(sissel): Add dependency checking support.
# IIRC this has to be done as a 'checkinstall' step.
class FPM::Target::Solaris < FPM::Package
  def architecture
    case @architecture
    when nil, "native"




>







1
2
3
4
5
6
7
8
9
10
11
12
require "erb"
require "fpm/namespace"
require "fpm/package"
require "fpm/errors"
require "fpm/util"

# TODO(sissel): Add dependency checking support.
# IIRC this has to be done as a 'checkinstall' step.
class FPM::Target::Solaris < FPM::Package
  def architecture
    case @architecture
    when nil, "native"
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
52
53
54
55
    "#{builddir}/pkginfo"
  end

  def build!(params)
    self.scripts.each do |name, path|
      case name
        when "pre-install"
          system("cp #{path} ./preinstall")
          File.chmod(0755, "./preinstall")
        when "post-install"
          system("cp #{path} ./postinstall")
          File.chmod(0755, "./postinstall")
        when "pre-uninstall"
          raise FPM::InvalidPackageConfiguration.new(
            "pre-uninstall is not supported by Solaris packages"
          )
        when "post-uninstall"
          raise FPM::InvalidPackageConfiguration.new(
            "post-uninstall is not supported by Solaris packages"
          )
      end # case name
    end # self.scripts.each

    # Unpack data.tar.gz so we can build a package from it.
    Dir.mkdir("data")
    system("gzip -d data.tar.gz");
    Dir.chdir("data") do
      system("tar -xf ../data.tar");
    end

    #system("(echo 'i pkginfo'; pkgproto data=/) > Prototype")

    # Generate the package 'Prototype' file
    # TODO(sissel): allow setting default file owner.
    File.open("Prototype", "w") do |prototype|







|


|














|

|







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
52
53
54
55
56
    "#{builddir}/pkginfo"
  end

  def build!(params)
    self.scripts.each do |name, path|
      case name
        when "pre-install"
          safesystem("cp #{path} ./preinstall")
          File.chmod(0755, "./preinstall")
        when "post-install"
          safesystem("cp #{path} ./postinstall")
          File.chmod(0755, "./postinstall")
        when "pre-uninstall"
          raise FPM::InvalidPackageConfiguration.new(
            "pre-uninstall is not supported by Solaris packages"
          )
        when "post-uninstall"
          raise FPM::InvalidPackageConfiguration.new(
            "post-uninstall is not supported by Solaris packages"
          )
      end # case name
    end # self.scripts.each

    # Unpack data.tar.gz so we can build a package from it.
    Dir.mkdir("data")
    safesystem("gzip -d data.tar.gz");
    Dir.chdir("data") do
      safesystem("tar -xf ../data.tar");
    end

    #system("(echo 'i pkginfo'; pkgproto data=/) > Prototype")

    # Generate the package 'Prototype' file
    # TODO(sissel): allow setting default file owner.
    File.open("Prototype", "w") do |prototype|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
        user = "root"
        group = "root"
        prototype.puts([type, klass, path, mode, user, group].join(" "))
      end # popen "pkgproto ..."
    end # File prototype

    # Should create a package directory named by the package name.
    system("pkgmk -o -d .")

    # Convert the 'package directory' built above to a real solaris package.
    system("pkgtrans -s . #{params[:output]} #{name}")
  end # def build

  def default_output
    v = version
    v = "#{epoch}:#{v}" if epoch
    if iteration
      "#{name}_#{v}-#{iteration}_#{architecture}.#{type}"
    else
      "#{name}_#{v}_#{architecture}.#{type}"
    end
  end # def default_output
end # class FPM::Deb








|


|













66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
        user = "root"
        group = "root"
        prototype.puts([type, klass, path, mode, user, group].join(" "))
      end # popen "pkgproto ..."
    end # File prototype

    # Should create a package directory named by the package name.
    safesystem("pkgmk -o -d .")

    # Convert the 'package directory' built above to a real solaris package.
    safesystem("pkgtrans -s . #{params[:output]} #{name}")
  end # def build

  def default_output
    v = version
    v = "#{epoch}:#{v}" if epoch
    if iteration
      "#{name}_#{v}-#{iteration}_#{architecture}.#{type}"
    else
      "#{name}_#{v}_#{architecture}.#{type}"
    end
  end # def default_output
end # class FPM::Deb

Added lib/fpm/util.rb.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
def safesystem(*call)
  return_val = system(*call)
  if !return_val
    raise "'#{call}' failed with error code: #{$?.exitstatus}"
  end
  return return_val
end # def safesystem