Skip to content

Commit

Permalink
- Add --rpm-digest and --rpm-compression flags to allow selectable
Browse files Browse the repository at this point in the history
  digest/compress algorithms during package building. Defaults to the
  settings that are most likely to work on the widest range of rpm
  consumers (md5 + gzip)

  Improves solution already committed for #192
  • Loading branch information
jordansissel committed Mar 30, 2012
1 parent 7915b1d commit 2f69afb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
46 changes: 45 additions & 1 deletion lib/fpm/package/rpm.rb
Expand Up @@ -15,12 +15,47 @@
# * :rpm_rpmbuild_define - an array of definitions to give to rpmbuild.
# These are used, verbatim, each as: --define ITEM
class FPM::Package::RPM < FPM::Package
DIGEST_ALGORITHM_MAP = {
"md5" => 1,
"sha1" => 2,
"sha256" => 8,
"sha384" => 9,
"sha512" => 10
}

COMPRESSION_MAP = {
"xz" => "w2.xzdio",
"gzip" => "w9.gzdio",
"bzip2" => "w9.bzdio"
}


option "--rpmbuild-define", "DEFINITION",
"Pass a --define argument to rpmbuild." do |define|
attributes[:rpm_rpmbuild_define] ||= []
attributes[:rpm_rpmbuild_define] << define
end

option "--digest", DIGEST_ALGORITHM_MAP.keys.join("|"),
"Select a digest algorithm. md5 works on the most platforms.",
:default => "md5" do |value|
if !DIGEST_ALGORITHM_MAP.include?(value.downcase)
raise "Unknown digest algorithm '#{value}'. Valid options " \
"include: #{DIGEST_ALGORITHM_MAP.keys.join(", ")}"
end
value.downcase
end

option "--compression", COMPRESSION_MAP.keys.join("|"),
"Select a compression method. gzip works on the most platforms.",
:default => "gzip" do |value|
if !COMPRESSION_MAP.include?(value.downcase)
raise "Unknown compression type '#{value}'. Valid options " \
"include: #{COMPRESSION_MAP.keys.join(", ")}"
end
value.downcase
end

private

def architecture
Expand Down Expand Up @@ -141,5 +176,14 @@ def to_s(format=nil)
return super(format)
end # def to_s

public(:input, :output, :converted_from, :architecture, :to_s)
def payload_compression
return COMPRESSION_MAP[attributes[:rpm_compression]]
end # def payload_compression

def digest_algorithm
return DIGEST_ALGORITHM_MAP[attributes[:rpm_digest]]
end # def digest_algorithm

public(:input, :output, :converted_from, :architecture, :to_s,
:payload_compression, :digest_algorithm)
end # class FPM::Package::RPM
10 changes: 4 additions & 6 deletions templates/rpm.erb
Expand Up @@ -8,13 +8,11 @@
# Disable checking for unpackaged files ?
#%undefine __check_files

# Use MD5 file digests to support older RPM libraries (CentOS 5, etc)
# TODO(sissel): Make this tunable
%define _binary_filedigest 1
# Use <%= attributes[:rpm_digest] %> file digest method
%define _binary_filedigest_algorithm <%= digest_algorithm %>

# Use gzip compression (Default on newer redhats is 'xz' which is unsupported
# by CentOS 5 and older)
%define _binary_payload w9.gzdio
# Use <%= attributes[:rpm_compression] %> payload compression
%define _binary_payload <%= payload_compression %>

Name: <%= name %>
Version: <%= version %>
Expand Down

0 comments on commit 2f69afb

Please sign in to comment.