2011-03-27 00:32:21 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require 'optparse'
|
|
|
|
require 'yaml'
|
|
|
|
require 'fileutils'
|
|
|
|
require 'pathname'
|
|
|
|
|
|
|
|
@options = {}
|
|
|
|
|
|
|
|
def system!(cmd)
|
|
|
|
system(cmd) or raise "failed to run #{cmd}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def sanitize(str, where)
|
|
|
|
raise "unsanitary string in #{where}" if (str =~ /[^\w.-]/)
|
|
|
|
str
|
|
|
|
end
|
|
|
|
|
|
|
|
def sanitize_path(str, where)
|
2014-07-25 15:54:43 +00:00
|
|
|
raise "unsanitary string in #{where}" if (str =~ /[^@\w\/.:+-]/)
|
2011-03-27 00:32:21 +00:00
|
|
|
str
|
|
|
|
end
|
|
|
|
|
|
|
|
def info(str)
|
|
|
|
puts str unless @options[:quiet]
|
|
|
|
end
|
|
|
|
|
|
|
|
################################
|
|
|
|
|
|
|
|
OptionParser.new do |opts|
|
|
|
|
opts.banner = "Usage: build [options] <build-description>.yml"
|
|
|
|
|
|
|
|
opts.on("-q", "--quiet", "be quiet") do |v|
|
|
|
|
@options[:quiet] = v
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-s SIGNER", "--signer SIGNER", "identity to sign as") do |v|
|
|
|
|
@options[:signer] = v
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-r REL", "--release REL", "release name") do |v|
|
|
|
|
@options[:release] = v
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-d DEST", "--destination DEST", "directory to place signature in") do |v|
|
|
|
|
@options[:destination] = v
|
|
|
|
end
|
2015-06-29 13:02:25 +00:00
|
|
|
|
2015-06-29 19:09:31 +00:00
|
|
|
opts.on("-p PROG", "--signing_program PROG", "specify signing program to use") do |v|
|
|
|
|
@options[:program] = v
|
2015-06-29 13:02:25 +00:00
|
|
|
end
|
2011-03-27 00:32:21 +00:00
|
|
|
end.parse!
|
|
|
|
|
|
|
|
base_dir = Pathname.new(__FILE__).expand_path.dirname.parent
|
|
|
|
|
|
|
|
build_desc_file = ARGV.shift or raise "must supply YAML build description file"
|
|
|
|
|
|
|
|
build_desc = YAML.load_file(build_desc_file)
|
|
|
|
|
|
|
|
in_sums = []
|
|
|
|
|
|
|
|
result_dir = 'result'
|
|
|
|
|
|
|
|
package_name = build_desc["name"] or raise "must supply name"
|
2012-02-21 17:43:13 +00:00
|
|
|
optionals = build_desc["optionals"] or []
|
2011-03-27 00:32:21 +00:00
|
|
|
package_name = sanitize(package_name, "package name")
|
|
|
|
|
|
|
|
result_file = "#{package_name}-res.yml"
|
|
|
|
result_path = File.join(result_dir, result_file)
|
|
|
|
File.exists?(result_path) or raise "#{result_path} does not exist"
|
2011-05-25 21:12:29 +00:00
|
|
|
result = YAML.load_file(result_path)
|
2011-03-27 00:32:21 +00:00
|
|
|
|
|
|
|
destination = @options[:destination] || File.join(base_dir, "sigs", package_name)
|
2011-05-25 21:12:29 +00:00
|
|
|
release = @options[:release] || "test"
|
2011-03-27 00:32:21 +00:00
|
|
|
release = sanitize(release, "release")
|
2011-05-25 21:12:29 +00:00
|
|
|
|
|
|
|
result['release'] = release
|
|
|
|
result['name'] = package_name
|
|
|
|
result['type'] = 'build'
|
2012-02-21 17:43:13 +00:00
|
|
|
result['optionals'] = optionals
|
2011-05-25 21:12:29 +00:00
|
|
|
|
2015-06-29 19:09:31 +00:00
|
|
|
signer = @options[:signer] or raise "must supply signer with --signer"
|
|
|
|
program = @options[:program] || "gpg --detach-sign"
|
2011-03-27 00:32:21 +00:00
|
|
|
|
|
|
|
FileUtils.mkdir_p(destination)
|
|
|
|
|
|
|
|
release_path = File.join(destination, release, signer)
|
|
|
|
FileUtils.mkdir_p(release_path)
|
2011-05-25 21:12:29 +00:00
|
|
|
assert_path = File.join(release_path, "#{package_name}-build.assert")
|
|
|
|
File.open(assert_path, "w") do |io|
|
|
|
|
io.write result.to_yaml
|
|
|
|
end
|
2015-06-29 19:42:06 +00:00
|
|
|
system!("#{program} -u \"#{signer}\" \"#{assert_path}\"")
|