|
| 1 | +#!/usr/bin/env ruby |
| 2 | +$: << File.join(File.dirname(__FILE__), "..", "..", "lib") |
| 3 | + |
| 4 | +# This example uses the API to create a package from local files |
| 5 | +# it also creates necessary init-scripts and systemd files so our executable can be used as a service |
| 6 | + |
| 7 | +require "fpm" |
| 8 | +require "tmpdir" |
| 9 | +require "fpm/package/pleaserun" |
| 10 | + |
| 11 | +# enable logging |
| 12 | +FPM::Util.send :module_function, :logger |
| 13 | +FPM::Util.logger.level = :info |
| 14 | +FPM::Util.logger.subscribe STDERR |
| 15 | + |
| 16 | +package = FPM::Package::Dir.new |
| 17 | + |
| 18 | +# Set some attributes |
| 19 | +package.name = "my-service" |
| 20 | +package.version = "1.0" |
| 21 | + |
| 22 | +# Add a script to run after install (should be in the current directory): |
| 23 | +package.scripts[:after_install] = 'my_after_install_script.sh' |
| 24 | + |
| 25 | +# Example for adding special attributes |
| 26 | +package.attributes[:deb_group] = "super-useful" |
| 27 | +package.attributes[:rpm_group] = "super-useful" |
| 28 | + |
| 29 | +# Add our files (should be in the current directory): |
| 30 | +package.input("my-executable=/usr/bin/") |
| 31 | +package.input("my-library.so=/usr/lib/") |
| 32 | + |
| 33 | +# Now, add our init-scripts, systemd services, and so on: |
| 34 | +pleaserun = package.convert(FPM::Package::PleaseRun) |
| 35 | +pleaserun.input ["/usr/bin/my-executable", "--foo-from", "bar"] |
| 36 | + |
| 37 | +# Create two output packages! |
| 38 | +output_packages = [] |
| 39 | +output_packages << pleaserun.convert(FPM::Package::RPM) |
| 40 | +output_packages << pleaserun.convert(FPM::Package::Deb) |
| 41 | + |
| 42 | +# and write them both. |
| 43 | +begin |
| 44 | + output_packages.each do |output_package| |
| 45 | + output = output_package.to_s |
| 46 | + output_package.output(output) |
| 47 | + |
| 48 | + puts "successfully created #{output}" |
| 49 | + end |
| 50 | +ensure |
| 51 | + # defer cleanup until the end |
| 52 | + output_packages.each {|p| p.cleanup} |
| 53 | +end |
0 commit comments