Class: FPM::Package::Deb

Inherits:
FPM::Package show all
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, #category, #config_files, #conflicts, #dependencies, #description, #directories, #epoch, #iteration, #license, #maintainer, #provides, #replaces, #scripts, #url, #vendor, #version

Instance Method Summary collapse

Methods inherited from FPM::Package

apply_options, #cleanup, #cleanup_build, #cleanup_staging, #convert, default_attributes, #edit_file, #files, inherited, option, #script, #staging_path, #type, type, types

Methods included from Util

#copy_entry, #mknod_w, #program_in_path?, #safesystem, #safesystemout, #tar_cmd, #with

Constructor Details

#initialize(*args) ⇒ Deb

Returns a new instance of Deb.



126
127
128
129
# File 'lib/fpm/package/deb.rb', line 126

def initialize(*args)
  super(*args)
  attributes[:deb_priority] = "extra"
end

Instance Method Details

#architectureObject

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.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/fpm/package/deb.rb', line 136

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



412
413
414
415
416
417
418
419
420
# File 'lib/fpm/package/deb.rb', line 412

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
    
end

#input(input_path) ⇒ Object

def prefix



190
191
192
193
# File 'lib/fpm/package/deb.rb', line 190

def input(input_path)
  extract_info(input_path)
  extract_files(input_path)
end

#nameObject

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.



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/fpm/package/deb.rb', line 166

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

  return @name
end

#output(output_path) ⇒ Object

def extract_files



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
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
# File 'lib/fpm/package/deb.rb', line 302

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

  write_control_tarball

  # Tar up the staging_path into data.tar.{compression type}
  case self.attributes[:deb_compression]
    when "gzip", 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

  tar_flags = []
  if !attributes[:deb_user].nil?
    if attributes[:deb_user] == 'root'
      tar_flags += [ "--numeric-owner", "--owner", "0" ]
    else
      tar_flags += [ "--owner", attributes[:deb_user] ]
    end
  end

  if !attributes[:deb_group].nil?
    if attributes[:deb_group] == 'root'
      tar_flags += [ "--numeric-owner", "--group", "0" ]
    else
      tar_flags += [ "--group", attributes[:deb_group] ]
    end
  end

  if attributes[:deb_changelog]
    dest_changelog = File.join(staging_path, "usr/share/doc/#{name}/changelog.Debian")
    FileUtils.mkdir_p(File.dirname(dest_changelog))
    FileUtils.cp attributes[:deb_changelog], dest_changelog
    File.chmod(0644, dest_changelog)
    safesystem("gzip", dest_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}")
    FileUtils.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}")
    FileUtils.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")
    dest_upstart = staging_path("etc/init/#{name}.conf")
    FileUtils.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}")
    FileUtils.mkdir_p(File.dirname(dest_init))
    FileUtils.ln_s("/lib/init/upstart-job", dest_init)
  end

  args = [ tar_cmd, "-C", staging_path, compression ] + 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
  with(File.expand_path(output_path)) do |output_path|
    ::Dir.chdir(build_path) do
      safesystem("ar", "-qc", output_path, "debian-binary", "control.tar.gz", datatar)
    end
  end
  @logger.log("Created deb package", :path => output_path)
end

#prefixObject

def name



186
187
188
# File 'lib/fpm/package/deb.rb', line 186

def prefix
  return (attributes[:prefix] or "/")
end

#to_s(format = nil) ⇒ Object

def write_md5sums



658
659
660
661
662
663
# File 'lib/fpm/package/deb.rb', line 658

def to_s(format=nil)
  # Default format if nil
  # git_1.7.9.3-1_amd64.deb
  return super("NAME_FULLVERSION_ARCH.TYPE") if format.nil?
  return super(format)
end