Class: Omnibus::Packager::PKG

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

Constant Summary collapse

SCRIPT_MAP =

Returns:

  • (Hash)
{
  # Default Omnibus naming
  preinst:  'preinstall',
  postinst: 'postinstall',
  # Default PKG naming
  preinstall:  'preinstall',
  postinstall: 'postinstall',
}.freeze

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 Sugarable

extended, included, #node

Methods included from NullArgumentable

included, #null?

Methods included from Logging

included

Methods included from Digestable

#digest, #digest_directory, included

Constructor Details

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

Instance Method Details

#build_component_pkgvoid

This method returns an undefined value.

Construct the intermediate build product. It can be installed with the Installer.app, but doesn't contain the data needed to customize the installer UI.



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/omnibus/packagers/pkg.rb', line 189

def build_component_pkg
  command = <<-EOH.gsub(/^ {8}/, '')
    pkgbuild \\
      --identifier "#{safe_identifier}" \\
      --version "#{safe_version}" \\
      --scripts "#{scripts_dir}" \\
      --root "#{project.install_dir}" \\
      --install-location "#{project.install_dir}" \\
      "#{component_pkg}"
  EOH

  Dir.chdir(staging_dir) do
    shellout!(command)
  end
end

#build_product_pkgvoid

This method returns an undefined value.

Construct the product package. The generated package is the final build product that is shipped to end users.



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/omnibus/packagers/pkg.rb', line 234

def build_product_pkg
  command = <<-EOH.gsub(/^ {8}/, '')
    productbuild \\
      --distribution "#{staging_dir}/Distribution" \\
      --resources "#{resources_dir}" \\
  EOH

  command << %Q(  --sign "#{signing_identity}" \\\n) if signing_identity
  command << %Q(  "#{final_pkg}")
  command << %Q(\n)

  Dir.chdir(staging_dir) do
    shellout!(command)
  end
end

#component_pkgString

The name of the (only) component package.

Returns:

  • (String)

    the filename of the component .pkg file to create.



255
256
257
# File 'lib/omnibus/packagers/pkg.rb', line 255

def component_pkg
  "#{safe_base_package_name}-core.pkg"
end

#final_pkgString

The full path where the product package was/will be written.

Returns:

  • (String)


136
137
138
# File 'lib/omnibus/packagers/pkg.rb', line 136

def final_pkg
  File.expand_path("#{Config.package_dir}/#{package_name}")
end

#identifier(val = NULL) ⇒ String

The identifer for the PKG package.

Examples:

identifier 'com.getchef.chefdk'

Parameters:

  • val (String) (defaults to: NULL)

    the package identifier

Returns:

  • (String)


91
92
93
94
95
96
97
# File 'lib/omnibus/packagers/pkg.rb', line 91

def identifier(val = NULL)
  if null?(val)
    @identifier
  else
    @identifier = val
  end
end

#package_nameObject

See Also:



127
128
129
# File 'lib/omnibus/packagers/pkg.rb', line 127

def package_name
  "#{safe_base_package_name}-#{safe_version}-#{safe_build_iteration}.pkg"
end

#resources_dirString

The path where the product package resources will live. We cannot store resources in the top-level staging dir, because productbuild's --resources flag expects a directory that does not contain the parent package.

Returns:

  • (String)


148
149
150
# File 'lib/omnibus/packagers/pkg.rb', line 148

def resources_dir
  File.expand_path("#{staging_dir}/Resources")
end

#safe_base_package_nameString

Return the PKG-ready base package name, removing any invalid characters.

Returns:

  • (String)


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

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

    log.warn(log_key) do
      "The `name' component of Mac package names can only include " \
      "alphabetical characters (a-z, A-Z), and numbers (0-9). Converting " \
      "`#{project.package_name}' to `#{converted}'."
    end

    converted
  end
end

#safe_build_iterationString

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

Returns:

  • (String)


300
301
302
# File 'lib/omnibus/packagers/pkg.rb', line 300

def safe_build_iteration
  project.build_iteration
end

#safe_identifierString

The identifier for this mac package (the com.whatever.thing.whatever). This is a configurable project value, but a default value is calculated if one is not given.

Returns:

  • (String)


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

def safe_identifier
  return identifier if identifier

  maintainer = project.maintainer.gsub(/[^[:alnum:]+]/, '').downcase
  "test.#{maintainer}.pkg.#{safe_base_package_name}"
end

#safe_versionString

Return the PKG-ready version, converting any invalid characters to dashes (-).

Returns:

  • (String)


310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/omnibus/packagers/pkg.rb', line 310

def safe_version
  if project.build_version =~ /\A[a-zA-Z0-9\.\+\-]+\z/
    project.build_version.dup
  else
    converted = project.build_version.gsub(/[^a-zA-Z0-9\.\+\-]+/, '-')

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

    converted
  end
end

#scripts_dirString

The path where the package scripts will live. We cannot store scripts in the top-level staging dir, because pkgbuild's --scripts flag expects a directory that does not contain the parent package.

Returns:

  • (String)


160
161
162
# File 'lib/omnibus/packagers/pkg.rb', line 160

def scripts_dir
  File.expand_path("#{staging_dir}/Scripts")
end

#signing_identity(val = NULL) ⇒ String

Set or return the signing identity. If this value is provided, Omnibus will attempt to sign the PKG.

Examples:

signing_identity "foo"

Parameters:

  • val (String) (defaults to: NULL)

    the identity to use when signing the PKG

Returns:

  • (String)

    the PKG-signing identity



113
114
115
116
117
118
119
# File 'lib/omnibus/packagers/pkg.rb', line 113

def signing_identity(val = NULL)
  if null?(val)
    @signing_identity
  else
    @signing_identity = val
  end
end

#write_distribution_filevoid

This method returns an undefined value.

Write the Distribution file to the staging area. This method generates the content of the Distribution file, which is used by productbuild to select the component packages to include in the product package.

It also includes information used to customize the UI of the Mac OS X installer.



215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/omnibus/packagers/pkg.rb', line 215

def write_distribution_file
  render_template(resource_path('distribution.xml.erb'),
    destination: "#{staging_dir}/Distribution",
    mode: 0600,
    variables: {
      friendly_name: project.friendly_name,
      identifier:    safe_identifier,
      version:       safe_version,
      component_pkg: component_pkg,
    }
  )
end

#write_scriptsvoid

This method returns an undefined value.

Copy all scripts in Omnibus::Project#package_scripts_path to the package directory.



170
171
172
173
174
175
176
177
178
179
180
# File 'lib/omnibus/packagers/pkg.rb', line 170

def write_scripts
  SCRIPT_MAP.each do |source, destination|
    source_path = File.join(project.package_scripts_path, source.to_s)

    if File.file?(source_path)
      destination_path = File.join(scripts_dir, destination)
      log.debug(log_key) { "Adding script `#{source}' to `#{destination_path}'" }
      copy_file(source_path, destination_path)
    end
  end
end