Add support for debconf.

This commit is contained in:
Emmanuel Bastien 2011-11-29 13:59:29 +01:00
parent f0c1051939
commit ceeddf73ef
1 changed files with 33 additions and 17 deletions

View File

@ -6,6 +6,16 @@ require "fpm/util"
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"
@ -23,6 +33,18 @@ class FPM::Target::Deb < FPM::Package
"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
@ -90,23 +112,16 @@ class FPM::Target::Deb < FPM::Package
"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?
@ -115,7 +130,8 @@ class FPM::Target::Deb < FPM::Package
end
# Make the control
safesystem("tar -zcf control.tar.gz #{control_files.map{ |f| "./#{f}" }.join(" ")}")
safesystem("tar --numeric-owner --owner=root --group=root -zcf control.tar.gz " \
"#{control_files.map{ |f| "./#{f}" }.join(" ")}")
# create debian-binary
File.open("debian-binary", "w") { |f| f.puts "2.0" }