Class: Packtory::FpmExec

Inherits:
Object
  • Object
show all
Defined in:
lib/packtory/fpm_exec.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(packager, prefix_path = nil) ⇒ FpmExec

Returns a new instance of FpmExec.



13
14
15
16
# File 'lib/packtory/fpm_exec.rb', line 13

def initialize(packager, prefix_path = nil)
  @packager = packager
  @prefix_path = prefix_path
end

Class Method Details

.fpm_exec_pathObject



5
6
7
8
9
10
11
# File 'lib/packtory/fpm_exec.rb', line 5

def self.fpm_exec_path
  if !Packtory.config[:fpm_exec_path].nil? && !Packtory.config[:fpm_exec_path].empty?
    Packtory.config[:fpm_exec_path]
  else
    Packtory.bin_support_fpm_path
  end
end

Instance Method Details

#build(sfiles_map, package_file, opts = { }) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/packtory/fpm_exec.rb', line 18

def build(sfiles_map, package_file, opts = { })
  pkg_file = File.join(@packager.pkg_path, package_file)
  FileUtils.mkpath(File.dirname(pkg_file))

  cmd = build_cmd(sfiles_map, pkg_file, opts)

  Bundler.ui.info 'CMD: %s' % cmd

  unless Packtory.config[:fpm_exec_verbose]
    cmd = '%s >/dev/null 2>&1' % cmd
  end

  Bundler.clean_system(cmd)

  pkg_file
end

#build_cmd(sfiles_map, pkg_file, opts = { }) ⇒ Object



35
36
37
38
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
# File 'lib/packtory/fpm_exec.rb', line 35

def build_cmd(sfiles_map, pkg_file, opts = { })
  cmd = '%s --log %s -f -s dir' % [ self.class.fpm_exec_path, Packtory.config[:fpm_exec_log] || 'warn' ]

  unless Packtory.config[:fpm_use_ruby_path].nil?
    cmd = 'env FPM_USE_RUBY_PATH=%s %s' % [ Packtory.config[:fpm_use_ruby_path], cmd ]
  end

  case opts[:type]
  when :rpm
    cmd << ' -t rpm --rpm-os linux'
  when :deb
    cmd << ' -t deb'
  when :tgz
    cmd << ' -t tar'
  else
    raise 'Unsupported type: %s' % opts[:type]
  end

  cmd << ' -a %s -m "%s" -n %s -v %s --description "%s" --url "%s" --license "%s" --vendor "%s"' %
         [ @packager.architecture,
           @packager.maintainer,
           @packager.package_name,
           @packager.version,
           @packager.description,
           @packager.homepage,
           @packager.license,
           @packager.author ]

  cmd << ' -p %s --after-install %s --template-scripts %s %s %s' %
         [ pkg_file,
           Packtory.after_install_script_path,
           package_dependencies,
           template_values,
           source_files_map(sfiles_map) ]

  cmd
end

#package_dependenciesObject



93
94
95
96
97
98
99
100
101
# File 'lib/packtory/fpm_exec.rb', line 93

def package_dependencies
  @packager.opts[:dependencies].collect do |k, v|
    if v.nil?
      '-d %s' % k
    else
      '-d "%s%s"' % [ k, v ]
    end
  end.join(' ')
end

#source_files_map(files) ⇒ Object



73
74
75
76
77
# File 'lib/packtory/fpm_exec.rb', line 73

def source_files_map(files)
  files.inject([ ]) do |a, (k,v)|
    a << '%s=%s' % [ k, v ]; a
  end.join(' ')
end

#template_valuesObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/packtory/fpm_exec.rb', line 79

def template_values
  values = { }.merge(@packager.template_scripts_values)

  if !@prefix_path.nil?
    values['pg_PACKAGE_PATH'] = @prefix_path % @packager.package_name
  else
    values['pg_PACKAGE_PATH'] = '<'
  end

  values.collect do |k, v|
    '--template-value %s="%s"' % [ k, v ]
  end.join(' ')
end