fpm 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ class FPM::Package::Puppet < FPM::Package
18
18
  # this package.
19
19
  def generate_specfile(builddir)
20
20
  paths = []
21
- @logger.info("PWD: #{File.join(builddir, unpack_data_to)}")
21
+ logger.info("PWD: #{File.join(builddir, unpack_data_to)}")
22
22
  fileroot = File.join(builddir, unpack_data_to)
23
23
  Dir.chdir(fileroot) do
24
24
  Find.find(".") do |p|
@@ -26,17 +26,17 @@ class FPM::Package::Puppet < FPM::Package
26
26
  paths << p
27
27
  end
28
28
  end
29
- @logger.info(paths[-1])
29
+ logger.info(paths[-1])
30
30
  manifests = %w{package.pp package/remove.pp}
31
31
 
32
32
  ::Dir.mkdir(File.join(builddir, "manifests"))
33
33
  manifests.each do |manifest|
34
34
  dir = File.join(builddir, "manifests", File.dirname(manifest))
35
- @logger.info("manifests targeting: #{dir}")
35
+ logger.info("manifests targeting: #{dir}")
36
36
  ::Dir.mkdir(dir) if !File.directory?(dir)
37
37
 
38
38
  File.open(File.join(builddir, "manifests", manifest), "w") do |f|
39
- @logger.info("manifest: #{f.path}")
39
+ logger.info("manifest: #{f.path}")
40
40
  template = template(File.join("puppet", "#{manifest}.erb"))
41
41
  ::Dir.chdir(fileroot) do
42
42
  f.puts template.result(binding)
@@ -62,7 +62,7 @@ class FPM::Package::Puppet < FPM::Package
62
62
 
63
63
  if File.exists?(params[:output])
64
64
  # TODO(sissel): Allow folks to choose output?
65
- @logger.error("Puppet module directory '#{params[:output]}' already " \
65
+ logger.error("Puppet module directory '#{params[:output]}' already " \
66
66
  "exists. Delete it or choose another output (-p flag)")
67
67
  end
68
68
 
@@ -71,7 +71,7 @@ class FPM::Package::Puppet < FPM::Package
71
71
 
72
72
  # Copy 'files' from builddir to :output/files
73
73
  Find.find("files", "manifests") do |path|
74
- @logger.info("Copying path: #{path}")
74
+ logger.info("Copying path: #{path}")
75
75
  if File.directory?(path)
76
76
  ::Dir.mkdir(File.join(params[:output], path))
77
77
  else
@@ -100,7 +100,7 @@ class FPM::Package::Puppet < FPM::Package
100
100
  return pwent.name
101
101
  rescue ArgumentError => e
102
102
  # Invalid user id? No user? Return the uid.
103
- @logger.warn("Failed to find username for uid #{uid}")
103
+ logger.warn("Failed to find username for uid #{uid}")
104
104
  return uid.to_s
105
105
  end
106
106
  end # def uid2user
@@ -112,7 +112,7 @@ class FPM::Package::Puppet < FPM::Package
112
112
  return grent.name
113
113
  rescue ArgumentError => e
114
114
  # Invalid user id? No user? Return the uid.
115
- @logger.warn("Failed to find group for gid #{gid}")
115
+ logger.warn("Failed to find group for gid #{gid}")
116
116
  return gid.to_s
117
117
  end
118
118
  end # def uid2user
@@ -32,7 +32,7 @@ class FPM::Package::Python < FPM::Package
32
32
  option "--package-prefix", "NAMEPREFIX",
33
33
  "(DEPRECATED, use --package-name-prefix) Name to prefix the package " \
34
34
  "name with." do |value|
35
- @logger.warn("Using deprecated flag: --package-prefix. Please use " \
35
+ logger.warn("Using deprecated flag: --package-prefix. Please use " \
36
36
  "--package-name-prefix")
37
37
  value
38
38
  end
@@ -89,7 +89,7 @@ class FPM::Package::Python < FPM::Package
89
89
  end
90
90
 
91
91
  if !File.exists?(setup_py)
92
- @logger.error("Could not find 'setup.py'", :path => setup_py)
92
+ logger.error("Could not find 'setup.py'", :path => setup_py)
93
93
  raise "Unable to find python package; tried #{setup_py}"
94
94
  end
95
95
 
@@ -108,7 +108,7 @@ class FPM::Package::Python < FPM::Package
108
108
  return path
109
109
  end
110
110
 
111
- @logger.info("Trying to download", :package => package)
111
+ logger.info("Trying to download", :package => package)
112
112
 
113
113
  if version.nil?
114
114
  want_pkg = "#{package}"
@@ -121,12 +121,12 @@ class FPM::Package::Python < FPM::Package
121
121
 
122
122
  if attributes[:python_pip].nil?
123
123
  # no pip, use easy_install
124
- @logger.debug("no pip, defaulting to easy_install", :easy_install => attributes[:python_easyinstall])
124
+ logger.debug("no pip, defaulting to easy_install", :easy_install => attributes[:python_easyinstall])
125
125
  safesystem(attributes[:python_easyinstall], "-i",
126
126
  attributes[:python_pypi], "--editable", "-U",
127
127
  "--build-directory", target, want_pkg)
128
128
  else
129
- @logger.debug("using pip", :pip => attributes[:python_pip])
129
+ logger.debug("using pip", :pip => attributes[:python_pip])
130
130
  safesystem(attributes[:python_pip], "install", "--no-deps", "--no-install", "-i", attributes[:python_pypi], "-U", "--build", target, want_pkg)
131
131
  end
132
132
 
@@ -154,14 +154,14 @@ class FPM::Package::Python < FPM::Package
154
154
  ].join("\n")
155
155
  safesystem("#{attributes[:python_bin]} -c '#{json_test_code}'")
156
156
  rescue FPM::Util::ProcessFailed => e
157
- @logger.error("Your python environment is missing json support (either json or simplejson python module). I cannot continue without this.", :python => attributes[:python_bin], :error => e)
157
+ logger.error("Your python environment is missing json support (either json or simplejson python module). I cannot continue without this.", :python => attributes[:python_bin], :error => e)
158
158
  raise FPM::Util::ProcessFailed, "Python (#{attributes[:python_bin]}) is missing simplejson or json modules."
159
159
  end
160
160
 
161
161
  begin
162
162
  safesystem("#{attributes[:python_bin]} -c 'import pkg_resources'")
163
163
  rescue FPM::Util::ProcessFailed => e
164
- @logger.error("Your python environment is missing a working setuptools module. I tried to find the 'pkg_resources' module but failed.", :python => attributes[:python_bin], :error => e)
164
+ logger.error("Your python environment is missing a working setuptools module. I tried to find the 'pkg_resources' module but failed.", :python => attributes[:python_bin], :error => e)
165
165
  raise FPM::Util::ProcessFailed, "Python (#{attributes[:python_bin]}) is missing pkg_resources module."
166
166
  end
167
167
 
@@ -184,20 +184,20 @@ class FPM::Package::Python < FPM::Package
184
184
  # Capture the output, which will be JSON metadata describing this python
185
185
  # package. See fpm/lib/fpm/package/pyfpm/get_metadata.py for more
186
186
  # details.
187
- @logger.info("fetching package metadata", :setup_cmd => setup_cmd)
187
+ logger.info("fetching package metadata", :setup_cmd => setup_cmd)
188
188
 
189
189
  success = safesystem(setup_cmd)
190
190
  #%x{#{setup_cmd}}
191
191
  if !success
192
- @logger.error("setup.py get_metadata failed", :command => setup_cmd,
192
+ logger.error("setup.py get_metadata failed", :command => setup_cmd,
193
193
  :exitcode => $?.exitstatus)
194
194
  raise "An unexpected error occurred while processing the setup.py file"
195
195
  end
196
196
  File.read(tmp)
197
197
  end
198
- @logger.debug("result from `setup.py get_metadata`", :data => output)
198
+ logger.debug("result from `setup.py get_metadata`", :data => output)
199
199
  metadata = JSON.parse(output)
200
- @logger.info("object output of get_metadata", :json => metadata)
200
+ logger.info("object output of get_metadata", :json => metadata)
201
201
 
202
202
  self.architecture = metadata["architecture"]
203
203
  self.description = metadata["description"]
@@ -223,14 +223,14 @@ class FPM::Package::Python < FPM::Package
223
223
  dep_re = /^([^<>!= ]+)\s*(?:([<>!=]{1,2})\s*(.*))?$/
224
224
  match = dep_re.match(dep)
225
225
  if match.nil?
226
- @logger.error("Unable to parse dependency", :dependency => dep)
226
+ logger.error("Unable to parse dependency", :dependency => dep)
227
227
  raise FPM::InvalidPackageConfiguration, "Invalid dependency '#{dep}'"
228
228
  end
229
229
  name, cmp, version = match.captures
230
230
 
231
231
  # convert == to =
232
232
  if cmp == "=="
233
- @logger.info("Converting == dependency requirement to =", :dependency => dep )
233
+ logger.info("Converting == dependency requirement to =", :dependency => dep )
234
234
  cmp = "="
235
235
  end
236
236
 
@@ -98,6 +98,11 @@ class FPM::Package::RPM < FPM::Package
98
98
  option "--attr", "ATTRFILE",
99
99
  "Set the attribute for a file (%attr).",
100
100
  :multivalued => true, :attribute_name => :attrs
101
+
102
+ option "--init", "FILEPATH", "Add FILEPATH as an init script",
103
+ :multivalued => true do |file|
104
+ next File.expand_path(file)
105
+ end
101
106
 
102
107
  rpmbuild_filter_from_provides = []
103
108
  option "--filter-from-provides", "REGEX",
@@ -135,8 +140,23 @@ class FPM::Package::RPM < FPM::Package
135
140
  "posttrans script" do |val|
136
141
  File.expand_path(val) # Get the full path to the script
137
142
  end # --posttrans
138
- private
139
143
 
144
+ ["before-install","after-install","before-uninstall","after-target-uninstall"].each do |trigger_type|
145
+ rpm_trigger = []
146
+ option "--trigger-#{trigger_type}", "'[OPT]PACKAGE: FILEPATH'", "Adds a rpm trigger script located in FILEPATH, " \
147
+ "having 'OPT' options and linking to 'PACKAGE'. PACKAGE can be a comma seperated list of packages. " \
148
+ "See: http://rpm.org/api/4.4.2.2/triggers.html" do |trigger|
149
+ match = trigger.match(/^(\[.*\]|)(.*): (.*)$/)
150
+ @logger.fatal("Trigger '#{trigger_type}' definition can't be parsed ('#{trigger}')") unless match
151
+ opt, pkg, file = match.captures
152
+ @logger.fatal("File given for --trigger-#{trigger_type} does not exist (#{file})") unless File.exists?(file)
153
+ rpm_trigger << [pkg, File.read(file), opt.tr('[]','')]
154
+ next rpm_trigger
155
+ end
156
+ end
157
+
158
+ private
159
+
140
160
  # Fix path name
141
161
  # Replace [ with [\[] to make rpm not use globs
142
162
  # Replace * with [*] to make rpm not use globs
@@ -167,7 +187,7 @@ class FPM::Package::RPM < FPM::Package
167
187
 
168
188
  # Stat the original filename in the relative staging path
169
189
  ::Dir.chdir(staging_path) do
170
- stat = File.stat(original_file.gsub(/\"/, '').sub(/^\//,''))
190
+ stat = File.lstat(original_file.gsub(/\"/, '').sub(/^\//,''))
171
191
 
172
192
  # rpm_user and rpm_group attribute should override file ownership
173
193
  # otherwise use the current file user/group by name.
@@ -257,7 +277,7 @@ class FPM::Package::RPM < FPM::Package
257
277
  nextversion = version.split('.').collect { |v| v.to_i }
258
278
  nextversion[-1] += 1
259
279
  nextversion = nextversion.join(".")
260
- @logger.warn("Converting dependency #{dep} to #{name} >= #{version}, #{name} < #{nextversion}")
280
+ logger.warn("Converting dependency #{dep} to #{name} >= #{version}, #{name} < #{nextversion}")
261
281
  ["#{name} >= #{version}", "#{name} < #{nextversion}"]
262
282
  else
263
283
  dep
@@ -270,7 +290,7 @@ class FPM::Package::RPM < FPM::Package
270
290
  # Skip scripts not set
271
291
  next if script_path.nil?
272
292
  if !File.exists?(script_path)
273
- @logger.error("No such file (for #{scriptname.to_s}): #{script_path.inspect}")
293
+ logger.error("No such file (for #{scriptname.to_s}): #{script_path.inspect}")
274
294
  script_errors << script_path
275
295
  end
276
296
  # Load the script into memory.
@@ -282,6 +302,21 @@ class FPM::Package::RPM < FPM::Package
282
302
  setscript.call(:rpm_pretrans)
283
303
  end # def converted
284
304
 
305
+ def rpm_get_trigger_type(flag)
306
+ puts "#{flag.to_s(2)}"
307
+ if (flag & (1 << 25)) == (1 << 25)
308
+ :rpm_trigger_before_install
309
+ elsif (flag & (1 << 16)) == (1 << 16)
310
+ :rpm_trigger_after_install
311
+ elsif (flag & (1 << 17)) == (1 << 17)
312
+ :rpm_trigger_before_uninstall
313
+ elsif (flag & (1 << 18)) == (1 << 18)
314
+ :rpm_trigger_after_target_uninstall
315
+ else
316
+ @logger.fatal("I don't know about this triggerflag ('#{flag}')")
317
+ end
318
+ end # def rpm_get_trigger
319
+
285
320
  def input(path)
286
321
  rpm = ::RPM::File.new(path)
287
322
 
@@ -313,7 +348,17 @@ class FPM::Package::RPM < FPM::Package
313
348
  # Also taking into account the value of tags[preinprog] etc, something like:
314
349
  # #!#{tags[:preinprog]}
315
350
  # #{tags[prein]}
316
- # TODO(sissel): put 'trigger scripts' stuff into attributes
351
+
352
+ val = tags[:triggerindex].zip(tags[:triggername],tags[:triggerflags],tags[:triggerversion]).group_by{ |x| x[0]}
353
+ val = val.collect do |order,data|
354
+ new_data = data.collect { |x| [ x[1], rpm.operator(x[2]), x[3]].join(" ").strip}.join(", ")
355
+ [order, rpm_get_trigger_type(data[0][2]), new_data]
356
+ end
357
+ val.each do |order, attr,data|
358
+ self.attributes[attr] = [] if self.attributes[attr].nil?
359
+ scriptprog = (tags[:triggerscriptprog][order] == '/bin/sh') ? "" : "-p #{tags[:triggerscriptprog][order]}"
360
+ self.attributes[attr] << [data,tags[:triggerscripts][order],scriptprog]
361
+ end
317
362
 
318
363
  if !attributes[:no_auto_depends?]
319
364
  self.dependencies += rpm.requires.collect do |name, operator, version|
@@ -415,6 +460,15 @@ class FPM::Package::RPM < FPM::Package
415
460
 
416
461
  self.config_files = allconfigs.map { |x| File.join("/", x) }
417
462
 
463
+ # add init script if present
464
+ (attributes[:rpm_init_list] or []).each do |init|
465
+ name = File.basename(init, ".init")
466
+ dest_init = File.join(staging_path, "etc/init.d/#{name}")
467
+ FileUtils.mkdir_p(File.dirname(dest_init))
468
+ FileUtils.cp init, dest_init
469
+ File.chmod(0755, dest_init)
470
+ end
471
+
418
472
  (attributes[:rpm_rpmbuild_define] or []).each do |define|
419
473
  args += ["--define", define]
420
474
  end
@@ -434,7 +488,7 @@ class FPM::Package::RPM < FPM::Package
434
488
 
435
489
  args << specfile
436
490
 
437
- @logger.info("Running rpmbuild", :args => args)
491
+ logger.info("Running rpmbuild", :args => args)
438
492
  safesystem(*args)
439
493
 
440
494
  ::Dir["#{build_path}/RPMS/**/*.rpm"].each do |rpmpath|
@@ -454,7 +508,7 @@ class FPM::Package::RPM < FPM::Package
454
508
 
455
509
  def version
456
510
  if @version.kind_of?(String) and @version.include?("-")
457
- @logger.warn("Package version '#{@version}' includes dashes, converting" \
511
+ logger.warn("Package version '#{@version}' includes dashes, converting" \
458
512
  " to underscores")
459
513
  @version = @version.gsub(/-/, "_")
460
514
  end
@@ -467,7 +521,7 @@ class FPM::Package::RPM < FPM::Package
467
521
  return @epoch if @epoch.is_a?(Numeric)
468
522
 
469
523
  if @epoch.nil? or @epoch.empty?
470
- @logger.warn("no value for epoch is set, defaulting to nil")
524
+ logger.warn("no value for epoch is set, defaulting to nil")
471
525
  return nil
472
526
  end
473
527
 
@@ -46,7 +46,7 @@ class FPM::Package::Sh < FPM::Package
46
46
  # Returns the path to the tar file containing the packed up staging directory
47
47
  def payload
48
48
  payload_tar = build_path("payload.tar")
49
- @logger.info("Creating payload tar ", :path => payload_tar)
49
+ logger.info("Creating payload tar ", :path => payload_tar)
50
50
 
51
51
  args = [ tar_cmd,
52
52
  "-C",
@@ -56,7 +56,7 @@ module FPM::Util
56
56
  raise ExecutableNotFound.new(program)
57
57
  end
58
58
 
59
- @logger.debug("Running command", :args => args)
59
+ logger.debug("Running command", :args => args)
60
60
 
61
61
  # Create a pair of pipes to connect the
62
62
  # invoked process to the cabin logger
@@ -69,10 +69,10 @@ module FPM::Util
69
69
 
70
70
  process.start
71
71
  stdout_w.close; stderr_w.close
72
- @logger.debug('Process is running', :pid => process.pid)
72
+ logger.debug('Process is running', :pid => process.pid)
73
73
  # Log both stdout and stderr as 'info' because nobody uses stderr for
74
74
  # actually reporting errors and as a result 'stderr' is a misnomer.
75
- @logger.pipe(stdout_r => :info, stderr_r => :info)
75
+ logger.pipe(stdout_r => :info, stderr_r => :info)
76
76
 
77
77
  process.wait
78
78
  success = (process.exit_code == 0)
@@ -95,7 +95,7 @@ module FPM::Util
95
95
  raise ExecutableNotFound.new(program)
96
96
  end
97
97
 
98
- @logger.debug("Running command", :args => args)
98
+ logger.debug("Running command", :args => args)
99
99
 
100
100
  stdout_r, stdout_w = IO.pipe
101
101
  stderr_r, stderr_w = IO.pipe
@@ -108,7 +108,7 @@ module FPM::Util
108
108
  stdout_w.close; stderr_w.close
109
109
  stdout_r_str = stdout_r.read
110
110
  stdout_r.close; stderr_r.close
111
- @logger.debug("Process is running", :pid => process.pid)
111
+ logger.debug("Process is running", :pid => process.pid)
112
112
 
113
113
  process.wait
114
114
  success = (process.exit_code == 0)
@@ -223,4 +223,8 @@ module FPM::Util
223
223
  return [constraint]
224
224
  end
225
225
  end #def expand_pesimistic_constraints
226
+
227
+ def logger
228
+ @logger ||= Cabin::Channel.get
229
+ end # def logger
226
230
  end # module FPM::Util
@@ -1,3 +1,3 @@
1
1
  module FPM
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -1,7 +1,9 @@
1
1
  Package: <%= name %>
2
2
  Version: <%= "#{epoch}:" if epoch %><%= version %><%= "-" + iteration.to_s if iteration %>
3
3
  License: <%= license %>
4
+ <% if !vendor.nil? and !vendor.empty? -%>
4
5
  Vendor: <%= vendor %>
6
+ <% end -%>
5
7
  Architecture: <%= architecture %>
6
8
  Maintainer: <%= maintainer %>
7
9
  Installed-Size: <%= attributes[:deb_installed_size] %>
@@ -0,0 +1,5 @@
1
+ <%= name %> (<%= "#{epoch}:" if epoch %><%= version %><%= "-" + iteration.to_s if iteration %>) whatever; urgency=medium
2
+
3
+ * Package created with FPM.
4
+
5
+ -- <%= maintainer %>[two spaces] <%= Time.now.strftime("%a, %d %b %Y %T %z") %>
@@ -0,0 +1,31 @@
1
+ after_upgrade() {
2
+ <% if script?(:after_upgrade) -%>
3
+ <%= script(:after_upgrade) %>
4
+ <% end -%>
5
+ }
6
+
7
+ after_install() {
8
+ <% if script?(:after_install) -%>
9
+ <%= script(:after_install) %>
10
+ <% end -%>
11
+ }
12
+
13
+ if [ "${1}" = "configure " -a -z "${2}" ]
14
+ then
15
+ # "after install" here
16
+ after_install
17
+ elif [ "${1}" = "configure" -a -n "${2}" ]
18
+ then
19
+ upgradeFromVersion="${2}"
20
+ # "after upgrade" here
21
+ # NOTE: This slot is also used when deb packages are removed,
22
+ # but their config files aren't, but a newer version of the
23
+ # package is installed later, called "Config-Files" state.
24
+ # basically, that still looks a _lot_ like an upgrade to me.
25
+ after_upgrade "${2}"
26
+ elif echo "${1}" | grep -E -q "(abort|fail)"
27
+ then
28
+ echo "Failed to install before the post-installation script was run." >&2
29
+ exit 1
30
+ fi
31
+
@@ -0,0 +1,37 @@
1
+ after_remove() {
2
+ <% if script?(:after_remove) -%>
3
+ <%= script(:after_remove) %>
4
+ <% end -%>
5
+ }
6
+
7
+ dummy() {
8
+ }
9
+
10
+
11
+ if [ "${1}" = "remove" ]
12
+ then
13
+ # "after remove" goes here
14
+ after_remove
15
+ elif [ "${1}" = "purge" -a -z "${2}" ]
16
+ then
17
+ # like "on remove", but executes after dpkg deletes config files
18
+ # 'apt-get purge' runs 'on remove' section, then this section.
19
+ # Maybe we ignore this; it seems really fine-grained.
20
+ # There is no equivalent in RPM or ARCH. A debian-specific argument
21
+ # might perhaps be used here, but most people
22
+ # probably don't need it.
23
+ dummy
24
+ elif [ "${1}" = "upgrade" ]
25
+ then
26
+ # This represents the case where the old package's postrm is called after
27
+ # the 'preinst' script is called.
28
+ # We should ignore this and just use 'preinst upgrade' and
29
+ # 'postinst configure'. The newly installed package should do the
30
+ # upgrade, not the uninstalled one, since it can't anticipate what new
31
+ # things it will have to do to upgrade for the new version.
32
+ dummy
33
+ elif echo "${1}" | grep -E -q '(fail|abort)'
34
+ then
35
+ echo "Failed to install before the post-removal script was run." >&2
36
+ exit 1
37
+ fi