From eb681e8aaee3be0182fc283b489089d9adca4a78 Mon Sep 17 00:00:00 2001 From: Jonathan Craig Date: Fri, 10 Apr 2015 09:27:57 -0400 Subject: [PATCH 1/2] Add support for Solaris 11 style IPS packages using *.p5p format --- lib/fpm.rb | 1 + lib/fpm/package/p5p.rb | 116 +++++++++++++++++++++++++++++++++++++ templates/p5p_metadata.erb | 12 ++++ 3 files changed, 129 insertions(+) create mode 100644 lib/fpm/package/p5p.rb create mode 100644 templates/p5p_metadata.erb diff --git a/lib/fpm.rb b/lib/fpm.rb index 2c0ce6eb27..205effaf21 100644 --- a/lib/fpm.rb +++ b/lib/fpm.rb @@ -14,4 +14,5 @@ require "fpm/package/python" require "fpm/package/osxpkg" require "fpm/package/solaris" +require "fpm/package/p5p" require "fpm/package/pkgin" diff --git a/lib/fpm/package/p5p.rb b/lib/fpm/package/p5p.rb new file mode 100644 index 0000000000..74c555c46a --- /dev/null +++ b/lib/fpm/package/p5p.rb @@ -0,0 +1,116 @@ +require "erb" +require "fpm/namespace" +require "fpm/package" +require "fpm/errors" +require "fpm/util" + +class FPM::Package::P5P < FPM::Package + + option "--user", "USER", + "Set the user to USER in the prototype files.", + :default => 'root' + + option "--group", "GROUP", + "Set the group to GROUP in the prototype file.", + :default => 'root' + + option "--zonetype", "ZONETYPE", + "Set the allowed zone types (global, nonglobal, both)", + :default => 'value=global value=nonglobal' do |value| + case @value + when "both" + value = "value=global value=nonglobal" + else + value = "value=#{value}" + end + end # value + + option "--publisher", "PUBLISHER", + "Set the publisher name for the repository", + :default => 'FPM' + + option "--lint" , :flag, "Check manifest with pkglint", + :default => true + + option "--validate", :flag, "Validate with pkg install", + :default => true + + def architecture + case @architecture + when nil, "native" + @architecture = %x{uname -p}.chomp + when "all" + @architecture = 'i386 value=sparc' + end + + return @architecture + end # def architecture + + def output(output_path) + + # Fixup the category to an acceptable solaris category + case @category + when nil, "default" + @category = 'Applications/System Utilities' + end + + # Generate a package manifest. + pkg_generate = safesystemout("pkgsend", "generate", "#{staging_path}") + File.open("#{build_path}/#{name}.p5m.1", "w") do |manifest| + manifest.puts pkg_generate + end + safesystem("cp", "#{build_path}/#{name}.p5m.1", "#{build_path}/#{name}.p5m") + + # Add necessary metadata to the generated manifest. + metadata_template = template("p5p_metadata.erb").result(binding) + File.open("#{build_path}/#{name}.mog", "w") do |manifest| + manifest.puts metadata_template + end + pkg_mogrify = safesystemout("pkgmogrify", "#{build_path}/#{name}.p5m", "#{build_path}/#{name}.mog") + File.open("#{build_path}/#{name}.p5m.2", "w") do |manifest| + manifest.puts pkg_mogrify + end + safesystem("cp", "#{build_path}/#{name}.p5m.2", "#{build_path}/#{name}.p5m") + + # Evaluate dependencies. + if !attributes[:no_auto_depends?] + pkgdepend_gen = safesystemout("pkgdepend", "generate", "-md", "#{staging_path}", "#{build_path}/#{name}.p5m") + File.open("#{build_path}/#{name}.p5m.3", "w") do |manifest| + manifest.puts pkgdepend_gen + end + safesystem("pkgdepend", "resolve", "-m", "#{build_path}/#{name}.p5m.3") + safesystem("cp", "#{build_path}/#{name}.p5m.3.res", "#{build_path}/#{name}.p5m") + end + + # Final format of manifest + safesystem("pkgfmt", "#{build_path}/#{name}.p5m") + + edit_file("#{build_path}/#{name}.p5m") if attributes[:edit?] + + # Add any facets or actuators that are needed. + # TODO(jcraig): add manpage actuator to enable install wo/ man pages + + # Verify the package. + if attributes[:p5p_lint] then + safesystem("pkglint", "#{build_path}/#{name}.p5m") + end + + # Publish the package. + safesystem("pkgrepo", "create", "#{build_path}/#{name}_repo") + safesystem("pkgrepo", "set", "-s", "#{build_path}/#{name}_repo", + "publisher/prefix=#{attributes[:p5p_publisher]}") + safesystem("pkgsend", "-s", "#{build_path}/#{name}_repo", + "publish", "-d", "#{staging_path}", "#{build_path}/#{name}.p5m") + safesystem("pkgrecv", "-s", "#{build_path}/#{name}_repo", "-a", + "-d", "#{build_path}/#{name}.p5p", "#{name}") + + # Test the package + if attributes[:p5p_validate] then + safesystem("pkg", "install", "-nvg", "#{build_path}/#{name}.p5p", "#{name}") + end + + # Cleanup + safesystem("mv", "#{build_path}/#{name}.p5p", output_path) + + end # def output +end # class FPM::Package::IPS diff --git a/templates/p5p_metadata.erb b/templates/p5p_metadata.erb new file mode 100644 index 0000000000..c55e979ad4 --- /dev/null +++ b/templates/p5p_metadata.erb @@ -0,0 +1,12 @@ +set name=pkg.fmri value="<%=@name%>@<%=@version%>" +set name=pkg.summary value="<%=@description%>" +set name=pkg.human-version value="<%=@version%>" +set name=pkg.description value="<%=@description%>" +set name=info.classification value="org.opensolaris.category.2008:<%=@category%>" +set name=variant.opensolaris.zone <%= attributes[:p5p_zonetype] %> +set name=variant.arch value=<%=@architecture%> + set owner <%= attributes[:p5p_user] %>> + set group <%= attributes[:p5p_group] %>> +drop> +drop> +drop> From d8c70038f7b22bdf084834930c5c27478d1c8b43 Mon Sep 17 00:00:00 2001 From: Jonathan Craig Date: Tue, 14 Apr 2015 06:47:22 -0400 Subject: [PATCH 2/2] Cleaned up the p5p code and revised work-flow --- lib/fpm/package/p5p.rb | 64 ++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/lib/fpm/package/p5p.rb b/lib/fpm/package/p5p.rb index 74c555c46a..01ba926379 100644 --- a/lib/fpm/package/p5p.rb +++ b/lib/fpm/package/p5p.rb @@ -54,63 +54,71 @@ def output(output_path) @category = 'Applications/System Utilities' end + # Manifest Filename + manifest_fn = build_path("#{name}.p5m") + # Generate a package manifest. pkg_generate = safesystemout("pkgsend", "generate", "#{staging_path}") - File.open("#{build_path}/#{name}.p5m.1", "w") do |manifest| - manifest.puts pkg_generate - end - safesystem("cp", "#{build_path}/#{name}.p5m.1", "#{build_path}/#{name}.p5m") + File.write(build_path("#{name}.p5m.1"), pkg_generate) # Add necessary metadata to the generated manifest. metadata_template = template("p5p_metadata.erb").result(binding) - File.open("#{build_path}/#{name}.mog", "w") do |manifest| - manifest.puts metadata_template - end - pkg_mogrify = safesystemout("pkgmogrify", "#{build_path}/#{name}.p5m", "#{build_path}/#{name}.mog") - File.open("#{build_path}/#{name}.p5m.2", "w") do |manifest| - manifest.puts pkg_mogrify + File.write(build_path("#{name}.mog"), metadata_template) + + # Combine template and filelist; allow user to edit before proceeding + File.open(manifest_fn, "w") do |manifest| + manifest.write metadata_template + manifest.write pkg_generate end - safesystem("cp", "#{build_path}/#{name}.p5m.2", "#{build_path}/#{name}.p5m") + edit_file(manifest_fn) if attributes[:edit?] + + # Execute the transmogrification on the manifest + pkg_mogrify = safesystemout("pkgmogrify", manifest_fn) + File.write(build_path("#{name}.p5m.2"), pkg_mogrify) + safesystem("cp", build_path("#{name}.p5m.2"), manifest_fn) # Evaluate dependencies. if !attributes[:no_auto_depends?] - pkgdepend_gen = safesystemout("pkgdepend", "generate", "-md", "#{staging_path}", "#{build_path}/#{name}.p5m") - File.open("#{build_path}/#{name}.p5m.3", "w") do |manifest| - manifest.puts pkgdepend_gen - end - safesystem("pkgdepend", "resolve", "-m", "#{build_path}/#{name}.p5m.3") - safesystem("cp", "#{build_path}/#{name}.p5m.3.res", "#{build_path}/#{name}.p5m") + pkgdepend_gen = safesystemout("pkgdepend", "generate", "-md", "#{staging_path}", manifest_fn) + File.write(build_path("#{name}.p5m.3"), pkgdepend_gen) + + # Allow user to review added dependencies + edit_file(build_path("#{name}.p5m.3")) if attributes[:edit?] + + safesystem("pkgdepend", "resolve", "-m", build_path("#{name}.p5m.3")) + safesystem("cp", build_path("#{name}.p5m.3.res"), manifest_fn) end # Final format of manifest - safesystem("pkgfmt", "#{build_path}/#{name}.p5m") + safesystem("pkgfmt", manifest_fn) - edit_file("#{build_path}/#{name}.p5m") if attributes[:edit?] + # Final edit for lint check and packaging + edit_file(manifest_fn) if attributes[:edit?] # Add any facets or actuators that are needed. # TODO(jcraig): add manpage actuator to enable install wo/ man pages # Verify the package. if attributes[:p5p_lint] then - safesystem("pkglint", "#{build_path}/#{name}.p5m") + safesystem("pkglint", manifest_fn) end # Publish the package. - safesystem("pkgrepo", "create", "#{build_path}/#{name}_repo") - safesystem("pkgrepo", "set", "-s", "#{build_path}/#{name}_repo", - "publisher/prefix=#{attributes[:p5p_publisher]}") - safesystem("pkgsend", "-s", "#{build_path}/#{name}_repo", + repo_path = build_path("#{name}_repo") + safesystem("pkgrepo", "create", repo_path) + safesystem("pkgrepo", "set", "-s", repo_path, "publisher/prefix=#{attributes[:p5p_publisher]}") + safesystem("pkgsend", "-s", repo_path, "publish", "-d", "#{staging_path}", "#{build_path}/#{name}.p5m") - safesystem("pkgrecv", "-s", "#{build_path}/#{name}_repo", "-a", - "-d", "#{build_path}/#{name}.p5p", "#{name}") + safesystem("pkgrecv", "-s", repo_path, "-a", + "-d", build_path("#{name}.p5p"), name) # Test the package if attributes[:p5p_validate] then - safesystem("pkg", "install", "-nvg", "#{build_path}/#{name}.p5p", "#{name}") + safesystem("pkg", "install", "-nvg", build_path("#{name}.p5p"), name) end # Cleanup - safesystem("mv", "#{build_path}/#{name}.p5p", output_path) + safesystem("mv", build_path("#{name}.p5p"), output_path) end # def output end # class FPM::Package::IPS