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 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. optionals = build_desc["optionals"] or []
  44. package_name = sanitize(package_name, "package name")
  45. result_file = "#{package_name}-res.yml"
  46. result_path = File.join(result_dir, result_file)
  47. File.exists?(result_path) or raise "#{result_path} does not exist"
  48. result = YAML.load_file(result_path)
  49. destination = @options[:destination] || File.join(base_dir, "sigs", package_name)
  50. release = @options[:release] || "test"
  51. release = sanitize(release, "release")
  52. result['release'] = release
  53. result['name'] = package_name
  54. result['type'] = 'build'
  55. result['optionals'] = optionals
  56. signer = @options[:signer] or raise "must supply signer with --signer"
  57. FileUtils.mkdir_p(destination)
  58. release_path = File.join(destination, release, signer)
  59. FileUtils.mkdir_p(release_path)
  60. assert_path = File.join(release_path, "#{package_name}-build.assert")
  61. File.open(assert_path, "w") do |io|
  62. io.write result.to_yaml
  63. end
  64. system!("gpg --detach-sign -u \"#{signer}\" \"#{assert_path}\"")