From 9cb492f85156b195575837d268503fef7a6c26c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Tue, 20 Jun 2023 10:14:17 +0200 Subject: [PATCH 1/4] - use the ID from os-release to use the proper template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 91bc63e3fbba24a5f90c4fce4f74b371c4694657) Co-authored-by: Ewoud Kohl van Wijngaarden Co-authored-by: Dan Čermák --- bin/gem2rpm | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/bin/gem2rpm b/bin/gem2rpm index a320262..246f1ff 100755 --- a/bin/gem2rpm +++ b/bin/gem2rpm @@ -26,11 +26,23 @@ end rest = options[:args] -template = begin - Gem2Rpm::Template.find options[:template_file], :gem_file => rest[0] -rescue Gem2Rpm::Template::TemplateError => e - $stderr.puts e - exit(1) +template = nil +template_file = options[:template_file] +if template_file.nil? && File.exist?('/etc/os-release') + File.read('/etc/os-release').each_line(chomp: true) do |line| + line.match(%r{^ID=(.*)$}) { |m| template_file = m[1] } + end +end +if template_file.nil? + template = Gem2Rpm::TEMPLATE +else + template_file = File.join(Gem2Rpm.template_dir, "#{template_file}.spec.erb") unless File.exist?(template_file) + begin + template = File.read(template_file) + rescue Errno::ENOENT + $stderr.puts "Could not open template #{template_file}. Aborting" + exit(1) + end end if options[:print_template_file] From 8f728f6e61f7d56719e4df1cd0549ea0bae82aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Tue, 20 Jun 2023 10:14:17 +0200 Subject: [PATCH 2/4] use template opensuse on openSUSE Tumbleweed, where /etc/os-release contains ID="opensuse-tumbleweed" (cherry picked from commit 7fa4f56a2a55278e95510d1663c495fa733d7780) --- bin/gem2rpm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/gem2rpm b/bin/gem2rpm index 246f1ff..f81c127 100755 --- a/bin/gem2rpm +++ b/bin/gem2rpm @@ -32,6 +32,10 @@ if template_file.nil? && File.exist?('/etc/os-release') File.read('/etc/os-release').each_line(chomp: true) do |line| line.match(%r{^ID=(.*)$}) { |m| template_file = m[1] } end + if template_file.eql? '"opensuse-tumbleweed"' + $stderr.puts 'Using template opensuse on Tumbleweed' + template_file = 'opensuse' + end end if template_file.nil? template = Gem2Rpm::TEMPLATE From adf719b863fa185403088d278b7e6bb18bf69805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Tue, 20 Jun 2023 10:14:17 +0200 Subject: [PATCH 3/4] Use the opensuse template on all openSUSE variants At the moment you have to manually specify the template file name on Leap, as gem2rpm tries to use the opensuse-leap template on Leap, which does not exist. Therefore we fallback to the opensuse template instead. (cherry picked from commit 2f3487679010ec0ca1e4d91896483e7e171711cb) --- bin/gem2rpm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/gem2rpm b/bin/gem2rpm index f81c127..444ffe8 100755 --- a/bin/gem2rpm +++ b/bin/gem2rpm @@ -32,8 +32,8 @@ if template_file.nil? && File.exist?('/etc/os-release') File.read('/etc/os-release').each_line(chomp: true) do |line| line.match(%r{^ID=(.*)$}) { |m| template_file = m[1] } end - if template_file.eql? '"opensuse-tumbleweed"' - $stderr.puts 'Using template opensuse on Tumbleweed' + if template_file.match? '^"opensuse' + $stderr.puts 'Using template opensuse on openSUSE variant' template_file = 'opensuse' end end From e23d592986f4ba7fb84a926cc00c8e544eacef84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Tue, 20 Jun 2023 10:14:17 +0200 Subject: [PATCH 4/4] Use single quotes and string templates where applicable --- bin/gem2rpm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/gem2rpm b/bin/gem2rpm index 444ffe8..451df4c 100755 --- a/bin/gem2rpm +++ b/bin/gem2rpm @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # -*- ruby -*- -$LOAD_PATH.push(File.expand_path(File.dirname(__FILE__) + "/../lib")) +$LOAD_PATH.push(File.expand_path("#{File.dirname(__FILE__)}/../lib")) require 'gem2rpm' require 'fileutils' @@ -97,7 +97,7 @@ Gem2Rpm.convert(gemfile, template, output_spec, options[:nongem], options[:local # Save or print a specfile. if options[:output_file] - File.open(options[:output_file], "w") do |f| + File.open(options[:output_file], 'w') do |f| f.puts(output_spec.string) end else @@ -110,15 +110,15 @@ if options[:srpm] Dir.mktmpdir "gem2rpm-#{gemname}-" do |srpmdir| specfile = File.join(srpmdir, "rubygem-#{gemname}.spec") - File.open(specfile, "w") do |f| + File.open(specfile, 'w') do |f| f.puts(output_spec.string) end FileUtils.copy(gemfile, srpmdir) command = - "rpmbuild -bs --nodeps " + - "--define '_sourcedir #{srpmdir}' " + + 'rpmbuild -bs --nodeps ' \ + "--define '_sourcedir #{srpmdir}' " \ "--define '_srcrpmdir #{out_dir}' " + specfile