Class: Omnibus::Packager::DEB

Inherits:
Base
  • Object
show all
Defined in:
lib/omnibus/packagers/deb.rb

Constant Summary

Constants included from Util

Util::SHELLOUT_OPTIONS

Constants included from NullArgumentable

NullArgumentable::NULL

Instance Attribute Summary

Attributes inherited from Base

#project

DSL methods collapse

Instance Method Summary collapse

Methods inherited from Base

build, #exclusions, id, #id, #initialize, #install_dir, #package_path, #resource_path, #resources_path, #run!, setup, #staging_dir

Methods included from Util

#copy_file, #create_directory, #create_file, #create_link, included, #remove_directory, #remove_file, #shellout, #shellout!, #windows_safe_path

Methods included from Templating

included, #render_template

Methods included from NullArgumentable

included, #null?

Methods included from Logging

included

Methods included from Digestable

#digest, #digest_directory

Constructor Details

This class inherits a constructor from Omnibus::Packager::Base

Instance Method Details

#create_deb_filevoid

This method returns an undefined value.

Create the .deb file, compressing at gzip level 9. The use of the fakeroot command is required so that the package is owned by root:root, but the build user does not need to have sudo permissions.


287
288
289
290
291
292
293
294
# File 'lib/omnibus/packagers/deb.rb', line 287

def create_deb_file
  log.info(log_key) { "Creating .deb file" }

  # Execute the build command
  Dir.chdir(Config.package_dir) do
    shellout!("fakeroot dpkg-deb -z9 -Zgzip -D --build #{staging_dir} #{package_name}")
  end
end

#debian_dirString

The path where Debian-specific files will live.

Examples:

/var/.../chef-server_11.12.4/DEBIAN

189
190
191
# File 'lib/omnibus/packagers/deb.rb', line 189

def debian_dir
  @debian_dir ||= File.join(staging_dir, 'DEBIAN')
end

#license(val = NULL) ⇒ String

Set or return the license for this package.

Examples:

license "Apache 2.0"

106
107
108
109
110
111
112
113
114
115
116
# File 'lib/omnibus/packagers/deb.rb', line 106

def license(val = NULL)
  if null?(val)
    @license || 'unknown'
  else
    unless val.is_a?(String)
      raise InvalidValue.new(:license, 'be a String')
    end

    @license = val
  end
end

#package_nameObject

The name of the package to create. Note, this does *not* include the extension.


177
178
179
# File 'lib/omnibus/packagers/deb.rb', line 177

def package_name
  "#{safe_base_package_name}_#{safe_version}-#{safe_build_iteration}_#{safe_architecture}.deb"
end

#package_sizeFixnum

The size of this Debian package. This is dynamically calculated.


301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/omnibus/packagers/deb.rb', line 301

def package_size
  @package_size ||= begin
    path  = "#{project.install_dir}/**/*"
    total = FileSyncer.glob(path).inject(0) do |size, path|
      unless File.directory?(path) || File.symlink?(path)
        size += File.size(path)
      end

      size
    end

    # Per http://www.debian.org/doc/debian-policy/ch-controlfields.html, the
    # disk space is given as the integer value of the estimated installed
    # size in bytes, divided by 1024 and rounded up.
    total / 1024
  end
end

#priority(val = NULL) ⇒ String

Set or return the priority for this package.

Examples:

priority "extra"

131
132
133
134
135
136
137
138
139
140
141
# File 'lib/omnibus/packagers/deb.rb', line 131

def priority(val = NULL)
  if null?(val)
    @priority || 'extra'
  else
    unless val.is_a?(String)
      raise InvalidValue.new(:priority, 'be a String')
    end

    @priority = val
  end
end

#safe_architectureString

Debian does not follow the standards when naming 64-bit packages.


397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/omnibus/packagers/deb.rb', line 397

def safe_architecture
  case Ohai['kernel']['machine']
  when 'x86_64'
    'amd64'
  when 'i686'
    'i386'
  when 'armv6l'
    if Ohai['platform'] == 'raspbian'
      'armhf'
    else
      'armv6l'
    end
  else
    Ohai['kernel']['machine']
  end
end

#safe_base_package_nameString

Return the Debian-ready base package name, converting any invalid characters to dashes (-).


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/omnibus/packagers/deb.rb', line 325

def safe_base_package_name
  if project.package_name =~ /\A[a-z0-9\.\+\-]+\z/
    project.package_name.dup
  else
    converted = project.package_name.downcase.gsub(/[^a-z0-9\.\+\-]+/, '-')

    log.warn(log_key) do
      "The `name' component of Debian package names can only include " \
      "lower case alphabetical characters (a-z), numbers (0-9), dots (.), " \
      "plus signs (+), and dashes (-). Converting `#{project.package_name}' to " \
      "`#{converted}'."
    end

    converted
  end
end

#safe_build_iterationString

This is actually just the regular build_iteration, but it felt lonely among all the other safe_* methods.


348
349
350
# File 'lib/omnibus/packagers/deb.rb', line 348

def safe_build_iteration
  project.build_iteration
end

#safe_versionString

Return the Debian-ready version, replacing all dashes (-) with tildes (+~+) and converting any invalid characters to underscores (_).


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
# File 'lib/omnibus/packagers/deb.rb', line 358

def safe_version
  version = project.build_version.dup

  if version =~ /\-/
    converted = version.gsub('-', '~')

    log.warn(log_key) do
      "Dashes hold special significance in the Debian package versions. " \
      "Versions that contain a dash and should be considered an earlier " \
      "version (e.g. pre-releases) may actually be ordered as later " \
      "(e.g. 12.0.0-rc.6 > 12.0.0). We'll work around this by replacing " \
      "dashes (-) with tildes (~). Converting `#{project.build_version}' " \
      "to `#{converted}'."
    end

    version = converted
  end

  if version =~ /\A[a-zA-Z0-9\.\+\:\~]+\z/
    version
  else
    converted = version.gsub(/[^a-zA-Z0-9\.\+\:\~]+/, '_')

    log.warn(log_key) do
      "The `version' component of Debian package names can only include " \
      "alphabetical characters (a-z, A-Z), numbers (0-9), dots (.), " \
      "plus signs (+), dashes (-), tildes (~) and colons (:). Converting " \
      "`#{project.build_version}' to `#{converted}'."
    end

    converted
  end
end

#section(val = NULL) ⇒ String

Set or return the section for this package.

Examples:

section "databases"

156
157
158
159
160
161
162
163
164
165
166
# File 'lib/omnibus/packagers/deb.rb', line 156

def section(val = NULL)
  if null?(val)
    @section || 'misc'
  else
    unless val.is_a?(String)
      raise InvalidValue.new(:section, 'be a String')
    end

    @section = val
  end
end

#vendor(val = NULL) ⇒ String

Set or return the vendor who made this package.

Examples:

vendor "Seth Vargo <[email protected]>"

81
82
83
84
85
86
87
88
89
90
91
# File 'lib/omnibus/packagers/deb.rb', line 81

def vendor(val = NULL)
  if null?(val)
    @vendor || 'Omnibus <[email protected]>'
  else
    unless val.is_a?(String)
      raise InvalidValue.new(:vendor, 'be a String')
    end

    @vendor = val
  end
end

#write_conffiles_filevoid

This method returns an undefined value.

Render the list of config files into the conffile.


227
228
229
230
231
232
233
234
235
236
# File 'lib/omnibus/packagers/deb.rb', line 227

def write_conffiles_file
  return if project.config_files.empty?

  render_template(resource_path('conffiles.erb'),
    destination: File.join(debian_dir, 'conffiles'),
    variables: {
      config_files: project.config_files,
    }
  )
end

#write_control_filevoid

This method returns an undefined value.

Render a control file in #{debian_dir}/control using the supplied ERB template.


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/omnibus/packagers/deb.rb', line 199

def write_control_file
  render_template(resource_path('control.erb'),
    destination: File.join(debian_dir, 'control'),
    variables: {
      name:           safe_base_package_name,
      version:        safe_version,
      iteration:      safe_build_iteration,
      vendor:         vendor,
      license:        license,
      architecture:   safe_architecture,
      maintainer:     project.maintainer,
      installed_size: package_size,
      homepage:       project.homepage,
      description:    project.description,
      priority:       priority,
      section:        section,
      conflicts:      project.conflicts,
      replaces:       project.replaces,
      dependencies:   project.runtime_dependencies,
    }
  )
end

#write_md5_sumsvoid

This method returns an undefined value.

Generate a list of the md5 sums of every file in the package and write it to #{debian_dir}/control/md5sums.


261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/omnibus/packagers/deb.rb', line 261

def write_md5_sums
  path = "#{staging_dir}/**/*"
  hash = FileSyncer.glob(path).inject({}) do |hash, path|
    if File.file?(path) && !File.symlink?(path)
      relative_path = path.gsub("#{staging_dir}/", '')
      hash[relative_path] = digest(path, :md5)
    end

    hash
  end

  render_template(resource_path('md5sums.erb'),
    destination: File.join(debian_dir, 'md5sums'),
    variables: {
      md5sums: hash,
    }
  )
end

#write_scriptsvoid

This method returns an undefined value.

Copy all scripts in Omnibus::Project#package_scripts_path to the control directory of this repo.


244
245
246
247
248
249
250
251
252
253
# File 'lib/omnibus/packagers/deb.rb', line 244

def write_scripts
  %w(preinst postinst prerm postrm).each do |script|
    path = File.join(project.package_scripts_path, script)

    if File.file?(path)
      log.debug(log_key) { "Adding script `#{script}' to `#{debian_dir}'" }
      copy_file(path, debian_dir)
    end
  end
end