Class: FPM::Package::Tar

Inherits:
FPM::Package show all
Defined in:
lib/fpm/package/tar.rb

Overview

Use a tarball as a package.

This provides no metadata. Both input and output are supported.

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

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

#ar_cmd, #ar_cmd_deterministic?, #copied_entries, #copy_entry, #copy_metadata, #default_shell, #execmd, #expand_pessimistic_constraints, #logger, #mknod_w, #program_exists?, #program_in_path?, #safesystem, #safesystemout, #tar_cmd, #tar_cmd_supports_sort_names_and_set_mtime?

Constructor Details

This class inherits a constructor from FPM::Package

Instance Method Details

#input(input_path) ⇒ Object

Input a tarball. Compressed tarballs should be OK.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fpm/package/tar.rb', line 13

def input(input_path)
  # use part of the filename as the package name
  self.name = File.basename(input_path).split(".").first

  # Unpack the tarball to the build path before ultimately moving it to
  # staging.
  args = ["-xf", input_path, "-C", build_path]

  # Add the tar compression flag if necessary
  tar_compression_flag(input_path).tap do |flag|
    args << flag unless flag.nil?
  end

  safesystem("tar", *args)

  # use dir to set stuff up properly, mainly so I don't have to reimplement
  # the chdir/prefix stuff special for tar.
  dir = convert(FPM::Package::Dir)
  if attributes[:chdir]
    dir.attributes[:chdir] = File.join(build_path, attributes[:chdir])
  else
    dir.attributes[:chdir] = build_path
  end

  cleanup_staging
  # Tell 'dir' to input "." and chdir/prefix will help it figure out the
  # rest.
  dir.input(".")
  @staging_path = dir.staging_path
  dir.cleanup_build
end

#output(output_path) ⇒ Object

Output a tarball.

If the output path ends predictably (like in .tar.gz) it will try to obey the compression type.


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fpm/package/tar.rb', line 49

def output(output_path)
  output_check(output_path)

  # Write the scripts, too.
  write_scripts

  # Unpack the tarball to the staging path
  args = ["-cf", output_path, "-C", staging_path]
  tar_compression_flag(output_path).tap do |flag|
    args << flag unless flag.nil?
  end
  args << "."

  safesystem("tar", *args)
end

#tar_compression_flag(path) ⇒ Object

Generate the proper tar flags based on the path name.


66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fpm/package/tar.rb', line 66

def tar_compression_flag(path)
  case path
    when /\.tar\.bz2$/
      return "-j"
    when /\.tar\.gz$|\.tgz$/
      return "-z"
    when /\.tar\.xz$/
      return "-J"
    else
      return nil
  end
end