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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. opts.on("-p PROG", "--signing_program PROG", "specify signing program to use") do |v|
  37. @options[:program] = v
  38. end
  39. end.parse!
  40. base_dir = Pathname.new(__FILE__).expand_path.dirname.parent
  41. build_desc_file = ARGV.shift or raise "must supply YAML build description file"
  42. build_desc = YAML.load_file(build_desc_file)
  43. in_sums = []
  44. result_dir = 'result'
  45. package_name = build_desc["name"] or raise "must supply name"
  46. optionals = build_desc["optionals"] or []
  47. package_name = sanitize(package_name, "package name")
  48. result_file = "#{package_name}-res.yml"
  49. result_path = File.join(result_dir, result_file)
  50. File.exists?(result_path) or raise "#{result_path} does not exist"
  51. result = YAML.load_file(result_path)
  52. destination = @options[:destination] || File.join(base_dir, "sigs", package_name)
  53. release = @options[:release] || "test"
  54. release = sanitize(release, "release")
  55. result['release'] = release
  56. result['name'] = package_name
  57. result['type'] = 'build'
  58. result['optionals'] = optionals
  59. signer = @options[:signer] or raise "must supply signer with --signer"
  60. program = @options[:program] || "gpg --detach-sign"
  61. FileUtils.mkdir_p(destination)
  62. release_path = File.join(destination, release, signer)
  63. FileUtils.mkdir_p(release_path)
  64. assert_path = File.join(release_path, "#{package_name}-build.assert")
  65. File.open(assert_path, "w") do |io|
  66. io.write result.to_yaml
  67. end
  68. system!("#{program} -u \"#{signer}\" \"#{assert_path}\"")