Skip to content

Instantly share code, notes, and snippets.

@kosaki
Created August 10, 2014 17:04
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kosaki/de41d67a899b0d839599 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# usage: rpmpatch specfile [--localname name] files...
# example: rpmpatch kernel.spec --localname .mytest ../SOURCES/00*
require "optparse"
localname = nil
opts = OptionParser.new
opts.on("--localname NAME"){|v| localname = v }
opts.parse!(ARGV)
specfile = ARGV[0]
ARGV.shift
spec = File.read(specfile, :encoding => Encoding::UTF_8)
if localname != nil then
bid = "# % define buildid .local\n"
spec.gsub!(bid, "%define buildid #{localname}\n")
end
m = "Patch999999: linux-kernel-test.patch\n"
patches = ARGV
patchnum = 10000
spec.gsub!(m) {
s = m
s += "\n"
for patch in patches
s += "Patch#{patchnum += 1}: #{File.basename(patch)}\n"
end
s
}
apply = "ApplyOptionalPatch linux-kernel-test.patch\n"
spec.gsub!(apply) {
s = apply
s += "\n"
for patch in patches
s += "ApplyPatch #{File.basename(patch)}\n"
end
s
}
File.rename(specfile, specfile + ".old")
File.write(specfile, spec)
% cd rpmbuild/SPECS
% rpmpatch kernel.spec --localname .mytest ../SOURCES/00*.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment