Class: Omnibus::Packager::BFF

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

Constant Summary collapse

SCRIPT_MAP =
{
  # Default Omnibus naming
  preinst:  'Pre-installation Script',
  postinst: 'Post-installation Script',
  prerm:    'Pre_rm Script',
  postrm:   'Unconfiguration Script',
}.freeze

Constants included from Util

Util::SHELLOUT_OPTIONS

Constants included from NullArgumentable

NullArgumentable::NULL

Instance Attribute Summary

Attributes inherited from Base

#project

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

#bff_versionString

TODO:

This is probably not the best way to extract the version and probably misses edge cases like when using git describe!

Return the BFF-specific version for this package. This is calculated using the first three digits of the version, concatenated by a dot, then suffixed with the build_iteration.


237
238
239
240
# File 'lib/omnibus/packagers/bff.rb', line 237

def bff_version
  version = project.build_version.split(/[^\d]/)[0..2].join('.')
  "#{version}.#{project.build_iteration}"
end

#create_bff_filevoid

This method returns an undefined value.

Create the bff file using mkinstallp.

Warning: This command runs as sudo! AIX requires the use of sudo to run the mkinstallp command.


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/omnibus/packagers/bff.rb', line 167

def create_bff_file
  # We are making the assumption that sudo exists.
  # Unforunately, the owner of the file in the staging directory is what
  # will be on the target machine, and mkinstallp can't tell you if that
  # is a bad thing (it usually is).
  # The match is so we only pick the lowest level of the project dir.
  # This implies that if we are in /tmp/staging/project/dir/things,
  # we will chown from 'project' on, rather than 'project/dir', which leaves
  # project owned by the build user (which is incorrect)
  shellout!("sudo chown -R 0:0 #{staging_dir}/#{project.install_dir.match(/^\/?(\w+)/)}")
  log.info(log_key) { "Creating .bff file" }

  # Since we want the owner to be root, we need to sudo the mkinstallp
  # command, otherwise it will not have access to the previously chowned
  # directory.
  shellout!("sudo /usr/sbin/mkinstallp -d #{staging_dir} -T #{staging_dir}/gen.template")

  # Copy the resulting package up to the package_dir
  FileSyncer.glob("#{staging_dir}/tmp/*.bff").each do |bff|
    copy_file(bff, File.join(Config.package_dir, create_bff_file_name))
  end
end

#create_bff_file_nameString

Create bff file name

mkinstallp names the bff file according to the version specified in the template. We want to differentiate the build specific version correctly.


199
200
201
# File 'lib/omnibus/packagers/bff.rb', line 199

def create_bff_file_name
  "#{safe_base_package_name}-#{project.build_version}-#{project.build_iteration}.#{safe_architecture}.bff"
end

#package_nameObject


54
55
56
# File 'lib/omnibus/packagers/bff.rb', line 54

def package_name
  "#{safe_base_package_name}-#{project.build_version}-#{project.build_iteration}.#{safe_architecture}.bff"
end

#safe_architectureString

The architecture for this RPM package.


247
248
249
# File 'lib/omnibus/packagers/bff.rb', line 247

def safe_architecture
  Ohai['kernel']['machine']
end

#safe_base_package_nameString

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


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/omnibus/packagers/bff.rb', line 210

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 BFF package names can only include " \
      "lowercase alphabetical characters (a-z), numbers (0-9), dots (.), " \
      "plus signs (+), and dashes (-). Converting `#{project.package_name}' to " \
      "`#{converted}'."
    end

    converted
  end
end

#scripts_install_dirString

The path where the package scripts in the install directory.


63
64
65
# File 'lib/omnibus/packagers/bff.rb', line 63

def scripts_install_dir
  File.expand_path("#{project.install_dir}/embedded/share/installp")
end

#scripts_staging_dirString

The path where the package scripts will staged.


72
73
74
# File 'lib/omnibus/packagers/bff.rb', line 72

def scripts_staging_dir
  File.expand_path("#{staging_dir}#{scripts_install_dir}")
end

#write_gen_templatevoid

This method returns an undefined value.

Create the gen template for mkinstallp.

Some details on the various lifecycle scripts:

The order of the installp scripts is:

  • install

    • pre-install

    • post-install

    • config

  • upgrade

    • pre-remove (of previous version)

    • pre-install (previous version of software not present anymore)

    • post-install

    • config

  • remove

    • unconfig

    • unpre-install

To run the new version of scc, the post-install will do. To run the previous version with an upgrade, use the pre-remove script. To run a source install of scc upon installation of installp package, use the pre-install. Upon upgrade, both the pre-remove and the pre-install scripts will run. As scc has been removed between the runs of these scripts, it will only run once during upgrade.

Keywords for scripts:

Pre-installation Script: /path/script
Unpre-installation Script: /path/script
Post-installation Script: /path/script
Pre_rm Script: /path/script
Configuration Script: /path/script
Unconfiguration Script: /path/script

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/omnibus/packagers/bff.rb', line 129

def write_gen_template
  # Create a map of scripts that exist to inject into the template
  scripts = SCRIPT_MAP.inject({}) do |hash, (script, installp_key)|
    staging_path =  File.join(scripts_staging_dir, script.to_s)

    if File.file?(staging_path)
      hash[installp_key] = staging_path
    end

    hash
  end

  # Get a list of all files
  files = FileSyncer.glob("#{staging_dir}/**/*")
            .map { |path| path.gsub(/^#{staging_dir}/, '') }

  render_template(resource_path('gen.template.erb'),
    destination: File.join(staging_dir, 'gen.template'),
    variables: {
      name:           safe_base_package_name,
      install_dir:    project.install_dir,
      friendly_name:  project.friendly_name,
      version:        bff_version,
      description:    project.description,
      files:          files,
      scripts:        scripts,
    }
  )
end

#write_scriptsvoid

This method returns an undefined value.

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


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

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

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