fpm 0.4.29 → 0.4.30

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.
data/CHANGELIST CHANGED
@@ -1,3 +1,21 @@
1
+ 0.4.30 (March 21, 2013)
2
+ - Solaris: --solaris-user and --solaris-group flags to specify
3
+ the owner of files in a package. (#342, patch by Derek Olsen)
4
+ - rpm: (bug fix) epoch of 0 is permitted now (#343, patch by Ben Hughes)
5
+ - pear: add flags --pear-bin-dir --pear-php-bin --pear-php-dir (#358, patch
6
+ by Zsolt Takács)
7
+ - New 'source' type: empty. Allows you to create packages without any files
8
+ in them (sometimes called 'meta packages'). Useful when you want to have
9
+ one package be simply dependencies or when you want to spoof a package
10
+ you don't want installed, etc. (#359, 349; patch by Pranay Kanwar)
11
+ - solaris: Add --solaris-user and --solaris-group flags (#342, Patch by Derek
12
+ Olsen)
13
+ - gem: new flag --env-shebang; default true (disable with --no-env-shebang).
14
+ Lets you disable #! (shebang) mangling done by gem installation. (#363,
15
+ patch by Grier Johnson)
16
+ - deb: fix bug on changelog handling (#376, patch by mbakke)
17
+ - rpm: fix --rpm-rpmbuild-define (#383, patch by Eric Merritt)
18
+
1
19
  0.4.29 (January 22, 2013)
2
20
  - Copy links literally, not what they point at (#337, patch by Dane Knecht)
3
21
 
@@ -364,6 +364,7 @@ class FPM::Command < Clamp::Command
364
364
  input.config_files += config_files
365
365
  input.directories += directories
366
366
 
367
+ script_errors = []
367
368
  setscript = proc do |scriptname|
368
369
  # 'self.send(scriptname) == self.before_install == --before-install
369
370
  # Gets the path to the script
@@ -373,7 +374,7 @@ class FPM::Command < Clamp::Command
373
374
 
374
375
  if !File.exists?(path)
375
376
  @logger.error("No such file (for #{scriptname.to_s}): #{path.inspect}")
376
- return 1
377
+ script_errors << path
377
378
  end
378
379
 
379
380
  # Load the script into memory.
@@ -385,6 +386,10 @@ class FPM::Command < Clamp::Command
385
386
  setscript.call(:before_remove)
386
387
  setscript.call(:after_remove)
387
388
 
389
+ # Bail if any setscript calls had errors. We don't need to log
390
+ # anything because we've already logged the error(s) above.
391
+ return 1 if script_errors.any?
392
+
388
393
  # Validate the package
389
394
  if input.name.nil? or input.name.empty?
390
395
  @logger.fatal("No name given for this package (set name with, " \
@@ -424,6 +429,9 @@ class FPM::Command < Clamp::Command
424
429
  rescue FPM::Package::InvalidArgument => e
425
430
  @logger.error("Invalid package argument: #{e}")
426
431
  return 1
432
+ rescue FPM::Util::ProcessFailed => e
433
+ @logger.error("Process failed: #{e}")
434
+ return 1
427
435
  ensure
428
436
  input.cleanup unless input.nil?
429
437
  output.cleanup unless output.nil?
@@ -488,7 +496,7 @@ class FPM::Command < Clamp::Command
488
496
  mandatory(@command.input_type == "dir", "--inputs is only valid with -s dir")
489
497
  end
490
498
 
491
- mandatory(@command.args.any? || @command.inputs,
499
+ mandatory(@command.args.any? || @command.inputs || @command.input_type == 'empty',
492
500
  "No parameters given. You need to pass additional command " \
493
501
  "arguments so that I know what you want to build packages " \
494
502
  "from. For example, for '-s dir' you would pass a list of " \
@@ -337,7 +337,13 @@ class FPM::Package
337
337
  def edit_file(path)
338
338
  editor = ENV['FPM_EDITOR'] || ENV['EDITOR'] || 'vi'
339
339
  @logger.info("Launching editor", :file => path)
340
+ command = "#{editor} #{Shellwords.escape(path)}"
340
341
  system("#{editor} #{Shellwords.escape(path)}")
342
+ if !$?.success?
343
+ raise ProcessFailed.new("'#{editor}' failed (exit code " \
344
+ "#{$?.exitstatus}) Full command was: "\
345
+ "#{command}");
346
+ end
341
347
 
342
348
  if File.size(path) == 0
343
349
  raise "Empty file after editing: #{path.inspect}"
@@ -301,8 +301,8 @@ class FPM::Package::Deb < FPM::Package
301
301
  dest_changelog = File.join(staging_path, "usr/share/doc/#{attributes[:name]}/changelog.Debian")
302
302
  FileUtils.mkdir_p(File.dirname(dest_changelog))
303
303
  FileUtils.cp attributes[:deb_changelog], dest_changelog
304
- safesystem("gzip", dest_changelog)
305
304
  File.chmod(0644, dest_changelog)
305
+ safesystem("gzip", dest_changelog)
306
306
  end
307
307
 
308
308
  args = [ tar_cmd, "-C", staging_path, compression ] + tar_flags + [ "-cf", datatar, "." ]
@@ -349,13 +349,13 @@ class FPM::Package::Deb < FPM::Package
349
349
  if name =~ /[A-Z]/
350
350
  @logger.warn("Downcasing dependency '#{name}' because deb packages " \
351
351
  " don't work so good with uppercase names")
352
- dep.gsub!(name_re) { |n| n.downcase }
352
+ dep = dep.gsub(name_re) { |n| n.downcase }
353
353
  end
354
354
 
355
355
  if dep.include?("_")
356
356
  @logger.warn("Replacing underscores with dashes in '#{dep}' because " \
357
357
  "debs don't like underscores")
358
- dep.gsub!("_", "-")
358
+ dep = dep.gsub("_", "-")
359
359
  end
360
360
 
361
361
  # Convert gem ~> X.Y.Z to '>= X.Y.Z' and << X.Y+1.0
@@ -0,0 +1,7 @@
1
+ require "fpm/package"
2
+ require "backports"
3
+
4
+ # Empty Package type. For strict/meta/virtual package creation
5
+
6
+ class FPM::Package::Empty < FPM::Package
7
+ end
@@ -35,6 +35,8 @@ class FPM::Package::Gem < FPM::Package
35
35
  :default => true
36
36
  option "--fix-dependencies", :flag, "Should the package dependencies be " \
37
37
  "prefixed?", :default => true
38
+ option "--env-shebang", :flag, "Should the target package have the " \
39
+ "shebang rewritten to use env?", :default => true
38
40
 
39
41
  def input(gem)
40
42
  # 'arg' is the name of the rubygem we should unpack.
@@ -170,7 +172,10 @@ class FPM::Package::Gem < FPM::Package
170
172
  ::FileUtils.mkdir_p(installdir)
171
173
  # TODO(sissel): Allow setting gem tool path
172
174
  args = [attributes[:gem_gem], "install", "--quiet", "--no-ri", "--no-rdoc",
173
- "--install-dir", installdir, "--ignore-dependencies", "-E"]
175
+ "--install-dir", installdir, "--ignore-dependencies"]
176
+ if attributes[:gem_env_shebang?]
177
+ args += ["-E"]
178
+ end
174
179
  if attributes[:gem_bin_path]
175
180
  bin_path = File.join(staging_path, attributes[:gem_bin_path])
176
181
  args += ["--bindir", bin_path]
@@ -13,16 +13,25 @@ class FPM::Package::PEAR < FPM::Package
13
13
  option "--channel", "CHANNEL_URL",
14
14
  "The pear channel url to use instead of the default."
15
15
 
16
- option "--channel-update", :flag,
16
+ option "--channel-update", :flag,
17
17
  "call 'pear channel-update' prior to installation"
18
18
 
19
+ option "--bin-dir", "BIN_DIR",
20
+ "Directory to put binaries in"
21
+
22
+ option "--php-bin", "PHP_BIN",
23
+ "Specify php executable path if differs from the os used for packaging"
24
+
25
+ option "--php-dir", "PHP_DIR",
26
+ "Specify php dir relative to prefix if differs from pear default (pear/php)"
27
+
19
28
  # Input a PEAR package.
20
29
  #
21
30
  # The parameter is a PHP PEAR package name.
22
31
  #
23
32
  # Attributes that affect behavior here:
24
33
  # * :prefix - changes the install root, default is /usr/share
25
- # * :pear_package_name_prefix - changes the
34
+ # * :pear_package_name_prefix - changes the
26
35
  def input(input_package)
27
36
  if !program_in_path?("pear")
28
37
  raise ExecutableNotFound.new("pear")
@@ -34,10 +43,22 @@ class FPM::Package::PEAR < FPM::Package
34
43
  installroot = attributes[:prefix] || "/usr/share"
35
44
  safesystem("pear", "config-create", staging_path(installroot), config)
36
45
 
46
+ if attributes[:pear_php_dir]
47
+ @logger.info("Setting php_dir", :php_dir => attributes[:pear_php_dir])
48
+ safesystem("pear", "-c", config, "config-set", "php_dir", "#{staging_path(installroot)}/#{attributes[:pear_php_dir]}")
49
+ end
50
+
51
+ bin_dir = attributes[:pear_bin_dir] || "usr/bin"
52
+ @logger.info("Setting bin_dir", :bin_dir => bin_dir)
53
+ safesystem("pear", "-c", config, "config-set", "bin_dir", bin_dir)
54
+
55
+ php_bin = attributes[:pear_php_bin] || "/usr/bin/php"
56
+ @logger.info("Setting php_bin", :php_bin => php_bin)
57
+ safesystem("pear", "-c", config, "config-set", "php_bin", php_bin)
58
+
37
59
  # try channel-discover
38
60
  if !attributes[:pear_channel].nil?
39
61
  @logger.info("Custom channel specified", :channel => attributes[:pear_channel])
40
- p ["pear", "-c", config, "channel-discover", attributes[:pear_channel]]
41
62
  safesystem("pear", "-c", config, "channel-discover", attributes[:pear_channel])
42
63
  input_package = "#{attributes[:pear_channel]}/#{input_package}"
43
64
  @logger.info("Prefixing package name with channel", :package => input_package)
@@ -50,25 +71,32 @@ class FPM::Package::PEAR < FPM::Package
50
71
  safesystem("pear", "-c", config, "channel-update", channel)
51
72
  end
52
73
 
74
+ @logger.info("Installing pear package", :package => input_package,
75
+ :directory => staging_path)
76
+ ::Dir.chdir(staging_path) do
77
+ safesystem("pear", "-c", config, "install", "-n", "-f", input_package)
78
+ end
79
+
53
80
  pear_cmd = "pear -c #{config} remote-info #{input_package}"
54
81
  @logger.info("Fetching package information", :package => input_package, :command => pear_cmd)
55
82
  name = %x{#{pear_cmd} | sed -ne '/^Package\s*/s/^Package\s*//p'}.chomp
56
83
  self.name = "#{attributes[:pear_package_name_prefix]}-#{name}"
57
- self.version = %x{#{pear_cmd} | sed -ne '/^Latest\s*/s/^Latest\s*//p'}.chomp
84
+ self.version = %x{#{pear_cmd} | sed -ne '/^Installed\s*/s/^Installed\s*//p'}.chomp
58
85
  self.description = %x{#{pear_cmd} | sed -ne '/^Summary\s*/s/^Summary\s*//p'}.chomp
59
86
  @logger.debug("Package info", :name => self.name, :version => self.version,
60
87
  :description => self.description)
61
88
 
62
- @logger.info("Installing pear package", :package => input_package,
63
- :directory => staging_path)
64
- ::Dir.chdir(staging_path) do
65
- safesystem("pear", "-c", config, "install", "-n", "-f", input_package)
66
- end
67
-
68
89
  # Remove the stuff we don't want
69
- delete_these = [".depdb", ".depdblock", ".filemap", ".lock", ".channel"]
90
+ delete_these = [".depdb", ".depdblock", ".filemap", ".lock", ".channel", "cache", "temp", "download", ".channels", ".registry"]
70
91
  Find.find(staging_path) do |path|
92
+ if File.file?(path) && File.executable?(path)
93
+ @logger.info("replacing pear_dir in binary", :binary => path)
94
+ staging_path_re = Regexp.new("^" + Regexp.escape(staging_path))
95
+ content = File.read(path).gsub(staging_path_re, "")
96
+ File.write(path, content)
97
+ end
71
98
  FileUtils.rm_r(path) if delete_these.include?(File.basename(path))
72
99
  end
100
+
73
101
  end # def input
74
102
  end # class FPM::Package::PEAR
@@ -58,6 +58,8 @@ class FPM::Package::Python < FPM::Package
58
58
  option "--install-data", "DATA_PATH", "The path to where data should be." \
59
59
  "installed to. This is equivalent to 'python setup.py --install-data " \
60
60
  "DATA_PATH"
61
+ option "--dependencies", :flag, "Include requirements defined in setup.py" \
62
+ " as dependencies.", :default => true
61
63
 
62
64
  private
63
65
 
@@ -196,23 +198,25 @@ class FPM::Package::Python < FPM::Package
196
198
  .map(&:strip)
197
199
  end
198
200
 
199
- self.dependencies += metadata["dependencies"].collect do |dep|
200
- dep_re = /^([^<>!= ]+)\s*(?:([<>!=]{1,2})\s*(.*))?$/
201
- match = dep_re.match(dep)
202
- if match.nil?
203
- @logger.error("Unable to parse dependency", :dependency => dep)
204
- raise FPM::InvalidPackageConfiguration, "Invalid dependency '#{dep}'"
205
- end
206
- name, cmp, version = match.captures
207
- # dependency name prefixing is optional, if enabled, a name 'foo' will
208
- # become 'python-foo' (depending on what the python_package_name_prefix
209
- # is)
210
- name = fix_name(name) if attributes[:python_fix_dependencies?]
201
+ if attributes[:python_dependencies?]
202
+ self.dependencies += metadata["dependencies"].collect do |dep|
203
+ dep_re = /^([^<>!= ]+)\s*(?:([<>!=]{1,2})\s*(.*))?$/
204
+ match = dep_re.match(dep)
205
+ if match.nil?
206
+ @logger.error("Unable to parse dependency", :dependency => dep)
207
+ raise FPM::InvalidPackageConfiguration, "Invalid dependency '#{dep}'"
208
+ end
209
+ name, cmp, version = match.captures
210
+ # dependency name prefixing is optional, if enabled, a name 'foo' will
211
+ # become 'python-foo' (depending on what the python_package_name_prefix
212
+ # is)
213
+ name = fix_name(name) if attributes[:python_fix_dependencies?]
211
214
 
212
- # convert dependencies from python-Foo to python-foo
213
- name = name.downcase if attributes[:python_downcase_dependencies?]
214
- "#{name} #{cmp} #{version}"
215
- end
215
+ # convert dependencies from python-Foo to python-foo
216
+ name = name.downcase if attributes[:python_downcase_dependencies?]
217
+ "#{name} #{cmp} #{version}"
218
+ end
219
+ end # if attributes[:python_dependencies?]
216
220
  end # def load_package_info
217
221
 
218
222
  # Sanitize package name.
@@ -243,13 +247,29 @@ class FPM::Package::Python < FPM::Package
243
247
  flags = [ "--root", staging_path ]
244
248
  if !attributes[:python_install_lib].nil?
245
249
  flags += [ "--install-lib", File.join(prefix, attributes[:python_install_lib]) ]
250
+ elsif !attributes[:prefix].nil?
251
+ # setup.py install --prefix PREFIX still installs libs to
252
+ # PREFIX/lib64/python2.7/site-packages/
253
+ # but we really want something saner.
254
+ #
255
+ # since prefix is given, but not python_install_lib, assume PREFIX/lib
256
+ flags += [ "--install-lib", File.join(prefix, "lib") ]
246
257
  end
258
+
247
259
  if !attributes[:python_install_data].nil?
248
260
  flags += [ "--install-data", File.join(prefix, attributes[:python_install_data]) ]
261
+ elsif !attributes[:prefix].nil?
262
+ # prefix given, but not python_install_data, assume PREFIX/data
263
+ flags += [ "--install-data", File.join(prefix, "data") ]
249
264
  end
265
+
250
266
  if !attributes[:python_install_bin].nil?
251
267
  flags += [ "--install-scripts", File.join(prefix, attributes[:python_install_bin]) ]
268
+ elsif !attributes[:prefix].nil?
269
+ # prefix given, but not python_install_bin, assume PREFIX/bin
270
+ flags += [ "--install-scripts", File.join(prefix, "bin") ]
252
271
  end
272
+
253
273
  safesystem(attributes[:python_bin], "setup.py", "install", *flags)
254
274
  end
255
275
  end # def install_to_staging
@@ -40,10 +40,11 @@ class FPM::Package::RPM < FPM::Package
40
40
  value
41
41
  end
42
42
 
43
+ rpmbuild_define = []
43
44
  option "--rpmbuild-define", "DEFINITION",
44
45
  "Pass a --define argument to rpmbuild." do |define|
45
- attributes[:rpm_rpmbuild_define] ||= []
46
- attributes[:rpm_rpmbuild_define] << define
46
+ rpmbuild_define << define
47
+ next rpmbuild_define
47
48
  end
48
49
 
49
50
  option "--digest", DIGEST_ALGORITHM_MAP.keys.join("|"),
@@ -271,6 +272,7 @@ class FPM::Package::RPM < FPM::Package
271
272
  # with fpm 0.4.3 and older)
272
273
  def epoch
273
274
  return 1 if @epoch.nil?
275
+ return @epoch if @epoch.is_a?(Numeric)
274
276
  return nil if @epoch.empty?
275
277
  return @epoch
276
278
  end # def epoch
@@ -7,6 +7,15 @@ require "fpm/util"
7
7
  # TODO(sissel): Add dependency checking support.
8
8
  # IIRC this has to be done as a 'checkinstall' step.
9
9
  class FPM::Package::Solaris < FPM::Package
10
+
11
+ option "--user", "USER",
12
+ "Set the user to USER in the prototype files.",
13
+ :default => 'root'
14
+
15
+ option "--group", "GROUP",
16
+ "Set the group to GROUP in the prototype file.",
17
+ :default => 'root'
18
+
10
19
  def architecture
11
20
  case @architecture
12
21
  when nil, "native"
@@ -48,7 +57,6 @@ class FPM::Package::Solaris < FPM::Package
48
57
  end
49
58
 
50
59
  # Generate the package 'Prototype' file
51
- # TODO(sissel): allow setting default file owner.
52
60
  File.open("#{build_path}/Prototype", "w") do |prototype|
53
61
  prototype.puts("i pkginfo")
54
62
  prototype.puts("i preinstall") if self.scripts["pre-install"]
@@ -58,11 +66,8 @@ class FPM::Package::Solaris < FPM::Package
58
66
  # strip @prefix, since BASEDIR will set prefix via the pkginfo file
59
67
  IO.popen("pkgproto #{staging_path}/#{@prefix}=").each_line do |line|
60
68
  type, klass, path, mode, user, group = line.split
61
- # Override stuff in pkgproto
62
- # TODO(sissel): Make this tunable?
63
- user = "root"
64
- group = "root"
65
- prototype.puts([type, klass, path, mode, user, group].join(" "))
69
+
70
+ prototype.puts([type, klass, path, mode, attributes[:solaris_user], attributes[:solaris_group]].join(" "))
66
71
  end # popen "pkgproto ..."
67
72
  end # File prototype
68
73
 
@@ -1,3 +1,3 @@
1
1
  module FPM
2
- VERSION = "0.4.29"
2
+ VERSION = "0.4.30"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.29
4
+ version: 0.4.30
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-22 00:00:00.000000000 Z
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - '='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.6.6
21
+ version: 1.7.7
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - '='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.6.6
29
+ version: 1.7.7
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: cabin
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 0.0.7
69
+ version: 0.0.8
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 0.0.7
77
+ version: 0.0.8
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: clamp
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -161,40 +161,39 @@ description: Convert directories, rpms, python eggs, rubygems, and more to rpms,
161
161
  email: jls@semicomplete.com
162
162
  executables:
163
163
  - fpm
164
- - fpm-npm
165
164
  extensions: []
166
165
  extra_rdoc_files: []
167
166
  files:
168
167
  - lib/fpm.rb
169
- - lib/fpm/command.rb
170
168
  - lib/fpm/errors.rb
171
169
  - lib/fpm/namespace.rb
172
- - lib/fpm/package.rb
173
- - lib/fpm/package/deb.rb
174
- - lib/fpm/package/gem.rb
175
170
  - lib/fpm/package/npm.rb
176
171
  - lib/fpm/package/osxpkg.rb
177
- - lib/fpm/package/pear.rb
178
172
  - lib/fpm/package/puppet.rb
179
173
  - lib/fpm/package/pyfpm/__init__.py
180
- - lib/fpm/package/pyfpm/get_metadata.py
181
174
  - lib/fpm/package/pyfpm/__init__.pyc
175
+ - lib/fpm/package/pyfpm/get_metadata.py
182
176
  - lib/fpm/package/pyfpm/get_metadata.pyc
183
- - lib/fpm/package/python.rb
184
- - lib/fpm/package/rpm.rb
185
- - lib/fpm/package/solaris.rb
186
177
  - lib/fpm/package/tar.rb
187
178
  - lib/fpm/package/dir.rb
179
+ - lib/fpm/package/pear.rb
180
+ - lib/fpm/package/empty.rb
181
+ - lib/fpm/package/solaris.rb
182
+ - lib/fpm/package/python.rb
183
+ - lib/fpm/package/deb.rb
184
+ - lib/fpm/package/gem.rb
185
+ - lib/fpm/package/rpm.rb
188
186
  - lib/fpm/util.rb
187
+ - lib/fpm/package.rb
188
+ - lib/fpm/command.rb
189
189
  - lib/fpm/version.rb
190
190
  - bin/fpm
191
- - bin/fpm-npm
192
191
  - templates/deb.erb
193
192
  - templates/osxpkg.erb
194
193
  - templates/puppet/package.pp.erb
195
194
  - templates/puppet/package/remove.pp.erb
196
- - templates/rpm.erb
197
195
  - templates/solaris.erb
196
+ - templates/rpm.erb
198
197
  - LICENSE
199
198
  - CONTRIBUTORS
200
199
  - CHANGELIST
@@ -224,3 +223,4 @@ signing_key:
224
223
  specification_version: 3
225
224
  summary: fpm - package building and mangling
226
225
  test_files: []
226
+ has_rdoc:
@@ -1,104 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "optparse"
4
- require "ostruct"
5
- require "json"
6
-
7
- settings = OpenStruct.new
8
- opts = OptionParser.new do |opts|
9
- opts.on("-n PACKAGENAME", "--name PACKAGENAME",
10
- "What name to give to the package") do |name|
11
- settings.name = name
12
- end
13
-
14
- opts.on("-v VERSION", "--version VERSION",
15
- "version to give the package") do |version|
16
- settings.version = version
17
- end
18
-
19
- opts.on("-t OUTPUTTYPE", "--type OUTPUTTYPE",
20
- "what kind of package you want as output (deb, etc)") do |packagetype|
21
- settings.packagetype = packagetype
22
- end
23
- end
24
-
25
- args = opts.parse(ARGV)
26
-
27
- if !["deb"].include?(settings.packagetype)
28
- $stderr.puts "Unsupported output package type '#{settings.packagetype}'." \
29
- "Only supports 'deb' right now."
30
- exit 1
31
- end
32
-
33
- if !settings.name
34
- $stderr.puts "No npm package name given (missing -n?)"
35
- exit 1
36
- end
37
-
38
- builddir="#{Dir.pwd}/npm2pkg"
39
- # Prefix package names with 'nodejs-'
40
- PACKAGEPREFIX = "nodejs-"
41
-
42
- Dir.mkdir(builddir) if !File.exists?(builddir)
43
- File.open("#{builddir}/.npmrc", "w") do |file|
44
- file.puts "root = #{builddir}/usr/lib/node"
45
- file.puts "binroot = #{builddir}/usr/lib/node/bin"
46
- file.puts "manroot = #{builddir}/usr/share/man"
47
- end
48
-
49
- ## Trick npm into using a custom .npmrc
50
- system("env - PATH=$PATH HOME=#{builddir} npm install #{settings.name} #{settings.version}")
51
-
52
- # Find all installed npms in builddir, make packages.
53
- Dir.glob("#{builddir}/usr/lib/node/.npm/*/*") do |path|
54
- next if File.symlink?(path)
55
- puts path
56
-
57
- # Load the package.json and glean any information from it, then invoke pkg.rb
58
- package = JSON.parse(File.new("#{path}/package/package.json").read())
59
-
60
- # TODO(sissel): Ideally we want to say any version with the same 'release' number, like
61
- # So we'll specify deps of {v}-1 <= x <= {v}-999999....
62
- depends = Dir.glob("#{path}/dependson/*@*") \
63
- .collect { |p| PACKAGEPREFIX + File.basename(p) } \
64
- .collect { |p| n,v = p.split("@");
65
- ["#{n} (>= #{v}-1)", "#{n} (<= #{v}-99999999999999)"]
66
- }.flatten
67
-
68
- if package["author"]
69
- maintainer = package["author"]
70
- else
71
- m = package["maintainers"][0] \
72
- rescue { "name" => "missing upstream author", "email" => ENV["USER"] }
73
- maintainer = "#{m["name"]} <#{m["email"]}>"
74
- end
75
-
76
- pkgcmd = [ "fpm",
77
- "-n", "#{PACKAGEPREFIX}#{package["name"]}",
78
- "-v", package["version"],
79
- "-m", maintainer,
80
- "-a", "all",
81
- ]
82
-
83
- depends.each do |dep|
84
- pkgcmd += ["-d", dep]
85
- end
86
-
87
- pkgcmd += ["-p", "#{PACKAGEPREFIX}#{package["name"]}-VERSION_ARCH.deb"]
88
- pkgcmd += ["-C", builddir]
89
- pkgcmd << "usr/lib/node/.npm/#{package["name"]}/active"
90
- pkgcmd << "usr/lib/node/.npm/#{package["name"]}/#{package["version"]}"
91
- pkgcmd << "usr/lib/node/#{package["name"]}"
92
- pkgcmd << "usr/lib/node/#{package["name"]}@#{package["version"]}"
93
-
94
- # Include bin files, install to usr/lib/node/bin
95
- (package["bin"] or []).each do |bin, script|
96
- pkgcmd << "usr/lib/node/bin/#{bin}"
97
- pkgcmd << "usr/lib/node/bin/#{bin}@#{package["version"]}"
98
- end
99
-
100
- # TODO(sissel): We could include manpages and docs, but I don't care right
101
- # now. If you want it, I accept patches! :)
102
-
103
- system *pkgcmd
104
- end