omnibus 5.4.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -3
  3. data/CHANGELOG.md +21 -0
  4. data/Gemfile +8 -5
  5. data/README.md +3 -1
  6. data/Rakefile +20 -13
  7. data/appveyor.yml +4 -3
  8. data/bin/omnibus +3 -3
  9. data/features/commands/manifest.feature +19 -5
  10. data/features/step_definitions/generator_steps.rb +5 -6
  11. data/features/support/env.rb +4 -4
  12. data/lib/omnibus/build_version.rb +14 -14
  13. data/lib/omnibus/build_version_dsl.rb +3 -3
  14. data/lib/omnibus/builder.rb +50 -61
  15. data/lib/omnibus/changelog.rb +2 -2
  16. data/lib/omnibus/changelog_printer.rb +4 -4
  17. data/lib/omnibus/cleaner.rb +4 -4
  18. data/lib/omnibus/cli/base.rb +15 -15
  19. data/lib/omnibus/cli/cache.rb +13 -13
  20. data/lib/omnibus/cli/changelog.rb +8 -9
  21. data/lib/omnibus/cli/publish.rb +12 -13
  22. data/lib/omnibus/cli.rb +26 -27
  23. data/lib/omnibus/compressor.rb +6 -6
  24. data/lib/omnibus/compressors/base.rb +7 -2
  25. data/lib/omnibus/compressors/dmg.rb +12 -12
  26. data/lib/omnibus/compressors/null.rb +1 -1
  27. data/lib/omnibus/compressors/tgz.rb +8 -8
  28. data/lib/omnibus/config.rb +37 -26
  29. data/lib/omnibus/core_extensions/open_uri.rb +3 -3
  30. data/lib/omnibus/core_extensions.rb +1 -1
  31. data/lib/omnibus/digestable.rb +5 -4
  32. data/lib/omnibus/download_helpers.rb +7 -6
  33. data/lib/omnibus/exceptions.rb +29 -13
  34. data/lib/omnibus/fetcher.rb +0 -1
  35. data/lib/omnibus/fetchers/git_fetcher.rb +7 -7
  36. data/lib/omnibus/fetchers/net_fetcher.rb +19 -19
  37. data/lib/omnibus/fetchers/path_fetcher.rb +1 -1
  38. data/lib/omnibus/file_syncer.rb +3 -3
  39. data/lib/omnibus/generator.rb +60 -47
  40. data/lib/omnibus/git_cache.rb +33 -22
  41. data/lib/omnibus/git_repository.rb +5 -5
  42. data/lib/omnibus/health_check.rb +122 -119
  43. data/lib/omnibus/instrumentation.rb +1 -1
  44. data/lib/omnibus/licensing.rb +348 -60
  45. data/lib/omnibus/logger.rb +12 -9
  46. data/lib/omnibus/logging.rb +1 -1
  47. data/lib/omnibus/manifest.rb +4 -4
  48. data/lib/omnibus/manifest_diff.rb +6 -7
  49. data/lib/omnibus/manifest_entry.rb +1 -1
  50. data/lib/omnibus/metadata.rb +36 -36
  51. data/lib/omnibus/ohai.rb +6 -7
  52. data/lib/omnibus/package.rb +1 -1
  53. data/lib/omnibus/packager.rb +37 -28
  54. data/lib/omnibus/packagers/appx.rb +86 -0
  55. data/lib/omnibus/packagers/base.rb +21 -18
  56. data/lib/omnibus/packagers/bff.rb +22 -24
  57. data/lib/omnibus/packagers/deb.rb +20 -20
  58. data/lib/omnibus/packagers/ips.rb +18 -17
  59. data/lib/omnibus/packagers/makeself.rb +7 -7
  60. data/lib/omnibus/packagers/msi.rb +38 -193
  61. data/lib/omnibus/packagers/pkg.rb +16 -16
  62. data/lib/omnibus/packagers/rpm.rb +53 -54
  63. data/lib/omnibus/packagers/solaris.rb +14 -14
  64. data/lib/omnibus/packagers/windows_base.rb +192 -0
  65. data/lib/omnibus/project.rb +45 -43
  66. data/lib/omnibus/publisher.rb +3 -3
  67. data/lib/omnibus/publishers/artifactory_publisher.rb +39 -39
  68. data/lib/omnibus/publishers/s3_publisher.rb +7 -7
  69. data/lib/omnibus/reports.rb +10 -10
  70. data/lib/omnibus/s3_cache.rb +7 -7
  71. data/lib/omnibus/s3_helpers.rb +8 -7
  72. data/lib/omnibus/semantic_version.rb +1 -1
  73. data/lib/omnibus/software.rb +131 -81
  74. data/lib/omnibus/sugarable.rb +10 -10
  75. data/lib/omnibus/templating.rb +5 -5
  76. data/lib/omnibus/thread_pool.rb +1 -1
  77. data/lib/omnibus/util.rb +5 -5
  78. data/lib/omnibus/version.rb +1 -1
  79. data/lib/omnibus.rb +65 -65
  80. data/omnibus.gemspec +34 -32
  81. data/resources/appx/AppxManifest.xml.erb +18 -0
  82. data/resources/appx/assets/clear.png +0 -0
  83. data/spec/fixtures/licensing/license_scout/snoopy/ruby_bundler-bundler-audit-0.5.0-COPYING.txt +674 -0
  84. data/spec/fixtures/licensing/license_scout/snoopy/ruby_bundler-inifile-3.0.0-README.md +215 -0
  85. data/spec/fixtures/licensing/license_scout/snoopy/snoopy-dependency-licenses.json +24 -0
  86. data/spec/fixtures/licensing/license_scout/zlib/ruby_bundler-inifile-3.0.0-README.md +215 -0
  87. data/spec/fixtures/licensing/license_scout/zlib/ruby_bundler-mime-types-3.1-Licence.rdoc +25 -0
  88. data/spec/fixtures/licensing/license_scout/zlib/ruby_bundler-mini_portile2-2.1.0-LICENSE.txt +20 -0
  89. data/spec/fixtures/licensing/license_scout/zlib/zlib-dependency-licenses.json +32 -0
  90. data/spec/functional/builder_spec.rb +149 -150
  91. data/spec/functional/fetchers/git_fetcher_spec.rb +69 -71
  92. data/spec/functional/fetchers/net_fetcher_spec.rb +79 -79
  93. data/spec/functional/fetchers/path_fetcher_spec.rb +19 -20
  94. data/spec/functional/file_syncer_spec.rb +74 -74
  95. data/spec/functional/licensing_spec.rb +344 -35
  96. data/spec/functional/templating_spec.rb +17 -17
  97. data/spec/spec_helper.rb +20 -20
  98. data/spec/support/examples.rb +21 -15
  99. data/spec/support/file_helpers.rb +1 -1
  100. data/spec/support/git_helpers.rb +37 -37
  101. data/spec/support/matchers.rb +3 -3
  102. data/spec/support/ohai_helpers.rb +4 -4
  103. data/spec/support/path_helpers.rb +2 -2
  104. data/spec/support/shell_helpers.rb +2 -2
  105. data/spec/unit/build_version_dsl_spec.rb +5 -5
  106. data/spec/unit/build_version_spec.rb +63 -63
  107. data/spec/unit/builder_spec.rb +86 -70
  108. data/spec/unit/changelog_spec.rb +4 -4
  109. data/spec/unit/changelogprinter_spec.rb +130 -0
  110. data/spec/unit/cleanroom_spec.rb +11 -11
  111. data/spec/unit/compressor_spec.rb +16 -16
  112. data/spec/unit/compressors/base_spec.rb +6 -6
  113. data/spec/unit/compressors/dmg_spec.rb +76 -76
  114. data/spec/unit/compressors/null_spec.rb +4 -4
  115. data/spec/unit/compressors/tgz_spec.rb +20 -20
  116. data/spec/unit/config_spec.rb +44 -43
  117. data/spec/unit/digestable_spec.rb +13 -13
  118. data/spec/unit/fetcher_spec.rb +11 -12
  119. data/spec/unit/fetchers/git_fetcher_spec.rb +31 -31
  120. data/spec/unit/fetchers/net_fetcher_spec.rb +172 -173
  121. data/spec/unit/fetchers/path_fetcher_spec.rb +18 -18
  122. data/spec/unit/generator_spec.rb +38 -38
  123. data/spec/unit/git_cache_spec.rb +56 -54
  124. data/spec/unit/git_repository_spec.rb +2 -2
  125. data/spec/unit/health_check_spec.rb +40 -40
  126. data/spec/unit/library_spec.rb +35 -35
  127. data/spec/unit/manifest_diff_spec.rb +10 -11
  128. data/spec/unit/manifest_spec.rb +17 -17
  129. data/spec/unit/metadata_spec.rb +152 -152
  130. data/spec/unit/ohai_spec.rb +5 -5
  131. data/spec/unit/omnibus_spec.rb +31 -31
  132. data/spec/unit/package_spec.rb +20 -20
  133. data/spec/unit/packager_spec.rb +48 -42
  134. data/spec/unit/packagers/appx_spec.rb +165 -0
  135. data/spec/unit/packagers/base_spec.rb +34 -34
  136. data/spec/unit/packagers/bff_spec.rb +60 -60
  137. data/spec/unit/packagers/deb_spec.rb +71 -71
  138. data/spec/unit/packagers/ips_spec.rb +45 -45
  139. data/spec/unit/packagers/makeself_spec.rb +22 -22
  140. data/spec/unit/packagers/msi_spec.rb +141 -147
  141. data/spec/unit/packagers/pkg_spec.rb +59 -60
  142. data/spec/unit/packagers/rpm_spec.rb +125 -126
  143. data/spec/unit/packagers/solaris_spec.rb +52 -52
  144. data/spec/unit/project_spec.rb +137 -135
  145. data/spec/unit/publisher_spec.rb +70 -70
  146. data/spec/unit/publishers/artifactory_publisher_spec.rb +85 -85
  147. data/spec/unit/publishers/s3_publisher_spec.rb +36 -36
  148. data/spec/unit/s3_cacher_spec.rb +34 -34
  149. data/spec/unit/s3_helpers_spec.rb +6 -6
  150. data/spec/unit/semantic_version_spec.rb +2 -2
  151. data/spec/unit/software_spec.rb +346 -384
  152. data/spec/unit/sugarable_spec.rb +10 -10
  153. data/spec/unit/util_spec.rb +60 -60
  154. metadata +54 -6
  155. data/.rubocop.yml +0 -48
@@ -21,18 +21,18 @@ module Omnibus
21
21
  # @return [Hash]
22
22
  SCRIPT_MAP = {
23
23
  # Default Omnibus naming
24
- preinst: 'pre',
25
- postinst: 'post',
26
- prerm: 'preun',
27
- postrm: 'postun',
24
+ preinst: "pre",
25
+ postinst: "post",
26
+ prerm: "preun",
27
+ postrm: "postun",
28
28
  # Default RPM naming
29
- pre: 'pre',
30
- post: 'post',
31
- preun: 'preun',
32
- postun: 'postun',
33
- verifyscript: 'verifyscript',
34
- pretans: 'pretans',
35
- posttrans: 'posttrans',
29
+ pre: "pre",
30
+ post: "post",
31
+ preun: "preun",
32
+ postun: "postun",
33
+ verifyscript: "verifyscript",
34
+ pretans: "pretans",
35
+ posttrans: "posttrans",
36
36
  }.freeze
37
37
 
38
38
  id :rpm
@@ -116,10 +116,10 @@ module Omnibus
116
116
  #
117
117
  def vendor(val = NULL)
118
118
  if null?(val)
119
- @vendor || 'Omnibus <omnibus@getchef.com>'
119
+ @vendor || "Omnibus <omnibus@getchef.com>"
120
120
  else
121
121
  unless val.is_a?(String)
122
- raise InvalidValue.new(:vendor, 'be a String')
122
+ raise InvalidValue.new(:vendor, "be a String")
123
123
  end
124
124
 
125
125
  @vendor = val
@@ -144,7 +144,7 @@ module Omnibus
144
144
  @license || project.license
145
145
  else
146
146
  unless val.is_a?(String)
147
- raise InvalidValue.new(:license, 'be a String')
147
+ raise InvalidValue.new(:license, "be a String")
148
148
  end
149
149
 
150
150
  @license = val
@@ -166,10 +166,10 @@ module Omnibus
166
166
  #
167
167
  def priority(val = NULL)
168
168
  if null?(val)
169
- @priority || 'extra'
169
+ @priority || "extra"
170
170
  else
171
171
  unless val.is_a?(String)
172
- raise InvalidValue.new(:priority, 'be a String')
172
+ raise InvalidValue.new(:priority, "be a String")
173
173
  end
174
174
 
175
175
  @priority = val
@@ -191,10 +191,10 @@ module Omnibus
191
191
  #
192
192
  def category(val = NULL)
193
193
  if null?(val)
194
- @category || 'default'
194
+ @category || "default"
195
195
  else
196
196
  unless val.is_a?(String)
197
- raise InvalidValue.new(:category, 'be a String')
197
+ raise InvalidValue.new(:category, "be a String")
198
198
  end
199
199
 
200
200
  @category = val
@@ -248,7 +248,7 @@ module Omnibus
248
248
  # @return [String]
249
249
  #
250
250
  def build_dir
251
- @build_dir ||= File.join(staging_dir, 'BUILD')
251
+ @build_dir ||= File.join(staging_dir, "BUILD")
252
252
  end
253
253
 
254
254
  #
@@ -267,7 +267,7 @@ module Omnibus
267
267
  # @return [Array]
268
268
  #
269
269
  def filesystem_directories
270
- @filesystem_directories ||= IO.readlines(resource_path('filesystem_list')).map { |f| f.chomp }
270
+ @filesystem_directories ||= IO.readlines(resource_path("filesystem_list")).map { |f| f.chomp }
271
271
  end
272
272
 
273
273
  #
@@ -277,7 +277,7 @@ module Omnibus
277
277
  # @return [String]
278
278
  #
279
279
  def mark_filesystem_directories(fsdir)
280
- if fsdir.eql?('/') || fsdir.eql?('/usr/lib') || fsdir.eql?('/usr/share/empty')
280
+ if fsdir.eql?("/") || fsdir.eql?("/usr/lib") || fsdir.eql?("/usr/share/empty")
281
281
  return "%dir %attr(0555,root,root) #{fsdir}"
282
282
  elsif filesystem_directories.include?(fsdir)
283
283
  return "%dir %attr(0755,root,root) #{fsdir}"
@@ -306,9 +306,9 @@ module Omnibus
306
306
 
307
307
  # Get a list of all files
308
308
  files = FileSyncer.glob("#{build_dir}/**/*")
309
- .map { |path| build_filepath(path) }
309
+ .map { |path| build_filepath(path) }
310
310
 
311
- render_template(resource_path('spec.erb'),
311
+ render_template(resource_path("spec.erb"),
312
312
  destination: spec_file,
313
313
  variables: {
314
314
  name: safe_base_package_name,
@@ -331,38 +331,38 @@ module Omnibus
331
331
  config_files: config_files,
332
332
  files: files,
333
333
  build_dir: build_dir,
334
- platform_family: Ohai['platform_family']
334
+ platform_family: Ohai["platform_family"],
335
335
  }
336
336
  )
337
337
  end
338
338
 
339
339
  #
340
- # Generate the RPM file using +rpmbuild+. The use of the +fakeroot+ command
341
- # is required so that the package is owned by +root:root+, but the build
342
- # user does not need to have sudo permissions.
340
+ # Generate the RPM file using +rpmbuild+. Unlike debian,the +fakeroot+
341
+ # command is not required for the package to be owned by +root:root+. The
342
+ # rpmuser specified in the spec file dictates this.
343
343
  #
344
344
  # @return [void]
345
345
  #
346
346
  def create_rpm_file
347
- command = %|fakeroot rpmbuild|
348
- command << %| --target #{safe_architecture}|
349
- command << %| -bb|
350
- command << %| --buildroot #{staging_dir}/BUILD|
351
- command << %| --define '_topdir #{staging_dir}'|
347
+ command = %{rpmbuild}
348
+ command << %{ --target #{safe_architecture}}
349
+ command << %{ -bb}
350
+ command << %{ --buildroot #{staging_dir}/BUILD}
351
+ command << %{ --define '_topdir #{staging_dir}'}
352
352
 
353
353
  if signing_passphrase
354
354
  log.info(log_key) { "Signing enabled for .rpm file" }
355
355
 
356
356
  if File.exist?("#{ENV['HOME']}/.rpmmacros")
357
357
  log.info(log_key) { "Detected .rpmmacros file at `#{ENV['HOME']}'" }
358
- home = ENV['HOME']
358
+ home = ENV["HOME"]
359
359
  else
360
360
  log.info(log_key) { "Using default .rpmmacros file from Omnibus" }
361
361
 
362
362
  # Generate a temporary home directory
363
363
  home = Dir.mktmpdir
364
364
 
365
- render_template(resource_path('rpmmacros.erb'),
365
+ render_template(resource_path("rpmmacros.erb"),
366
366
  destination: "#{home}/.rpmmacros",
367
367
  variables: {
368
368
  gpg_name: project.maintainer,
@@ -376,7 +376,7 @@ module Omnibus
376
376
 
377
377
  with_rpm_signing do |signing_script|
378
378
  log.info(log_key) { "Creating .rpm file" }
379
- shellout!("#{signing_script} \"#{command}\"", environment: { 'HOME' => home })
379
+ shellout!("#{signing_script} \"#{command}\"", environment: { "HOME" => home })
380
380
  end
381
381
  else
382
382
  log.info(log_key) { "Creating .rpm file" }
@@ -395,11 +395,11 @@ module Omnibus
395
395
  # @return [String]
396
396
  #
397
397
  def build_filepath(path)
398
- filepath = rpm_safe('/' + path.gsub("#{build_dir}/", ''))
398
+ filepath = rpm_safe("/" + path.gsub("#{build_dir}/", ""))
399
399
  return if config_files.include?(filepath)
400
- full_path = build_dir + filepath.gsub('[%]','%')
400
+ full_path = build_dir + filepath.gsub("[%]", "%")
401
401
  # FileSyncer.glob quotes pathnames that contain spaces, which is a problem on el7
402
- full_path.gsub!('"', '')
402
+ full_path.delete!('"')
403
403
  # Mark directories with the %dir directive to prevent rpmbuild from counting their contents twice.
404
404
  return mark_filesystem_directories(filepath) if !File.symlink?(full_path) && File.directory?(full_path)
405
405
  filepath
@@ -428,7 +428,7 @@ module Omnibus
428
428
  directory = Dir.mktmpdir
429
429
  destination = "#{directory}/sign-rpm"
430
430
 
431
- render_template(resource_path('signing.erb'),
431
+ render_template(resource_path("signing.erb"),
432
432
  destination: destination,
433
433
  mode: 0700,
434
434
  variables: {
@@ -437,7 +437,7 @@ module Omnibus
437
437
  )
438
438
 
439
439
  # Yield the destination to the block
440
- block.call(destination)
440
+ yield(destination)
441
441
  ensure
442
442
  remove_file(destination)
443
443
  remove_directory(directory)
@@ -474,7 +474,7 @@ module Omnibus
474
474
  if project.package_name =~ /\A[a-z0-9\.\+\-]+\z/
475
475
  project.package_name.dup
476
476
  else
477
- converted = project.package_name.downcase.gsub(/[^a-z0-9\.\+\-]+/, '-')
477
+ converted = project.package_name.downcase.gsub(/[^a-z0-9\.\+\-]+/, "-")
478
478
 
479
479
  log.warn(log_key) do
480
480
  "The `name' component of RPM package names can only include " \
@@ -513,8 +513,8 @@ module Omnibus
513
513
  # http://rpm.org/ticket/56
514
514
  #
515
515
  if version =~ /\-/
516
- if Ohai['platform_family'] == 'wrlinux'
517
- converted = version.gsub('-', '_') #WRL has an elderly RPM version
516
+ if Ohai["platform_family"] == "wrlinux"
517
+ converted = version.tr("-", "_") #WRL has an elderly RPM version
518
518
  log.warn(log_key) do
519
519
  "Omnibus replaces dashes (-) with tildes (~) so pre-release " \
520
520
  "versions get sorted earlier than final versions. However, the " \
@@ -523,7 +523,7 @@ module Omnibus
523
523
  "`#{project.build_version}' to `#{converted}'."
524
524
  end
525
525
  else
526
- converted = version.gsub('-', '~')
526
+ converted = version.tr("-", "~")
527
527
  log.warn(log_key) do
528
528
  "Tildes hold special significance in the RPM package versions. " \
529
529
  "They mark a version as lower priority in RPM's version compare " \
@@ -533,14 +533,13 @@ module Omnibus
533
533
  end
534
534
  end
535
535
 
536
-
537
536
  version = converted
538
537
  end
539
538
 
540
539
  if version =~ /\A[a-zA-Z0-9\.\+\~]+\z/
541
540
  version
542
541
  else
543
- converted = version.gsub(/[^a-zA-Z0-9\.\+\~]+/, '_')
542
+ converted = version.gsub(/[^a-zA-Z0-9\.\+\~]+/, "_")
544
543
 
545
544
  log.warn(log_key) do
546
545
  "The `version' component of RPM package names can only include " \
@@ -559,17 +558,17 @@ module Omnibus
559
558
  # @return [String]
560
559
  #
561
560
  def safe_architecture
562
- case Ohai['kernel']['machine']
563
- when 'i686'
564
- 'i386'
565
- when 'armv6l'
566
- if Ohai['platform'] == 'pidora'
567
- 'armv6hl'
561
+ case Ohai["kernel"]["machine"]
562
+ when "i686"
563
+ "i386"
564
+ when "armv6l"
565
+ if Ohai["platform"] == "pidora"
566
+ "armv6hl"
568
567
  else
569
- 'armv6l'
568
+ "armv6l"
570
569
  end
571
570
  else
572
- Ohai['kernel']['machine']
571
+ Ohai["kernel"]["machine"]
573
572
  end
574
573
  end
575
574
  end
@@ -14,18 +14,18 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- require 'socket'
17
+ require "socket"
18
18
 
19
19
  module Omnibus
20
20
  class Packager::Solaris < Packager::Base
21
21
  # @return [Hash]
22
22
  SCRIPT_MAP = {
23
23
  # Default Omnibus naming
24
- postinst: 'postinstall',
25
- postrm: 'postremove',
24
+ postinst: "postinstall",
25
+ postrm: "postremove",
26
26
  # Default Solaris naming
27
- postinstall: 'postinstall',
28
- postremove: 'postremove',
27
+ postinstall: "postinstall",
28
+ postremove: "postremove",
29
29
  }.freeze
30
30
 
31
31
  id :solaris
@@ -82,8 +82,8 @@ module Omnibus
82
82
  def write_prototype_file
83
83
  shellout! "cd #{install_dirname} && find #{install_basename} -print > #{staging_dir_path('files')}"
84
84
 
85
- File.open staging_dir_path('files.clean'), 'w+' do |fout|
86
- File.open staging_dir_path('files') do |fin|
85
+ File.open staging_dir_path("files.clean"), "w+" do |fout|
86
+ File.open staging_dir_path("files") do |fin|
87
87
  fin.each_line do |line|
88
88
  if line.chomp =~ /\s/
89
89
  log.warn(log_key) { "Skipping packaging '#{line}' file due to whitespace in filename" }
@@ -95,8 +95,8 @@ module Omnibus
95
95
  end
96
96
 
97
97
  # generate list of control files
98
- File.open staging_dir_path('Prototype'), 'w+' do |f|
99
- f.write <<-EOF.gsub(/^ {10}/, '')
98
+ File.open staging_dir_path("Prototype"), "w+" do |f|
99
+ f.write <<-EOF.gsub(/^ {10}/, "")
100
100
  i pkginfo
101
101
  i postinstall
102
102
  i postremove
@@ -117,7 +117,7 @@ module Omnibus
117
117
  hostname = Socket.gethostname
118
118
 
119
119
  # http://docs.oracle.com/cd/E19683-01/816-0219/6m6njqbat/index.html
120
- pkginfo_content = <<-EOF.gsub(/^ {8}/, '')
120
+ pkginfo_content = <<-EOF.gsub(/^ {8}/, "")
121
121
  CLASSES=none
122
122
  TZ=PST
123
123
  PATH=/sbin:/usr/sbin:/usr/bin:/usr/sadm/install/bin
@@ -132,7 +132,7 @@ module Omnibus
132
132
  EMAIL=#{project.maintainer}
133
133
  PSTAMP=#{hostname}#{Time.now.utc.iso8601}
134
134
  EOF
135
- File.open staging_dir_path('pkginfo'), 'w+' do |f|
135
+ File.open staging_dir_path("pkginfo"), "w+" do |f|
136
136
  f.write pkginfo_content
137
137
  end
138
138
  end
@@ -156,11 +156,11 @@ module Omnibus
156
156
  def safe_architecture
157
157
  # The #i386? and #intel? helpers come from chef-sugar
158
158
  if intel?
159
- 'i386'
159
+ "i386"
160
160
  elsif sparc?
161
- 'sparc'
161
+ "sparc"
162
162
  else
163
- Ohai['kernel']['machine']
163
+ Ohai["kernel"]["machine"]
164
164
  end
165
165
  end
166
166
  end
@@ -0,0 +1,192 @@
1
+ #
2
+ # Copyright 2016 Chef Software, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Omnibus
18
+ class Packager::WindowsBase < Packager::Base
19
+ DEFAULT_TIMESTAMP_SERVERS = ["http://timestamp.digicert.com",
20
+ "http://timestamp.verisign.com/scripts/timestamp.dll"]
21
+
22
+ #
23
+ # Set the signing certificate name
24
+ #
25
+ # @example
26
+ # signing_identity 'FooCert'
27
+ # signing_identity 'FooCert', store: 'BarStore'
28
+ #
29
+ # @param [String] thumbprint
30
+ # the thumbprint of the certificate in the certificate store
31
+ # @param [Hash<Symbol, String>] params
32
+ # an optional hash that defines the parameters for the singing identity
33
+ #
34
+ # @option params [String] :store (My)
35
+ # The name of the certificate store which contains the certificate
36
+ # @option params [Array<String>, String] :timestamp_servers
37
+ # A trusted timestamp server or a list of truested timestamp servers to
38
+ # be tried. They are tried in the order provided.
39
+ # @option params [TrueClass, FalseClass] :machine_store (false)
40
+ # If set to true, the local machine store will be searched for a valid
41
+ # certificate. Otherwise, the current user store is used
42
+ #
43
+ # Setting nothing will default to trying ['http://timestamp.digicert.com',
44
+ # 'http://timestamp.verisign.com/scripts/timestamp.dll']
45
+ #
46
+ # @return [Hash{:thumbprint => String, :store => String, :timestamp_servers => Array[String]}]
47
+ #
48
+ def signing_identity(thumbprint = NULL, params = NULL)
49
+ unless null?(thumbprint)
50
+ @signing_identity = {}
51
+ unless thumbprint.is_a?(String)
52
+ raise InvalidValue.new(:signing_identity, "be a String")
53
+ end
54
+
55
+ @signing_identity[:thumbprint] = thumbprint
56
+
57
+ if !null?(params)
58
+ unless params.is_a?(Hash)
59
+ raise InvalidValue.new(:params, "be a Hash")
60
+ end
61
+
62
+ valid_keys = [:store, :timestamp_servers, :machine_store, :algorithm]
63
+ invalid_keys = params.keys - valid_keys
64
+ unless invalid_keys.empty?
65
+ raise InvalidValue.new(:params, "contain keys from [#{valid_keys.join(', ')}]. "\
66
+ "Found invalid keys [#{invalid_keys.join(', ')}]")
67
+ end
68
+
69
+ if !params[:machine_store].nil? && !(
70
+ params[:machine_store].is_a?(TrueClass) ||
71
+ params[:machine_store].is_a?(FalseClass))
72
+ raise InvalidValue.new(:params, "contain key :machine_store of type TrueClass or FalseClass")
73
+ end
74
+ else
75
+ params = {}
76
+ end
77
+
78
+ @signing_identity[:store] = params[:store] || "My"
79
+ @signing_identity[:algorithm] = params[:algorithm] || "SHA1"
80
+ servers = params[:timestamp_servers] || DEFAULT_TIMESTAMP_SERVERS
81
+ @signing_identity[:timestamp_servers] = [servers].flatten
82
+ @signing_identity[:machine_store] = params[:machine_store] || false
83
+ end
84
+
85
+ @signing_identity
86
+ end
87
+ expose :signing_identity
88
+
89
+ def thumbprint
90
+ signing_identity[:thumbprint]
91
+ end
92
+
93
+ def algorithm
94
+ signing_identity[:algorithm]
95
+ end
96
+
97
+ def cert_store_name
98
+ signing_identity[:store]
99
+ end
100
+
101
+ def timestamp_servers
102
+ signing_identity[:timestamp_servers]
103
+ end
104
+
105
+ def machine_store?
106
+ signing_identity[:machine_store]
107
+ end
108
+
109
+ #
110
+ # Iterates through available timestamp servers and tries to sign
111
+ # the file with with each server, stopping after the first to succeed.
112
+ # If none succeed, an exception is raised.
113
+ #
114
+ def sign_package(package_file)
115
+ success = false
116
+ timestamp_servers.each do |ts|
117
+ success = try_sign(package_file, ts)
118
+ break if success
119
+ end
120
+ raise FailedToSignWindowsPackage.new if !success
121
+ end
122
+
123
+ def try_sign(package_file, url)
124
+ cmd = Array.new.tap do |arr|
125
+ arr << "signtool.exe"
126
+ arr << "sign /v"
127
+ arr << "/t #{url}"
128
+ arr << "/fd #{algorithm}"
129
+ arr << "/sm" if machine_store?
130
+ arr << "/s #{cert_store_name}"
131
+ arr << "/sha1 #{thumbprint}"
132
+ arr << "/d #{project.package_name}"
133
+ arr << "\"#{package_file}\""
134
+ end.join(" ")
135
+ status = shellout(cmd)
136
+ if status.exitstatus != 0
137
+ log.warn(log_key) do
138
+ <<-EOH.strip
139
+ Failed to add timestamp with timeserver #{url}
140
+
141
+ STDOUT
142
+ ------
143
+ #{status.stdout}
144
+
145
+ STDERR
146
+ ------
147
+ #{status.stderr}
148
+ EOH
149
+ end
150
+ end
151
+ status.exitstatus == 0
152
+ end
153
+
154
+ #
155
+ # Get the certificate subject of the signing identity
156
+ #
157
+ # @return [String]
158
+ #
159
+ def certificate_subject
160
+ return "CN=#{project.package_name}" unless signing_identity
161
+ store = machine_store? ? "LocalMachine" : "CurrentUser"
162
+ cmd = Array.new.tap do |arr|
163
+ arr << "powershell.exe"
164
+ arr << "-ExecutionPolicy Bypass"
165
+ arr << "-NoProfile"
166
+ arr << "-Command (Get-Item Cert:/#{store}/#{cert_store_name}/#{thumbprint}).Subject"
167
+ end.join(" ")
168
+
169
+ shellout!(cmd).stdout.strip
170
+ end
171
+
172
+ #
173
+ # Parse and return the version from the {Project#build_version}.
174
+ #
175
+ # A project's +build_version+ looks something like:
176
+ #
177
+ # dev builds => 11.14.0-alpha.1+20140501194641.git.94.561b564
178
+ # => 0.0.0+20140506165802.1
179
+ #
180
+ # rel builds => 11.14.0.alpha.1 || 11.14.0
181
+ #
182
+ # The appx and msi version specs expects a version that looks like X.Y.Z.W where
183
+ # X, Y, Z & W are all 32 bit integers.
184
+ #
185
+ # @return [String]
186
+ #
187
+ def windows_package_version
188
+ major, minor, patch = project.build_version.split(/[.+-]/)
189
+ [major, minor, patch, project.build_iteration].join(".")
190
+ end
191
+ end
192
+ end