|
4 | 4 | require 'optparse' |
5 | 5 | require 'ostruct' |
6 | 6 |
|
| 7 | +def patch_files(options) |
| 8 | + if options.java_bin == EZBake::Config[:java_bin] |
| 9 | + yield |
| 10 | + else |
| 11 | + suffix = '.backup' |
| 12 | + [ |
| 13 | + # Debian |
| 14 | + '/etc/default/puppet*', |
| 15 | + '/lib/systemd/system/puppet*.service', |
| 16 | + # RPM |
| 17 | + '/usr/lib/systemd/system/puppet*.service', |
| 18 | + '/etc/sysconfig/puppet*', |
| 19 | + ].each do |path| |
| 20 | + Dir.glob(File.join(options.chdir, path)).each do |real_path| |
| 21 | + content = File.read(real_path) |
| 22 | + next unless content.include?(EZBake::Config[:java_bin]) |
| 23 | + |
| 24 | + warn "Copying #{real_path} to #{real_path}#{suffix}" |
| 25 | + FileUtils.cp(real_path, "#{real_path}#{suffix}") |
| 26 | + warn "Patching #{real_path} to use #{options.java_bin}" |
| 27 | + File.write(real_path, content.gsub(EZBake::Config[:java_bin], options.java_bin)) |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + yield |
| 32 | + |
| 33 | + Dir.glob(File.join(options.chdir, '**', "*#{suffix}")).each do |path| |
| 34 | + original = File.join(File.dirname(path), File.basename(path, suffix)) |
| 35 | + warn "Restoring #{path} to #{original}" |
| 36 | + FileUtils.mv(path, original) |
| 37 | + end |
| 38 | + end |
| 39 | +end |
| 40 | + |
7 | 41 | options = OpenStruct.new |
| 42 | + |
| 43 | +# ezbake.rb is rendered from |
| 44 | +# resources/puppetlabs/lein-ezbake/staging-templates/ezbake.rb.mustache |
| 45 | +# |
| 46 | +# inside the build container, fpm.rb is at: |
| 47 | +# /code/target/staging/puppetserver-8.9.0/ext/fpm.rb |
| 48 | +# ezbake: |
| 49 | +# /code/target/staging/ezbake.rb |
| 50 | +# |
| 51 | +# we do this hula hoop jump because in our build process the ezbake.rb exists |
| 52 | +# We also distribute a .tar.gz. This contains the compiled jar + fpm.rb. |
| 53 | +# fpm.rb is executed while we build the packages. This is the same process as |
| 54 | +# compiling the jar and rendering ezbake from |
| 55 | +# resources/puppetlabs/lein-ezbake/staging-templates/ezbake.rb.mustache |
| 56 | +# people that try to build their own package based on our tar, like FreeBSD, don't have the ezbake.rb |
| 57 | +# |
| 58 | +# patches welcome to move ezbake.rb into the tar *or* get rid of ezbake |
| 59 | +begin |
| 60 | + require_relative '../../ezbake' |
| 61 | +rescue LoadError |
| 62 | + options.java_bin = '/usr/bin/java' |
| 63 | +else |
| 64 | + options.java_bin = EZBake::Config[:java_bin] |
| 65 | +end |
| 66 | + |
8 | 67 | # settin' some defaults |
9 | 68 | options.systemd_el = 0 |
10 | 69 | options.systemd_sles = 0 |
11 | 70 | options.sles = 0 |
12 | 71 | options.java = 'java-1.8.0-openjdk-headless' |
13 | | -options.java_bin = '/usr/bin/java' |
14 | 72 | options.release = 1 |
15 | 73 | options.platform_version = 0 |
16 | 74 | options.replaces = {} |
|
408 | 466 | puts "#{Dir.pwd}" |
409 | 467 | end |
410 | 468 |
|
411 | | -# fpm sends all output to stdout |
412 | | -out, _, stat = Open3.capture3("#{fpm_editor} fpm #{fpm_opts.join(' ')}") |
413 | | -fail "Error trying to run FPM for #{options.dist}!\n#{out}" unless stat.success? |
| 469 | +patch_files(options) do |
| 470 | + # fpm sends all output to stdout |
| 471 | + out, _, stat = Open3.capture3("#{fpm_editor} fpm #{fpm_opts.join(' ')}") |
| 472 | + fail "Error trying to run FPM for #{options.dist}!\n#{out}" unless stat.success? |
| 473 | + |
| 474 | + puts "#{out}" |
414 | 475 |
|
415 | | -puts "#{out}" |
| 476 | + if options.termini |
| 477 | + if options.debug |
| 478 | + puts "==========================" |
| 479 | + puts "FPM COMMAND" |
| 480 | + puts "fpm #{termini_opts.join(' ')}" |
| 481 | + puts "==========================" |
| 482 | + end |
416 | 483 |
|
417 | | -if options.termini |
418 | | - if options.debug |
419 | | - puts "==========================" |
420 | | - puts "FPM COMMAND" |
421 | | - puts "fpm #{termini_opts.join(' ')}" |
422 | | - puts "==========================" |
| 484 | + # fpm sends all output to stdout |
| 485 | + out, _, stat = Open3.capture3("fpm #{termini_opts.join(' ')}") |
| 486 | + fail "Error trying to run FPM for the termini for #{options.dist}!\n#{out}" unless stat.success? |
| 487 | + puts "#{out}" |
423 | 488 | end |
424 | | - |
425 | | - # fpm sends all output to stdout |
426 | | - out, _, stat = Open3.capture3("fpm #{termini_opts.join(' ')}") |
427 | | - fail "Error trying to run FPM for the termini for #{options.dist}!\n#{out}" unless stat.success? |
428 | | - puts "#{out}" |
429 | 489 | end |
0 commit comments