Class: FPM::Package::Sh

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

Overview

Support for self extracting sh files (.sh files)

This class only supports output of packages.

The sh package is a single sh file with a tar payload concatenated to the end. The script can unpack the tarball to install it and call optional post install scripts.

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, #input, 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, #erbnew, #execmd, #expand_pessimistic_constraints, #logger, #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

#create_scriptsObject



26
27
28
29
30
# File 'lib/fpm/package/sh.rb', line 26

def create_scripts
  if script?(:after_install)
    File.write(File.join(fpm_meta_path, "after_install"), script(:after_install))
  end
end

#fpm_meta_pathObject

Where we keep metadata and post install scripts and such



62
63
64
65
66
67
68
# File 'lib/fpm/package/sh.rb', line 62

def fpm_meta_path
  @fpm_meta_path ||= begin
                       path = File.join(staging_path, ".fpm")
                       FileUtils.mkdir_p(path)
                       path
                     end
end

#install_scriptObject



32
33
34
35
36
37
38
# File 'lib/fpm/package/sh.rb', line 32

def install_script
  path = build_path("installer.sh")
  File.open(path, "w") do |file|
    file.write template("sh.erb").result(binding)
  end
  path
end

#output(output_path) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/fpm/package/sh.rb', line 18

def output(output_path)
  create_scripts

  # Make one file. The installscript can unpack itself.
  `cat #{install_script} #{payload} > #{output_path}`
  FileUtils.chmod("+x", output_path)
end

#payloadObject

Returns the path to the tar file containing the packed up staging directory



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fpm/package/sh.rb', line 41

def payload
  payload_tar = build_path("payload.tar")
  logger.info("Creating payload tar ", :path => payload_tar)

  args = [ tar_cmd,
           "-C",
           staging_path,
           "-cf",
           payload_tar,
           "--owner=0",
           "--group=0",
           "--numeric-owner",
           "." ]

  unless safesystem(*args)
    raise "Command failed while creating payload tar: #{args}"
  end
  payload_tar
end