8 require 'opencorn/config'
12 # This script is supposed to be run regularly.
14 # It clones the 'official' git repository and figures
15 # out which is the latest tag that contains 2 or more
16 # signatures from board members.
18 # It then resets the checked out git repository to this state
19 # and clones it to its final place.
21 def valid_signature(tag)
22 system "git-verify-tag #{tag}"
26 result = `git-verify-tag #{tag} 2>&1`
27 result[/key ID ([0-9A-F]{8})/, 1]
30 if OpenCorn::Config['GNUPGHOME'] then
31 ENV['GNUPGHOME'] = OpenCorn::Config['GNUPGHOME']
34 # update accepted repo
35 Git.open(OpenCorn::Config['ACCEPTED_REPO']).pull
37 # update revocation repo
38 Git.open(OpenCorn::Config['REVOCATION_REPO']).pull
42 g = Git.clone(OpenCorn::Config['ACCEPTED_REPO'], tmpdir)
44 object_signatures = {}
45 most_current_signed_object = nil
47 # iterate over all tags, as they are not sorted by time
49 puts "Checking tag #{tag.name}" if DEBUG
50 if ! tag.name[/^[a-zA-Z0-9]+$/] then
51 STDERR.puts 'Argh, non-alphanumeric tag name, WTF?'
54 object_id = tag.contents_array[0][/object ([a-f0-9]+)/, 1]
55 puts "Refers to object id #{object_id}" if DEBUG
56 if valid_signature(tag.name) then
57 puts "Valid signature on #{tag.name} by #{signer_id(tag.name)}" \
59 object_signatures[object_id] ||= {}
60 object_signatures[object_id][signer_id(tag.name)] = 1
63 pp object_signatures if DEBUG
65 # iterate over all commits to find the first that has more than one signature
67 if object_signatures[log.objectish] \
68 && object_signatures[log.objectish].keys.size >= 2 then
69 most_current_signed_object = log.objectish
74 if ! most_current_signed_object then
75 STDERR.puts "Sorry, no object with more than one signed tag found."
79 g.reset_hard(most_current_signed_object)
82 FileUtils.rm_r OpenCorn::Config['ACCEPTED_SIGNED_REPO'], :secure => true
83 rescue # ignore errors deleting the directory
85 Git.clone(tmpdir, OpenCorn::Config['ACCEPTED_SIGNED_REPO'], :depth => 1)