You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gsign 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/ruby
  2. require 'optparse'
  3. require 'yaml'
  4. require 'fileutils'
  5. require 'pathname'
  6. @options = {}
  7. def system!(cmd)
  8. system(cmd) or raise "failed to run #{cmd}"
  9. end
  10. def sanitize(str, where)
  11. raise "unsanitary string in #{where}" if (str =~ /[^\w.-]/)
  12. str
  13. end
  14. def sanitize_path(str, where)
  15. raise "unsanitary string in #{where}" if (str =~ /[^\w\/.-]/)
  16. str
  17. end
  18. def info(str)
  19. puts str unless @options[:quiet]
  20. end
  21. ################################
  22. OptionParser.new do |opts|
  23. opts.banner = "Usage: build [options] <build-description>.yml"
  24. opts.on("-q", "--quiet", "be quiet") do |v|
  25. @options[:quiet] = v
  26. end
  27. opts.on("-s SIGNER", "--signer SIGNER", "identity to sign as") do |v|
  28. @options[:signer] = v
  29. end
  30. opts.on("-r REL", "--release REL", "release name") do |v|
  31. @options[:release] = v
  32. end
  33. opts.on("-d DEST", "--destination DEST", "directory to place signature in") do |v|
  34. @options[:destination] = v
  35. end
  36. end.parse!
  37. base_dir = Pathname.new(__FILE__).expand_path.dirname.parent
  38. build_desc_file = ARGV.shift or raise "must supply YAML build description file"
  39. build_desc = YAML.load_file(build_desc_file)
  40. in_sums = []
  41. result_dir = 'result'
  42. package_name = build_desc["name"] or raise "must supply name"
  43. package_name = sanitize(package_name, "package name")
  44. result_file = "#{package_name}-res.yml"
  45. result_path = File.join(result_dir, result_file)
  46. File.exists?(result_path) or raise "#{result_path} does not exist"
  47. destination = @options[:destination] || File.join(base_dir, "sigs", package_name)
  48. release = @options[:release] || "current"
  49. release = sanitize(release, "release")
  50. signer = @options[:signer] or raise "must supply signer with --signer"
  51. FileUtils.mkdir_p(destination)
  52. release_path = File.join(destination, release, signer)
  53. FileUtils.mkdir_p(release_path)
  54. FileUtils.cp(result_path, release_path)
  55. system!("gpg --detach-sign -u \"#{signer}\" -o \"#{release_path}/signature.pgp\" #{result_path}")