Class: FPM::Package::Deb
- Inherits:
-
FPM::Package
- Object
- FPM::Package
- FPM::Package::Deb
- Defined in:
- lib/fpm/package/deb.rb
Overview
Support for debian packages (.deb files)
This class supports both input and output of packages.
Constant Summary collapse
- SCRIPT_MAP =
Map of what scripts are named.
{ :before_install => "preinst", :after_install => "postinst", :before_remove => "prerm", :after_remove => "postrm", }
- COMPRESSION_TYPES =
The list of supported compression types. Default is gz (gzip)
[ "gz", "bzip2", "xz" ]
Instance Attribute Summary
Attributes inherited from FPM::Package
#attributes, #attrs, #category, #config_files, #conflicts, #dependencies, #description, #directories, #epoch, #iteration, #license, #maintainer, #provides, #replaces, #scripts, #url, #vendor, #version
Instance Method Summary collapse
-
#add_path(path, allconfigs) ⇒ Object
expand recursively a given path to be put in allconfigs.
-
#architecture ⇒ Object
Return the architecture.
-
#converted_from(origin) ⇒ Object
def output.
-
#data_tar_flags ⇒ Object
def to_s.
-
#initialize(*args) ⇒ Deb
constructor
A new instance of Deb.
-
#input(input_path) ⇒ Object
def prefix.
-
#name ⇒ Object
Get the name of this package.
-
#output(output_path) ⇒ Object
def extract_files.
-
#prefix ⇒ Object
def name.
- #to_s(format = nil) ⇒ Object
Methods inherited from FPM::Package
apply_options, #build_path, #cleanup, #cleanup_build, #cleanup_staging, #convert, default_attributes, #edit_file, #files, inherited, option, #script, #staging_path, type, #type, types
Methods included from Util
#copied_entries, #copy_entry, #copy_metadata, #default_shell, #execmd, #expand_pessimistic_constraints, #logger, #mknod_w, #program_exists?, #program_in_path?, #safesystem, #safesystemout, #tar_cmd
Constructor Details
#initialize(*args) ⇒ Deb
Returns a new instance of Deb.
167 168 169 170 |
# File 'lib/fpm/package/deb.rb', line 167 def initialize(*args) super(*args) attributes[:deb_priority] = "extra" end |
Instance Method Details
#add_path(path, allconfigs) ⇒ Object
expand recursively a given path to be put in allconfigs
759 760 761 762 763 764 765 766 767 768 |
# File 'lib/fpm/package/deb.rb', line 759 def add_path(path, allconfigs) # Strip leading / path = path[1..-1] if path[0,1] == "/" cfg_path = File.(path, staging_path) Find.find(cfg_path) do |p| if File.file?(p) allconfigs << p.gsub("#{staging_path}/", '') end end end |
#architecture ⇒ Object
Return the architecture. This will default to native if not yet set. It will also try to use dpkg and ‘uname -m’ to figure out what the native ‘architecture’ value should be.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/fpm/package/deb.rb', line 177 def architecture if @architecture.nil? or @architecture == "native" # Default architecture should be 'native' which we'll need to ask the # system about. if program_in_path?("dpkg") @architecture = %x{dpkg --print-architecture 2> /dev/null}.chomp if $?.exitstatus != 0 or @architecture.empty? # if dpkg fails or emits nothing, revert back to uname -m @architecture = %x{uname -m}.chomp end else @architecture = %x{uname -m}.chomp end end case @architecture when "x86_64" # Debian calls x86_64 "amd64" @architecture = "amd64" when "noarch" # Debian calls noarch "all" @architecture = "all" end return @architecture end |
#converted_from(origin) ⇒ Object
def output
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/fpm/package/deb.rb', line 547 def converted_from(origin) self.dependencies = self.dependencies.collect do |dep| fix_dependency(dep) end.flatten self.provides = self.provides.collect do |provides| fix_provides(provides) end.flatten if origin == FPM::Package::Deb changelog_path = staging_path("usr/share/doc/#{name}/changelog.Debian.gz") if File.exists?(changelog_path) logger.debug("Found a deb changelog file, using it.", :path => changelog_path) attributes[:deb_changelog] = build_path("deb_changelog") File.open(attributes[:deb_changelog], "w") do |deb_changelog| Zlib::GzipReader.open(changelog_path) do |gz| IO::copy_stream(gz, deb_changelog) end end File.unlink(changelog_path) end end if origin == FPM::Package::Deb changelog_path = staging_path("usr/share/doc/#{name}/changelog.gz") if File.exists?(changelog_path) logger.debug("Found an upstream changelog file, using it.", :path => changelog_path) attributes[:deb_upstream_changelog] = build_path("deb_upstream_changelog") File.open(attributes[:deb_upstream_changelog], "w") do |deb_upstream_changelog| Zlib::GzipReader.open(changelog_path) do |gz| IO::copy_stream(gz, deb_upstream_changelog) end end File.unlink(changelog_path) end end end |
#data_tar_flags ⇒ Object
def to_s
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 |
# File 'lib/fpm/package/deb.rb', line 912 def data_tar_flags data_tar_flags = [] if attributes[:deb_use_file_permissions?].nil? if !attributes[:deb_user].nil? if attributes[:deb_user] == 'root' data_tar_flags += [ "--numeric-owner", "--owner", "0" ] else data_tar_flags += [ "--owner", attributes[:deb_user] ] end end if !attributes[:deb_group].nil? if attributes[:deb_group] == 'root' data_tar_flags += [ "--numeric-owner", "--group", "0" ] else data_tar_flags += [ "--group", attributes[:deb_group] ] end end end return data_tar_flags end |
#input(input_path) ⇒ Object
def prefix
237 238 239 240 |
# File 'lib/fpm/package/deb.rb', line 237 def input(input_path) extract_info(input_path) extract_files(input_path) end |
#name ⇒ Object
Get the name of this package. See also FPM::Package#name
This accessor actually modifies the name if it has some invalid or unwise characters.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/fpm/package/deb.rb', line 207 def name if @name =~ /[A-Z]/ logger.warn("Debian tools (dpkg/apt) don't do well with packages " \ "that use capital letters in the name. In some cases it will " \ "automatically downcase them, in others it will not. It is confusing." \ " Best to not use any capital letters at all. I have downcased the " \ "package name for you just to be safe.", :oldname => @name, :fixedname => @name.downcase) @name = @name.downcase end if @name.include?("_") logger.info("Debian package names cannot include underscores; " \ "automatically converting to dashes", :name => @name) @name = @name.gsub(/[_]/, "-") end if @name.include?(" ") logger.info("Debian package names cannot include spaces; " \ "automatically converting to dashes", :name => @name) @name = @name.gsub(/[ ]/, "-") end return @name end |
#output(output_path) ⇒ Object
def extract_files
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/fpm/package/deb.rb', line 365 def output(output_path) self.provides = self.provides.collect { |p| fix_provides(p) } output_check(output_path) # Abort if the target path already exists. # create 'debian-binary' file, required to make a valid debian package File.write(build_path("debian-binary"), "2.0\n") # If we are given --deb-shlibs but no --after-install script, we # should implicitly create a before/after scripts that run ldconfig if attributes[:deb_shlibs] if !script?(:after_install) logger.info("You gave --deb-shlibs but no --after-install, so " \ "I am adding an after-install script that runs " \ "ldconfig to update the system library cache") scripts[:after_install] = template("deb/ldconfig.sh.erb").result(binding) end if !script?(:after_remove) logger.info("You gave --deb-shlibs but no --after-remove, so " \ "I am adding an after-remove script that runs " \ "ldconfig to update the system library cache") scripts[:after_remove] = template("deb/ldconfig.sh.erb").result(binding) end end attributes.fetch(:deb_systemd_list, []).each do |systemd| name = File.basename(systemd, ".service") dest_systemd = staging_path("lib/systemd/system/#{name}.service") mkdir_p(File.dirname(dest_systemd)) FileUtils.cp(systemd, dest_systemd) File.chmod(0644, dest_systemd) # set the attribute with the systemd service name attributes[:deb_systemd] = name end if script?(:before_upgrade) or script?(:after_upgrade) or attributes[:deb_systemd] puts "Adding action files" if script?(:before_install) or script?(:before_upgrade) scripts[:before_install] = template("deb/preinst_upgrade.sh.erb").result(binding) end if script?(:before_remove) or attributes[:deb_systemd] scripts[:before_remove] = template("deb/prerm_upgrade.sh.erb").result(binding) end if script?(:after_install) or script?(:after_upgrade) or attributes[:deb_systemd] scripts[:after_install] = template("deb/postinst_upgrade.sh.erb").result(binding) end if script?(:after_remove) scripts[:after_remove] = template("deb/postrm_upgrade.sh.erb").result(binding) end end write_control_tarball # Tar up the staging_path into data.tar.{compression type} case self.attributes[:deb_compression] when "gz", nil datatar = build_path("data.tar.gz") compression = "-z" when "bzip2" datatar = build_path("data.tar.bz2") compression = "-j" when "xz" datatar = build_path("data.tar.xz") compression = "-J" else raise FPM::InvalidPackageConfiguration, "Unknown compression type '#{self.attributes[:deb_compression]}'" end # There are two changelogs that may appear: # - debian-specific changelog, which should be archived as changelog.Debian.gz # - upstream changelog, which should be archived as changelog.gz # see https://www.debian.org/doc/debian-policy/ch-docs.html#s-changelogs # Write the changelog.Debian.gz file dest_changelog = File.join(staging_path, "usr/share/doc/#{name}/changelog.Debian.gz") mkdir_p(File.dirname(dest_changelog)) File.new(dest_changelog, "wb", 0644).tap do |changelog| Zlib::GzipWriter.new(changelog, Zlib::BEST_COMPRESSION).tap do |changelog_gz| if attributes[:deb_changelog] logger.info("Writing user-specified changelog", :source => attributes[:deb_changelog]) File.new(attributes[:deb_changelog]).tap do |fd| chunk = nil # Ruby 1.8.7 doesn't have IO#copy_stream changelog_gz.write(chunk) while chunk = fd.read(16384) end.close else logger.info("Creating boilerplate changelog file") changelog_gz.write(template("deb/changelog.erb").result(binding)) end end.close end # No need to close, GzipWriter#close will close it. # Write the changelog.gz file (upstream changelog) dest_upstream_changelog = File.join(staging_path, "usr/share/doc/#{name}/changelog.gz") if attributes[:deb_upstream_changelog] File.new(dest_upstream_changelog, "wb", 0644).tap do |changelog| Zlib::GzipWriter.new(changelog, Zlib::BEST_COMPRESSION).tap do |changelog_gz| logger.info("Writing user-specified upstream changelog", :source => attributes[:deb_upstream_changelog]) File.new(attributes[:deb_upstream_changelog]).tap do |fd| chunk = nil # Ruby 1.8.7 doesn't have IO#copy_stream changelog_gz.write(chunk) while chunk = fd.read(16384) end.close end.close end # No need to close, GzipWriter#close will close it. end if File.exists?(dest_changelog) and not File.exists?(dest_upstream_changelog) # see https://www.debian.org/doc/debian-policy/ch-docs.html#s-changelogs File.rename(dest_changelog, dest_upstream_changelog) end attributes.fetch(:deb_init_list, []).each do |init| name = File.basename(init, ".init") dest_init = File.join(staging_path, "etc/init.d/#{name}") mkdir_p(File.dirname(dest_init)) FileUtils.cp init, dest_init File.chmod(0755, dest_init) end attributes.fetch(:deb_default_list, []).each do |default| name = File.basename(default, ".default") dest_default = File.join(staging_path, "etc/default/#{name}") mkdir_p(File.dirname(dest_default)) FileUtils.cp default, dest_default File.chmod(0644, dest_default) end attributes.fetch(:deb_upstart_list, []).each do |upstart| name = File.basename(upstart, ".upstart") name = "#{name}.conf" if !(name =~ /\.conf$/) dest_upstart = staging_path("etc/init/#{name}") mkdir_p(File.dirname(dest_upstart)) FileUtils.cp(upstart, dest_upstart) File.chmod(0644, dest_upstart) # Install an init.d shim that calls upstart dest_init = staging_path("etc/init.d/#{name}") mkdir_p(File.dirname(dest_init)) FileUtils.ln_s("/lib/init/upstart-job", dest_init) end attributes.fetch(:deb_systemd_list, []).each do |systemd| name = File.basename(systemd, ".service") dest_systemd = staging_path("lib/systemd/system/#{name}.service") mkdir_p(File.dirname(dest_systemd)) FileUtils.cp(systemd, dest_systemd) File.chmod(0644, dest_systemd) end write_control_tarball # Tar up the staging_path into data.tar.{compression type} case self.attributes[:deb_compression] when "gz", nil datatar = build_path("data.tar.gz") compression = "-z" when "bzip2" datatar = build_path("data.tar.bz2") compression = "-j" when "xz" datatar = build_path("data.tar.xz") compression = "-J" else raise FPM::InvalidPackageConfiguration, "Unknown compression type '#{self.attributes[:deb_compression]}'" end args = [ tar_cmd, "-C", staging_path, compression ] + data_tar_flags + [ "-cf", datatar, "." ] safesystem(*args) # pack up the .deb, which is just an 'ar' archive with 3 files # the 'debian-binary' file has to be first File.(output_path).tap do |output_path| ::Dir.chdir(build_path) do safesystem("ar", "-qc", output_path, "debian-binary", "control.tar.gz", datatar) end end end |
#prefix ⇒ Object
def name
233 234 235 |
# File 'lib/fpm/package/deb.rb', line 233 def prefix return (attributes[:prefix] or "/") end |
#to_s(format = nil) ⇒ Object
906 907 908 909 910 |
# File 'lib/fpm/package/deb.rb', line 906 def to_s(format=nil) # Default format if nil # git_1.7.9.3-1_amd64.deb return super(format.nil? ? "NAME_FULLVERSION_ARCH.EXTENSION" : format) end |