Class: Omnibus::Packager::PKG
Constant Summary collapse
- SCRIPT_MAP =
{ # Default Omnibus naming preinst: 'preinstall', postinst: 'postinstall', # Default PKG naming preinstall: 'preinstall', postinstall: 'postinstall', }.freeze
Constants included from Util
Constants included from NullArgumentable
Instance Attribute Summary
Attributes inherited from Base
DSL methods collapse
-
#identifier(val = NULL) ⇒ String
The identifer for the PKG package.
-
#signing_identity(val = NULL) ⇒ String
Set or return the signing identity.
Instance Method Summary collapse
-
#build_component_pkg ⇒ void
Construct the intermediate build product.
-
#build_product_pkg ⇒ void
Construct the product package.
-
#component_pkg ⇒ String
The name of the (only) component package.
-
#final_pkg ⇒ String
The full path where the product package was/will be written.
- #package_name ⇒ Object
-
#resources_dir ⇒ String
The path where the product package resources will live.
-
#safe_base_package_name ⇒ String
Return the PKG-ready base package name, removing any invalid characters.
-
#safe_build_iteration ⇒ String
This is actually just the regular build_iternation, but it felt lonely among all the other
safe_*
methods. -
#safe_identifier ⇒ String
The identifier for this mac package (the com.whatever.thing.whatever).
-
#safe_version ⇒ String
Return the PKG-ready version, converting any invalid characters to dashes (
-
). -
#scripts_dir ⇒ String
The path where the package scripts will live.
-
#write_distribution_file ⇒ void
Write the Distribution file to the staging area.
-
#write_scripts ⇒ void
Copy all scripts in Omnibus::Project#package_scripts_path to the package directory.
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
Methods included from NullArgumentable
Methods included from Logging
Methods included from Digestable
Constructor Details
This class inherits a constructor from Omnibus::Packager::Base
Instance Method Details
#build_component_pkg ⇒ void
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 = "pkgbuild \\\\\n--identifier \"\#{safe_identifier}\" \\\\\n--version \"\#{safe_version}\" \\\\\n--scripts \"\#{scripts_dir}\" \\\\\n--root \"\#{project.install_dir}\" \\\\\n--install-location \"\#{project.install_dir}\" \\\\\n\"\#{component_pkg}\"\n".gsub(/^ {8}/, '') Dir.chdir(staging_dir) do shellout!(command) end end |
#build_product_pkg ⇒ void
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 = "productbuild \\\\\n--distribution \"\#{staging_dir}/Distribution\" \\\\\n--resources \"\#{resources_dir}\" \\\\\n".gsub(/^ {8}/, '') 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_pkg ⇒ String
The name of the (only) component package.
255 256 257 |
# File 'lib/omnibus/packagers/pkg.rb', line 255 def component_pkg "#{safe_base_package_name}-core.pkg" end |
#final_pkg ⇒ String
The full path where the product package was/will be written.
136 137 138 |
# File 'lib/omnibus/packagers/pkg.rb', line 136 def final_pkg File.("#{Config.package_dir}/#{package_name}") end |
#identifier(val = NULL) ⇒ String
The identifer for the PKG package.
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_name ⇒ Object
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_dir ⇒ String
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.
148 149 150 |
# File 'lib/omnibus/packagers/pkg.rb', line 148 def resources_dir File.("#{staging_dir}/Resources") end |
#safe_base_package_name ⇒ String
Return the PKG-ready base package name, removing any invalid characters.
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_iteration ⇒ String
This is actually just the regular build_iternation, but it felt lonely
among all the other safe_*
methods.
300 301 302 |
# File 'lib/omnibus/packagers/pkg.rb', line 300 def safe_build_iteration project.build_iteration end |
#safe_identifier ⇒ String
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.
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_version ⇒ String
Return the PKG-ready version, converting any invalid characters to dashes
(-
).
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_dir ⇒ String
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.
160 161 162 |
# File 'lib/omnibus/packagers/pkg.rb', line 160 def scripts_dir File.("#{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.
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_file ⇒ void
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_scripts ⇒ void
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 |