Class: Omnibus::Packager::BFF
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
Constants included from NullArgumentable
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#bff_version ⇒ String
Return the BFF-specific version for this package.
-
#create_bff_file ⇒ void
Create the bff file using
mkinstallp
. -
#create_bff_file_name ⇒ String
Create bff file name.
- #package_name ⇒ Object
-
#safe_architecture ⇒ String
The architecture for this RPM package.
-
#safe_base_package_name ⇒ String
Return the BFF-ready base package name, converting any invalid characters to dashes (
-
). -
#scripts_install_dir ⇒ String
The path where the package scripts in the install directory.
-
#scripts_staging_dir ⇒ String
The path where the package scripts will staged.
-
#write_gen_template ⇒ void
Create the gen template for
mkinstallp
. -
#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
#bff_version ⇒ String
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_file ⇒ void
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_name ⇒ String
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_name ⇒ Object
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_architecture ⇒ String
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_name ⇒ String
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_dir ⇒ String
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.("#{project.install_dir}/embedded/share/installp") end |
#scripts_staging_dir ⇒ String
The path where the package scripts will staged.
72 73 74 |
# File 'lib/omnibus/packagers/bff.rb', line 72 def scripts_staging_dir File.("#{staging_dir}#{scripts_install_dir}") end |
#write_gen_template ⇒ void
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_scripts ⇒ void
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 |