Skip to content

Commit

Permalink
Merge pull request #130 from ebastien/debian-config
Browse files Browse the repository at this point in the history
Support for debconf control files in Debian target
  • Loading branch information
jordansissel committed Dec 5, 2011
2 parents 3fcde9f + 9876857 commit ee631b0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 25 deletions.
50 changes: 33 additions & 17 deletions lib/fpm/target/deb.rb
Expand Up @@ -6,6 +6,16 @@

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

# Supported Debian control files
CONTROL_FILES = {
"pre-install" => [:script, "preinst"],
"post-install" => [:script, "postinst"],
"pre-uninstall" => [:script, "prerm"],
"post-uninstall" => [:script, "postrm"],
"debconf-config" => [:script, "config"],
"debconf-templates" => [:text, "templates"]
}

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

Expand All @@ -23,6 +33,18 @@ def self.flags(opts, settings)
"Custom version of the Debian control file.") do |control|
settings.target[:control] = File.expand_path(control)
end

# Add custom debconf config file
opts.on("--config SCRIPTPATH",
"Add SCRIPTPATH as debconf config file.") do |config|
settings.scripts["debconf-config"] = File.expand_path(config)
end

# Add custom debconf templates file
opts.on("--templates FILEPATH",
"Add FILEPATH as debconf templates file.") do |templates|
settings.scripts["debconf-templates"] = File.expand_path(templates)
end
end

def needs_md5sums
Expand Down Expand Up @@ -90,23 +112,16 @@ def build!(params)
"template.") unless $?.exitstatus == 0
end

# place the postinst prerm files
# place the control 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
ctrl_type, ctrl_file = CONTROL_FILES[name]
if ctrl_file
safesystem("cp", path, "./#{ctrl_file}")
safesystem("chmod", "a+x", "./#{ctrl_file}") if ctrl_type == :script
control_files << ctrl_file
else
raise "Unsupported script name '#{name}' (path: #{path})"
end
end # self.scripts.each

if self.config_files.any?
Expand All @@ -115,7 +130,8 @@ def build!(params)
end

# Make the control
safesystem("tar", "-zcf", "control.tar.gz", *control_files)
safesystem("tar", "--numeric-owner", "--owner=root", "--group=root",
"-zcf", "control.tar.gz", *control_files)

# create debian-binary
File.open("debian-binary", "w") { |f| f.puts "2.0" }
Expand Down
2 changes: 2 additions & 0 deletions test/dir-deb-with-debconf.out
@@ -0,0 +1,2 @@
0 bytes, 0 lines * config
0 bytes, 0 lines templates
17 changes: 17 additions & 0 deletions test/dir-deb-with-debconf.test
@@ -0,0 +1,17 @@
#!/bin/bash

run() {
mkdir -p $tmpdir/prefix
touch $tmpdir/config
touch $tmpdir/templates

fpm -s dir -t deb -n testing -a all \
--deb-config $tmpdir/config \
--deb-templates $tmpdir/templates \
$tmpdir/prefix

file=testing_1.0_all.deb
dpkg -I $file | grep "\(config\)\|\(templates\)" > $output

rm $file
}
4 changes: 2 additions & 2 deletions test/dir-rpm-with-prefix.test
Expand Up @@ -10,6 +10,6 @@ run() {

fpm -s dir -t rpm -n testing -a all --prefix $prefix -C $tmpdir

rpm -qlp testing-1.0.noarch.rpm > $output
rm testing-1.0.noarch.rpm
rpm -qlp testing-1.0-1.noarch.rpm > $output
rm testing-1.0-1.noarch.rpm
}
2 changes: 1 addition & 1 deletion test/dir-rpm.test
Expand Up @@ -8,7 +8,7 @@ run() {

fpm -s dir -t rpm -n testing -a all $tmpdir

file=testing-1.0.noarch.rpm
file=testing-1.0-1.noarch.rpm
rpm -qlp $file > $output
sed -e "s,TMPDIR,$(basename $tmpdir)," $expected.template > $expected

Expand Down
10 changes: 5 additions & 5 deletions test/gem-deb.out
Expand Up @@ -5,12 +5,12 @@
./usr/lib/ruby/gems/1.8/
./usr/lib/ruby/gems/1.8/bin/
./usr/lib/ruby/gems/1.8/bin/rails
./usr/lib/ruby/gems/1.8/specifications/
./usr/lib/ruby/gems/1.8/specifications/rails-3.1.0.gemspec
./usr/lib/ruby/gems/1.8/cache/
./usr/lib/ruby/gems/1.8/cache/rails-3.1.0.gem
./usr/lib/ruby/gems/1.8/doc/
./usr/lib/ruby/gems/1.8/gems/
./usr/lib/ruby/gems/1.8/gems/rails-3.1.0/
./usr/lib/ruby/gems/1.8/gems/rails-3.1.0/bin/
./usr/lib/ruby/gems/1.8/gems/rails-3.1.0/bin/rails
./usr/lib/ruby/gems/1.8/doc/
./usr/lib/ruby/gems/1.8/cache/
./usr/lib/ruby/gems/1.8/cache/rails-3.1.0.gem
./usr/lib/ruby/gems/1.8/specifications/
./usr/lib/ruby/gems/1.8/specifications/rails-3.1.0.gemspec
3 changes: 3 additions & 0 deletions test/gem-deb.test
Expand Up @@ -2,6 +2,9 @@
RAILS_VERSION=3.1.0

run() {
# Force the gem installation path to match the one of the expected output
export GEM_HOME=/usr/lib/ruby/gems/1.8

fpm -s gem -t deb -v $RAILS_VERSION rails

file=rubygem-rails_${RAILS_VERSION}_all.deb
Expand Down

0 comments on commit ee631b0

Please sign in to comment.