Class: FPM::Package::Dir
- Inherits:
-
FPM::Package
- Object
- FPM::Package
- FPM::Package::Dir
- Defined in:
- lib/fpm/package/dir.rb
Overview
A directory package.
This class supports both input and output. As a note, ‘output’ will only emit the files, not any metadata. This is an effective way to extract another package type.
Instance Attribute Summary
Attributes inherited from FPM::Package
#architecture, #attributes, #attrs, #category, #config_files, #conflicts, #dependencies, #description, #directories, #epoch, #iteration, #license, #maintainer, #name, #provides, #replaces, #scripts, #url, #vendor, #version
Instance Method Summary collapse
-
#input(path) ⇒ Object
Add a new path to this package.
-
#output(output_path) ⇒ Object
Output this package to the given directory.
Methods inherited from FPM::Package
apply_options, #build_path, #cleanup, #cleanup_build, #cleanup_staging, #convert, #converted_from, default_attributes, #edit_file, #files, inherited, #initialize, option, #script, #staging_path, #to_s, #type, type, types
Methods included from Util
#copied_entries, #copy_entry, #copy_metadata, #default_shell, #execmd, #expand_pessimistic_constraints, #logger, #mknod_w, #program_exists?, #program_in_path?, #safesystem, #safesystemout, #tar_cmd
Constructor Details
This class inherits a constructor from FPM::Package
Instance Method Details
#input(path) ⇒ Object
Add a new path to this package.
A special handling of the path occurs if it includes a ‘=’ symbol. You can say “source=destination” and it will copy files from that source to the given destination in the package.
This lets you take a local directory and map it to the desired location at packaging time. Such as: “./src/redis-server=/usr/local/bin” will make the local file ./src/redis-server appear as /usr/local/bin/redis-server in your package.
If the path is a directory, it is copied recursively. The behavior of the copying is modified by the :chdir and :prefix attributes.
If :prefix is set, the destination path is prefixed with that value. If :chdir is set, the current directory is changed to that value during the copy.
Example: Copy /etc/X11 into this package as /opt/xorg/X11:
package.attributes[:prefix] = "/opt/xorg"
package.attributes[:chdir] = "/etc"
package.input("X11")
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fpm/package/dir.rb', line 39 def input(path) chdir = attributes[:chdir] || "." # Support mapping source=dest # This mapping should work the same way 'rsync -a' does # Meaning 'rsync -a source dest' # and 'source=dest' in fpm work the same as the above rsync if path =~ /.=./ && !File.exists?(chdir == '.' ? path : File.join(chdir, path)) origin, destination = path.split("=", 2) if File.directory?(origin) && origin[-1,1] == "/" chdir = chdir == '.' ? origin : File.join(chdir, origin) source = "." else origin_dir = File.dirname(origin) chdir = chdir == '.' ? origin_dir : File.join(chdir, origin_dir) source = File.basename(origin) end else source, destination = path, "/" end if attributes[:prefix] destination = File.join(attributes[:prefix], destination) end destination = File.join(staging_path, destination) logger["method"] = "input" begin ::Dir.chdir(chdir) do begin clone(source, destination) rescue Errno::ENOENT => e raise FPM::InvalidPackageConfiguration, "Cannot package the path '#{File.join(chdir, source)}', does it exist?" end end rescue Errno::ENOENT => e raise FPM::InvalidPackageConfiguration, "Cannot chdir to '#{chdir}'. Does it exist?" end # Set some defaults. This is useful because other package types # can include license data from themselves (rpms, gems, etc), # but to make sure a simple dir -> rpm works without having # to specify a license. self.license = "unknown" self.vendor = [ENV["USER"], Socket.gethostname].join("@") ensure # Clean up any logger context we added. logger.remove("method") end |
#output(output_path) ⇒ Object
Output this package to the given directory.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/fpm/package/dir.rb', line 94 def output(output_path) output_check(output_path) output_path = File.(output_path) ::Dir.chdir(staging_path) do logger["method"] = "output" clone(".", output_path) end # Write the scripts, too. scripts_path = File.join(output_path, ".scripts") ::Dir.mkdir(scripts_path) [:before_install, :after_install, :before_remove, :after_remove].each do |name| next unless script?(name) out = File.join(scripts_path, name.to_s) logger.debug("Writing script", :source => name, :target => out) File.write(out, script(name)) require "pry" binding.pry File.chmod(0755, out) end ensure logger.remove("method") end |